Ejemplo n.º 1
0
        public async Task CheckGettingAllCommentsFromPreviuosDayAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Comment>(db);
            var service    = new CommentsService(repository);

            var firstComment = new Comment()
            {
                Id        = Guid.NewGuid().ToString(),
                CreatedOn = DateTime.UtcNow.Date.AddDays(-1),
                Content   = "test content 1",
                ClientId  = this.client.Id,
                ArticleId = this.article.Id,
            };

            var secondComment = new Comment()
            {
                Id        = Guid.NewGuid().ToString(),
                CreatedOn = DateTime.UtcNow.Date.AddDays(-1),
                Content   = "test content 2",
                ClientId  = this.client.Id,
                ArticleId = this.article.Id,
            };

            var thirdComment = new Comment()
            {
                Id        = Guid.NewGuid().ToString(),
                CreatedOn = DateTime.UtcNow,
                Content   = "test content 3",
                ClientId  = this.client.Id,
                ArticleId = this.article.Id,
            };

            await db.Users.AddAsync(this.client);

            await db.Articles.AddAsync(this.article);

            await db.Comments.AddAsync(firstComment);

            await db.Comments.AddAsync(secondComment);

            await db.Comments.AddAsync(thirdComment);

            await db.SaveChangesAsync();

            var comments = await service.GetAllFromPreviousDayAsync <TestCommentModel>();

            Assert.Equal(2, comments.Count());
        }