Exemple #1
0
        public void CardRepository_GetAllWithDetails_ReturnsCardByIdAndIncludesBooks()
        {
            //Arrange
            using var context = new LibraryDbContext(UnitTestHelper.GetUnitTestDbOptions());
            var cardRepository = new CardRepository(context);
            var expectedCards  = context.Cards.AsNoTracking().Include(x => x.Books).Include(x => x.Reader).ToList();

            //Act
            var cards = cardRepository.FindAllWithDetails().ToList();

            //Assert
            Assert.That(cards, Is.EqualTo(expectedCards).Using(new CardEqualityComparer()));
            for (int i = 0; i < cards.Count; i++)
            {
                Assert.That(cards[i].Books, Is.EqualTo(expectedCards[i].Books).Using(new HistoryEqualityComparer()));
                Assert.That(cards[i].Reader, Is.EqualTo(expectedCards[i].Reader).Using(new ReaderEqualityComparer()));
            }
        }