public void GetsExistingPhoneBook() { var dummyPhoneBook = PhoneBookBuilder.Instance.DummyPhoneBook(); _phoneBookContext.PhoneBooks.Add(dummyPhoneBook); _phoneBookContext.SaveChanges(); int phoneBookId = dummyPhoneBook.Id; _output.WriteLine($"PhoneBookId: {phoneBookId}"); var phoneBookFromRepo = _phoneBookRepository.GetById(phoneBookId); Assert.Equal(dummyPhoneBook.Id, phoneBookFromRepo.Id); }
public void Get_ReturnsAPhoneBook() { // Arrange var options = new DbContextOptionsBuilder <PhoneBookApiContext>() .UseInMemoryDatabase(databaseName: "phone_book_get_by_id") .Options; var testId = 1; using (var context = new PhoneBookApiContext(options)) { context.PhoneBooks.Add(GetFakePhoneBooks()[0]); context.PhoneBooks.Add(GetFakePhoneBooks()[1]); context.SaveChanges(); var phoneBookRepository = new PhoneBookRepository(context); // Act var result = phoneBookRepository.GetById(1); // Assert Assert.IsType <PhoneBook>(result); Assert.Equal(testId, result.PhoneBookId); } }