public async Task AddTagsMethodShouldAddTagIdsToPost(string title, PostType type, string description, int categoryId) { 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 = title, Description = description, Type = type, CategoryId = categoryId, AuthorId = guid, CreatedOn = dateTimeProvider.Object.Now() }; await db.Posts.AddAsync(post); await db.SaveChangesAsync(); var postsService = new PostsService(db, null, null, dateTimeProvider.Object); var expectedIds = new[] { 1, 2, 3 }; await postsService.AddTagsAsync(1, expectedIds); var actual = await db.Posts.FirstOrDefaultAsync(); var actualIds = actual.Tags.Select(t => t.TagId); actualIds.Should().BeEquivalentTo(expectedIds); }