public void GetCustomerByIdShouldReturnNullCustomerIfCustomerDoesNotExistInDbSet() { // Arrange var mockDbSet = new MockDbSet <DeliveryPerson>(); var mockContext = new Mock <IContext>(); mockContext.SetupProperty <IDbSet <DeliveryPerson> >(_ => _.DeliveryPersons) .SetupGet(_ => _.DeliveryPersons) .Returns(mockDbSet); Context = mockContext.Object; Repository = new DeliveryPersonRepository(Context); var nonExistentId = Guid.NewGuid(); // Act var result = Repository.GetDeliveryPersonById(nonExistentId); // Assert Assert.AreEqual(null, result); }
public void GetCustomerByIdShouldReturnSameCustomerIfCustomerExistsInDbSet() { // Arrange var mockDPerson = Builder <DeliveryPerson> .CreateNew().Build(); var initialList = new DeliveryPerson[] { mockDPerson }; var mockDbSet = new MockDbSet <DeliveryPerson>(initialList); var mockContext = new Mock <IContext>(); mockContext.SetupProperty <IDbSet <DeliveryPerson> >(_ => _.DeliveryPersons) .SetupGet(_ => _.DeliveryPersons) .Returns(mockDbSet); Context = mockContext.Object; Repository = new DeliveryPersonRepository(Context); // Act var result = Repository.GetDeliveryPersonById(mockDPerson.Id); // Assert Assert.AreEqual(mockDPerson, result); }