Created
September 14, 2012 20:00
-
-
Save abdullin/3724348 to your computer and use it in GitHub Desktop.
Advanced A+ES with domain services
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
// This is slightly advanced usage scenario of Lokad A+ES tests, that shows | |
// setting up test implementations of domain services in ES+friendly way | |
// (really simple) that also prints out in the specifications. Price is an | |
// instance of IPricingService, used by Application service, while Clock | |
// is a static singleton actually. | |
[Test] | |
public void with_multiple_entries_and_previous_balance() | |
{ | |
Given( | |
Price.SetPrice("salescast", 50m.Eur()), | |
Price.SetPrice("forecast", 2m.Eur()), | |
new CustomerCreated(id, "Landor", CurrencyType.Eur, guid, Date(2001)), | |
new CustomerPaymentAdded(id, 1, 30m.Eur(), 30m.Eur(), "Prepaid", "magic", Date(2001)), | |
ClockWasSet(2011, 3, 2) | |
); | |
When(new AddCustomerBill(id, bill, Date(2011, 2), Date(2011, 3), new[] | |
{ | |
new CustomerBillEntry("salescast", 1), | |
new CustomerBillEntry("forecast", 2), | |
new CustomerBillEntry("forecast", 8) | |
})); | |
Then(new CustomerBillChargeAdded(id, bill, Date(2011, 2), Date(2011, 3), new[] | |
{ | |
new CustomerBillLine("salescast", "Test Product 'salescast'", 1, 50m.Eur()), | |
new CustomerBillLine("forecast", "Test Product 'forecast'", 10, 20m.Eur()), | |
}, 2, 70m.Eur(), -40m.Eur(), Date(2011, 3, 2))); | |
} | |
and prints to: | |
/* | |
------------------------------------------------------------------------- | |
Test: add customer bill | |
Specification: with multiple entries and previous balance | |
GIVEN: | |
1. Set price of salescast to 50 EUR | |
2. Set price of forecast to 2 EUR | |
3. Created customer Customer-7 Eur 'Landor' with key a4297e7f-8231-447f-805c-38d8abcb7de4... | |
4. Tx 1: payment 30 EUR 'Prepaid' (magic) | |
5. Test clock set to 2011-03-02 | |
WHEN: | |
Add bill 1 from 2011-02-01 to 2011-03-01 | |
salescast : 1 | |
forecast : 2 | |
forecast : 8 | |
THEN: | |
1. Tx 2: charge for bill 1 from 2011-02-01 to 2011-03-01 | |
Test Product 'salescast' (1 salescast): 50 EUR | |
Test Product 'forecast' (10 forecast): 20 EUR | |
Results: [Passed] | |
------------------------------------------------------------------------- | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment