Пример #1
0
        public async Task ChangeVisibilityShoulSetCorrectPublishedOnDate()
        {
            // arrange
            await using FakeDbContext context =
                            new FakeDbContext("ChangeVisibilityShoulSetCorrectPublishedOnDate");
            await context.SeedArticles(1);

            var dateTimeService = new FakeDateTimeService();

            dateTimeService.DateTime = new DateTime(2001, 1, 1, 1, 1, 1);

            var service =
                new ArticleService(
                    context,
                    null,
                    dateTimeService);

            // act
            await service.ChangeVisibility(1);

            await using FakeDbContext context2 =
                            new FakeDbContext("ChangeVisibilityShoulSetCorrectPublishedOnDate");

            var article = await context2.Articles.FirstOrDefaultAsync(t => t.Id == 1);

            Assert.Equal(dateTimeService.DateTime, article.PublishedOn);
        }
Пример #2
0
        public async void IsByUserShouldReturnTrueWhenArticleByTheSpecificUserExists()
        {
            // ARRANGE
            const int    articleId = 1;
            const string userId    = "1";
            const string database  = "IsByUserShouldReturnTrueWhenArticleByTheSpecificUserExists";

            await using (var context = new FakeDbContext(database))
            {
                await context.SeedArticles(3);
            }

            // ACT
            bool result;

            await using (var context = new FakeDbContext(database))
            {
                var articleService = new ArticleService(context, null, null);

                result = await articleService.IsByUser(articleId, userId);
            }

            // ASSERT
            Assert.True(result);
        }
Пример #3
0
        public async void IsByUserShouldReturnFalseWhenTheUserDoesntHaveArticleWithGivenArticleId()
        {
            // ARRANGE
            const int    articleId = 1;
            const string userId    = "10000";
            const string database  = "IsByUserShouldReturnFalseWhenTheUserDoesntHaveArticleWithGivenArticleId";

            await using (var context = new FakeDbContext(database))
            {
                await context.SeedArticles(3);
            }

            // ACT
            bool result;

            await using (var context = new FakeDbContext(database))
            {
                var articleService = new ArticleService(context, null, null);

                result = await articleService.IsByUser(articleId, userId);
            }

            // ASSERT
            Assert.False(result);
        }
Пример #4
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);
        }
Пример #5
0
        public async Task AllShouldReturnCorrectNumberOfArticles()
        {
            // arrange
            const string database = "asdfasdfasdfasdfasdfasdfasdf";

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

            // act
            var mapper = new Mapper(new MapperConfiguration(conf =>
            {
                conf.AddProfile <ServiceMappingProfile>();
            }));

            await using var context2 = new FakeDbContext(database);
            var articleService = new ArticleService(context2, mapper, null);

            var articles = await articleService.All();

            Assert.Equal(3, articles.ToArray().Length);
        }