I am trying to get a unit test for a service that injects elements into IHttpRequest.Items objects using a query filter:
this.RequestFilters.Add((req, res, dto) => {
My service uses this dictionary element:
public class UserService : AppServiceBase { public IUserServiceGateway UserServiceGateway { get; set; } public object Any(UserRequest request) { var accountCode = base.Request.Items["AccountCode"].ToString(); var user = UserServiceGateway.GetUserByUsername(request.Name); return new UserResponse { User = user }; } }
My test should somehow mock the request and insert this element of the account code:
[Test] public void ValidUsernameReturnUser() {
The service itself accepts a laughed RequestContext, but not Request. Therefore, the test fails. Is there a better way to do this?
Junto source share