Esempio n. 1
0
        public async Task AllShouldReturnModelWithCorrectInformation()
        {
            // ARRANGE
            const string database           = "AllShouldReturnModelWithCorrectInformation";
            const int    pageSize           = 5;
            const int    totalArticlesCount = 25;

            await using var context = new FakeDbContext(database);
            await context.SeedArticles(25);

            var mapper =
                new Mapper(
                    new MapperConfiguration(conf => conf.AddProfile(new ServiceMappingProfile())));
            var dataTimeService = new DateTimeService();
            var configuration   = new ConfigurationBuilder()
                                  .AddInMemoryCollection(new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>("Articles:PageSize", pageSize.ToString()),
            })
                                  .Build();

            var articleService = new ArticleService(context, mapper, dataTimeService);
            var controller     = new ArticlesController(articleService, mapper, configuration);


            // ACT
            ViewResult result             = Assert.IsType <ViewResult>(await controller.All());
            ArticleListingViewModel model = Assert.IsType <ArticleListingViewModel>(result.Model);

            // ASSERT
            Assert.Equal(pageSize, model.Articles.Count());
            Assert.Equal(totalArticlesCount, model.Total);
        }
Esempio n. 2
0
        public void ArticlesAll_ShouldReturnItsDefaultView()
        {
            var result = _controller.All() as ViewResult;

            Assert.IsTrue(string.IsNullOrEmpty(result.ViewName));
        }