public async Task OnGetAsync_WithPageNumberEqualsTo2And12Posts_ShouldReturnCurrentPageEqualsTo2() { var mediator = new Mock <IMediator>(); mediator.Setup(o => o.Send(It.IsAny <SearchArticlesQuery>(), default(CancellationToken))).Returns( Task.FromResult(new SearchResultDto <ArticleSearchDto> { CurrentPage = 2, Results = new List <ArticleSearchDto> { new ArticleSearchDto { Slug = "test11" }, new ArticleSearchDto { Slug = "test12" } } })); // Act var searchModel = new SearchModel(mediator.Object, ConfigureAutomapperServices.ConfigureAutomapper(null)); var result = await searchModel.OnGetAsync(query : "test", pageNumber : 2); Assert.Equal(2, searchModel.SearchResult.CurrentPage); }
public async Task OnGet_SearchReturnNotFound(string SearchString) { //Arrange var mockGalleryRep = new Mock <IGalleryRepository>(); mockGalleryRep.Setup(_db => _db.SearchGallery(SearchString)).Returns(MockGallery.SearchGalleryTest(SearchString)); //настрока: вызов нужного метода и передача данных var mockProductsRep = new Mock <IProductsRepository>(); mockProductsRep.Setup(_db => _db.SearchProduct(SearchString)).Returns(MockProducts.SearchProductsTest(SearchString)); //настрока: вызов нужного метода и передача данных var pageModel = new SearchModel(mockProductsRep.Object, mockGalleryRep.Object); //Act var result = await pageModel.OnGetAsync(SearchString); //Assert Assert.IsType <NotFoundResult>(result); }
public async Task OnGetAsync_ValidTerm() { var fakePosts = new List <PostDigest> { new() { Title = FakeData.Title2, ContentAbstract = "This is Jack Ma's fubao", LangCode = "en-us", PubDateUtc = new(FakeData.Int2, 9, 6), Slug = "f**k-jack-ma", Tags = new Tag[] { new() { DisplayName = "Fubao", NormalizedName = FakeData.ShortString1, Id = FakeData.Int2 } } } }; _mockMediator.Setup(p => p.Send(It.IsAny <SearchPostQuery>(), default)) .Returns(Task.FromResult((IReadOnlyList <PostDigest>)fakePosts)); var httpContext = new DefaultHttpContext(); var modelState = new ModelStateDictionary(); var actionContext = new ActionContext(httpContext, new(), new PageActionDescriptor(), modelState); var modelMetadataProvider = new EmptyModelMetadataProvider(); var viewData = new ViewDataDictionary(modelMetadataProvider, modelState); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); var pageContext = new PageContext(actionContext) { ViewData = viewData }; var searchModel = new SearchModel(_mockMediator.Object) { PageContext = pageContext, TempData = tempData }; var result = await searchModel.OnGetAsync(FakeData.ShortString2); Assert.IsNotNull(searchModel.Posts); } }