public void GetShouldReturnNullIfRepositoryThrowsExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); mock.Setup <DeliveryPerson>(_ => _.GetDeliveryPersonById(mockId)) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Get(mockId); // Assert Assert.AreEqual(null, result); }
public void GetShouldReturnTheSameDataIfRepositoryReturnsData() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); var mockData = Builder <DeliveryPerson> .CreateNew().Build(); mock.Setup <DeliveryPerson>(_ => _.GetDeliveryPersonById(mockId)) .Returns(mockData); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Get(mockId); bool same = mockData.FirstName == result.FirstName && mockData.LastName == result.LastName; // Assert Assert.IsTrue(same); }