Ejemplo n.º 1
0
        public async Task AddTagToBookAsync_WithExistingBookTagRelation_ReturnsFalse()
        {
            // Arrange
            var context      = this.NewInMemoryDatabase();
            var booksService = new BooksService(context);
            var tag          = new Tag();
            var book         = new Book();

            await context.Tags.AddAsync(tag);

            await context.Books.AddAsync(book);

            await context.BookTags.AddAsync(new BookTag
            {
                BookId = book.Id,
                TagId  = tag.Id
            });

            await context.SaveChangesAsync();

            // Act
            var result = await booksService.AddTagToBookAsync(book.Id, tag.Id);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 2
0
        public async Task AddTagToBookAsync_WithCorrectIds_WorksCorrectly()
        {
            // Arrange
            var context      = this.NewInMemoryDatabase();
            var booksService = new BooksService(context);
            var tag          = new Tag();
            var book         = new Book();

            await context.Tags.AddAsync(tag);

            await context.Books.AddAsync(book);

            await context.SaveChangesAsync();

            // Act
            var result = await booksService.AddTagToBookAsync(book.Id, tag.Id);

            // Assert
            Assert.True(result);
            Assert.True(await context.BookTags.AnyAsync(bt => bt.BookId == book.Id && bt.TagId == tag.Id));
        }
Ejemplo n.º 3
0
        public async Task AddTagToBookAsync_WithIncorrectBookId_ReturnsFalse()
        {
            // Arrange
            var context           = this.NewInMemoryDatabase();
            var booksService      = new BooksService(context);
            var tag               = new Tag();
            var book              = new Book();
            var nonexistentBookId = Guid.NewGuid().ToString();

            await context.Tags.AddAsync(tag);

            await context.Books.AddAsync(book);

            await context.SaveChangesAsync();

            // Act
            var result = await booksService.AddTagToBookAsync(nonexistentBookId, tag.Id);

            // Assert
            Assert.False(result);
            Assert.False(await context.BookTags.AnyAsync(bt => bt.BookId == book.Id && bt.TagId == tag.Id));
        }