Skip to content

Instantly share code, notes, and snippets.

@Saulis
Created August 14, 2012 08:14
Show Gist options
  • Save Saulis/3347468 to your computer and use it in GitHub Desktop.
Save Saulis/3347468 to your computer and use it in GitHub Desktop.
Refactoring PurchaseSenderTests
[TestMethod]
public void SendPurchase_CustomerDoesNotExist_CustomerCreated_StatusOK()
{
SetPurchaseCustomerSsnTo(NonexistingCustomerSsn);
SendPurchaseResult result = sut.SendFromWebService(purchase);
Assert.AreEqual(SendPurchaseResultType.STATUS_OK, result.Type);
}
[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