public async Task Search_ReturnsEmptyList() { // Arrange var articleDbSetMock = Builder <Article> .CreateListOfSize(3).Build().ToAsyncDbSetMock(); _articleRepositoryMock.Setup(m => m.Query()).Returns(articleDbSetMock.Object); // Act var result = await _articlesController.Search("Invalid"); // Assert Assert.NotNull(result); var objectResult = result as OkObjectResult; Assert.NotNull(objectResult); var content = objectResult.Value as ArticleListModel; Assert.NotNull(content); Assert.Equal(0, content.Articles.Count()); }
public void CallGetPageMethod_WhenParamsAreValid() { // Arrange var articleServiceMock = new Mock <IArticleService>(); var mappingServiceMock = new Mock <IMappingService>(); var storeServiceMock = new Mock <IStoreService>(); var userServiceMock = new Mock <IUserService>(); var utilsMock = new Mock <IUtilitiesService>(); var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object); var articleMock = new Article(); var mappedArticleMock = new ArticleItemViewModel(); var modelMock = new ArticlesListViewModel(); var articlesMock = new List <Article>() { articleMock }; var mappedArticlesMock = new List <ArticleItemViewModel>() { mappedArticleMock }; articleServiceMock.Setup(x => x.GetPagesCount(It.IsAny <string>())).Returns(1); utilsMock.Setup(x => x.GetPage(It.IsAny <int?>(), It.IsAny <int>())).Returns(1); articleServiceMock.Setup(x => x.GetFilteredArticlesByPage(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(articlesMock); mappingServiceMock.Setup(x => x.Map <IEnumerable <ArticleItemViewModel> >(It.IsAny <IEnumerable <Article> >())).Returns(mappedArticlesMock); mappingServiceMock.Setup(x => x.Map <ArticlesListViewModel>(It.IsAny <IEnumerable <ArticleItemViewModel> >())).Returns(modelMock); utilsMock.Setup(x => x.AssignViewParams <ArticlesListViewModel>(It.IsAny <ArticlesListViewModel>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(modelMock); // Act controller.Search(null, null); // Assert utilsMock.Verify(x => x.GetPage(It.IsAny <int?>(), It.IsAny <int>()), Times.Once); }
public void ArticlesSearch_LookingForANaughtyStringShouldThrowError() { var result = _controller.Search("<br/>") as ViewResult; Assert.IsTrue(string.IsNullOrEmpty(result.ViewName)); }