Beispiel #1
0
        public async Task AddTagsToBookMethodShouldNotAddBookTagsWhichExist()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            await db.BookTags.AddRangeAsync(
                new BookTag
            {
                BookId = 1,
                TagId  = 1,
            },
                new BookTag
            {
                BookId = 1,
                TagId  = 2,
            });

            await db.SaveChangesAsync();

            var bookTagsService = new BookTagsService(db);

            var addTags = new List <int> {
                1, 2, 3, 4, 5, 5, 5, 5, 5, 5
            };

            await bookTagsService.AddTagsToBookAsync(1, addTags);

            Assert.Equal(5, await db.BookTags.CountAsync());
        }
Beispiel #2
0
        public async Task AddTagsToBookMethodShouldNotAddDuplicateTags()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var bookTagsService = new BookTagsService(db);

            var tags = new List <int> {
                1, 2, 3, 4, 5, 5, 5, 5, 5, 5
            };

            await bookTagsService.AddTagsToBookAsync(1, tags);

            Assert.Equal(5, await db.BookTags.CountAsync());
        }