Exemple #1
0
        public async Task GetLatestActivityByIdMethodShouldReturnPostLatestActivity()
        {
            var guid = Guid.NewGuid().ToString();

            var options = new DbContextOptionsBuilder <ForumDbContext>()
                          .UseInMemoryDatabase(guid)
                          .Options;

            var db = new ForumDbContext(options);
            var dateTimeProvider = new Mock <IDateTimeProvider>();

            dateTimeProvider.Setup(dtp => dtp.Now()).Returns(new DateTime(2020, 3, 27));

            var post = new Post
            {
                Id          = 1,
                Title       = "Test title 1",
                Description = "Test description 1",
                Type        = PostType.Discussion,
                CategoryId  = 1,
                AuthorId    = guid,
                CreatedOn   = dateTimeProvider.Object.Now(),
            };

            await db.Posts.AddAsync(post);

            await db.SaveChangesAsync();

            var postsService = new PostsService(db, null, null, dateTimeProvider.Object);

            var latestActivity = await postsService.GetLatestActivityByIdAsync(1);

            latestActivity.Should().Be("0m");
        }