public async Task ShouldReturnValidViewModel() { var query = new SearchQuery { SearchTerm = "NHS", Page = 1, SearchType = SearchCategory.User }; var response = new SearchResponse(); _mockMediator .Setup(x => x.SendAsync(query)) .Returns(Task.FromResult(response)); _mockMappingService .Setup(x => x.Map <SearchResponse, SearchResultsViewModel>(response)) .Returns(new SearchResultsViewModel()); _sut = new Portal.Web.Controllers.SearchController(_mockMappingService.Object, _mockMediator.Object); var result = await _sut.Index(query); var vr = result as ViewResult; vr.Should().NotBeNull(); var vm = vr.Model as SearchResultsViewModel; vm.Should().NotBeNull(); }
public void Init() { MockLogger = new Mock <ILog>(); MockMappingService = new Mock <IMappingService>(); MockMediator = new Mock <IMediator>(); Unit = new Portal.Web.Controllers.SearchController( MockMappingService.Object, MockMediator.Object); RouteData = new RouteData(); MockContextBase = new Mock <HttpContextBase>(); MockRequestBase = new Mock <HttpRequestBase>(); MockResponseBase = new Mock <HttpResponseBase>(); MockUser = new Mock <IPrincipal>(); MockContextBase.Setup(x => x.Request).Returns(MockRequestBase.Object); MockContextBase.Setup(x => x.Response).Returns(MockResponseBase.Object); MockContextBase.Setup(x => x.User).Returns(MockUser.Object); UnitControllerContext = new ControllerContext(MockContextBase.Object, RouteData, Unit); Unit.ControllerContext = UnitControllerContext; }