Created
August 14, 2012 08:14
-
-
Save Saulis/3347468 to your computer and use it in GitHub Desktop.
Refactoring PurchaseSenderTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void SendPurchase_CustomerDoesNotExist_CustomerCreated_StatusOK() | |
{ | |
SetPurchaseCustomerSsnTo(NonexistingCustomerSsn); | |
SendPurchaseResult result = sut.SendFromWebService(purchase); | |
Assert.AreEqual(SendPurchaseResultType.STATUS_OK, result.Type); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void SendPurchase_CustomerDoesNotExist_CustomerCreated() | |
{ | |
PurchaseWithBalanceDto testDto = Build.PurchaseWithBalanceDto.AsTransient(); | |
CreditAllocationDto creditAllocationDto = new CreditAllocationDto(); | |
creditAllocationDto.CustomerKey = this.validPurchase.Customer.SSN; | |
using (mockRepository.Record()) | |
{ | |
StoreDto store = Build.StoreDto.WithClientId(123).AsTransient(); | |
Expect.Call(purchaseFacade.GetStore(Convert.ToUInt64(validPurchase.StoreId))).Return(store); | |
Expect.Call(creditAllocationFacade.GetLatestReservedCreditAllocation(0, 0, null)) | |
.IgnoreArguments() | |
.Return(creditAllocationDto); | |
Expect.Call(delegate | |
{ creditAllocationFacade.Use(new CreditAllocationDto(), 1, new Money(1, CurrencyCode.EUR)); }) | |
.IgnoreArguments(); | |
Expect.Call(delegate | |
{ creditAllocationFacade.OverrideAllReserved(1, 1, "1"); }) | |
.IgnoreArguments(); | |
Expect.Call(this.customerFacade.GetCustomer(null, 0)).IgnoreArguments().Return(null); | |
Expect.Call(this.customerCreator.Create(this.validPurchase, store.ClientId)).IgnoreArguments().Return(this.existingCustomerDto); | |
Expect.Call(this.purchaseCustomerUpdater.CreateOrUpdatePurchaseCustomer(null, null)).IgnoreArguments(); | |
postingFacade.Post(new PurchaseDto()); | |
LastCall.IgnoreArguments(); | |
Expect.Call(purchaseCreator.CreatePurchase(null, null, null, EndpointType.ExternalWcfInterface)).IgnoreArguments().Return(testDto); | |
Expect.Call(purchaseFacade.Insert(testDto)).IgnoreArguments().Return(1); | |
LastCall.IgnoreArguments(); | |
PurchaseDto purchaseDto = Build.PurchaseDto.AsTransient(); | |
InvoicePurchase invoicePurchase = MockRepository.GenerateStrictMock<InvoicePurchase>(purchaseDto); | |
this.purchaseFactory.Expect(pf => pf.CreateFrom(null)).IgnoreArguments().Return(invoicePurchase); | |
invoicePurchase.Expect(p => p.InsertAvailablePaymentPlanOptions(NumberOfInstallments)); | |
} | |
sut.SendFromUi(validPurchase); | |
this.purchaseFactory.VerifyAllExpectations(); | |
mockRepository.VerifyAll(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment