public void ShouldGetAnExceptionTryingToLookupClient() { //Arrainge var customerDataServiceMock = new Mock <ICustomerDataService>(); var customerMock = new Mock <ICustomerAccountService>(); var customerId = Guid.NewGuid(); var mowingCharge = 10; var wateringCharge = 15; var weedingCharge = 25; var customerName = "Bob"; customerMock.Setup(x => x.GetMowingCharge()).Returns(mowingCharge); customerMock.Setup(x => x.GetWateringCharge()).Returns(wateringCharge); customerMock.Setup(x => x.GetWeedingCharge()).Returns(weedingCharge); customerMock.Setup(x => x.Name).Returns(customerName); customerDataServiceMock.Setup(x => x.GetCustomerAccount(customerId)) .Returns(customerMock.Object); customerDataServiceMock.Setup(x => x.GetCustomerAccount(It.IsAny <Guid>())) .Throws <ArgumentException>(); var customerBillingService = new CustomerBillingService(customerDataServiceMock.Object); var result = customerBillingService.GetCustomerCurrentAmountDue(Guid.NewGuid()); Assert.AreEqual(25, result); }
public void ShouldBeAbleToGetTotalAmountDueForClient() { //Arrainge var customerDataServiceMock = new Mock <ICustomerDataService>(); var customerMock = new Mock <ICustomerAccountService>(); var customerId = Guid.NewGuid(); var mowingCharge = 10; var wateringCharge = 15; var weedingCharge = 25; var customerName = "Bob"; var expectedTotal = mowingCharge + wateringCharge + weedingCharge; customerMock.Setup(x => x.GetMowingCharge()).Returns(mowingCharge); customerMock.Setup(x => x.GetWateringCharge()).Returns(wateringCharge); customerMock.Setup(x => x.GetWeedingCharge()).Returns(weedingCharge); customerMock.Setup(x => x.Name).Returns(customerName); customerDataServiceMock.Setup(x => x.GetCustomerAccount(customerId)) .Returns(customerMock.Object); var customerBillingService = new CustomerBillingService(customerDataServiceMock.Object); //Act var result = customerBillingService.GetCustomerCurrentAmountDue(customerId); //Assert customerMock.Verify(x => x.WillNeverEverBeCalled(), Times.Never); customerDataServiceMock.Verify(x => x.GetCustomerAccount(customerId), Times.Once); Assert.AreEqual(expectedTotal, result); }
public void ShouldBeAbleToGetTotalAmountDueForClient() { //Arrainge var customerDataServiceMock = new Mock <ICustomerDataService>(); var customerMock = new Mock <ICustomerAccountService>(); var mowingCharge = 10; var wateringCharge = 15; var weedingCharge = 25; var customerName = "Bob"; var expectedTotal = mowingCharge + wateringCharge + weedingCharge; customerMock.Setup(x => x.GetMowingCharge()).Returns(mowingCharge); customerMock.Setup(x => x.GetWateringCharge()).Returns(wateringCharge); customerMock.Setup(x => x.GetWeedingCharge()).Returns(weedingCharge); customerMock.Setup(x => x.Name).Returns(customerName); customerDataServiceMock .Setup(x => x.GetCustomerAccount(It.IsAny <Guid>())) .Returns(customerMock.Object); var customerBillingService = new CustomerBillingService(customerDataServiceMock.Object); //Act var result = customerBillingService.GetCustomerCurrentAmountDue(Guid.Empty); //Assert Assert.AreEqual(expectedTotal, result); }
public void ShouldBeAbleToGetDaysPaymentLateAndStatusForCustomer() { //Arr var customerDataServiceMock = new Mock <ICustomerDataService>(); var customerAccountMock = new Mock <ICustomerAccountService>(); var customerId = Guid.NewGuid(); const int expectedDaysLate = 100; var expectedStatus = "Cancelled"; customerAccountMock.Setup(x => x.GetCustomerPaymentStatus(out expectedStatus)) .Returns(expectedDaysLate); customerDataServiceMock.Setup(x => x.GetCustomerAccount(customerId)) .Returns(customerAccountMock.Object); var customerBillingService = new CustomerBillingService(customerDataServiceMock.Object); //Act string statusResult; var result = customerBillingService.GetPaymentDaysLate(customerId, out statusResult); //Assert Assert.AreEqual(result, expectedDaysLate); Assert.AreEqual(expectedStatus, statusResult); }
public void ShouldBeAbleToSetupNewCustomer() { //Arr var customerDataServiceMock = new Mock <ICustomerDataService>(); var customerAccountMock = new Mock <ICustomerAccountService>(); var customerName = "Bob"; var expectedCustomerId = Guid.NewGuid(); customerAccountMock.Setup(x => x.CustomerId).Returns(expectedCustomerId); customerAccountMock.SetupProperty(x => x.Name); customerDataServiceMock.Setup(x => x.GetCustomerAccount()) .Returns(customerAccountMock.Object); var customerBillingService = new CustomerBillingService(customerDataServiceMock.Object); //Act var result = customerBillingService.SetupNewCustomer(customerName); //Assert Assert.AreEqual(expectedCustomerId, result); customerAccountMock.VerifySet(x => x.Name = customerName); Assert.AreEqual(customerName, customerAccountMock.Object.Name); }