public void AddItem_throws_InvalidOperationException_if_sale_cancelled() { var sale = new Sale(SaleState.Cancelled); var saleItem = new SaleItem(price: 1.00M); Assert.Throws <InvalidOperationException>(() => SaleStateManager.Fire(sale, SaleEvent.AddItem, saleItem)); }
public void AddPayment_throws_InvalidOperationException_if_sale_complete() { var sale = new Sale(SaleState.Completed); var payment = new Payment(amount: 1.00M); Assert.Throws <InvalidOperationException>(() => SaleStateManager.Fire(sale, SaleEvent.AddPayment, payment)); }
public void AddPayment_while_Open_adds_payment_to_sale() { var sale = new Sale(); const decimal paymentAmount = 1.23M; SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(paymentAmount)); Assert.Equal(-paymentAmount, sale.Balance); }
public void AddPayment_on_Open_sale_sets_state_Completed_if_items_delivered_and_0_balance() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 1.00M, state: SaleItemState.Delivered)); SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(amount: 1.00M)); Assert.Equal(SaleState.Completed, sale.State); }
public void GiveChange_throws_InvalidOperationException_when_amount_exceeds_balance() { var sale = new Sale(SaleState.Authorized) { Balance = -1 }; Assert.Throws <InvalidOperationException>(() => SaleStateManager.Fire(sale, SaleEvent.ChangeGiven, new ChangeTransaction(5.55M))); }
public void AddPayment_on_Open_sale_leaves_state_Open_if_0_items() { var sale = new Sale(); var payment = new Payment(amount: 1.00M); SaleStateManager.Fire(sale, SaleEvent.AddPayment, payment); Assert.Equal(SaleState.Opened, sale.State); }
public void Cancel_on_Authorized_goes_to_Cancelled() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 2.22M)); SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(amount: 5.00M)); SaleStateManager.Fire(sale, SaleEvent.Cancel); Assert.Equal(SaleState.Cancelled, sale.State); }
public void GiveChange_updates_balance() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 4.55M)); SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(amount: 5.00M)); Assert.True(SaleStateManager.IsInState(sale, SaleState.Authorized)); SaleStateManager.Fire(sale, SaleEvent.ChangeGiven, new ChangeTransaction(amount: .45M)); Assert.Equal(expected: 0, actual: sale.Balance); }
public void AddPayment_adds_the_payment() { var sale = new Sale(); var payment = new Payment(amount: 1.00M); Assert.Equal(expected: 0, actual: sale.PaymentCount); SaleStateManager.Fire(sale, SaleEvent.AddPayment, payment); Assert.Equal(expected: 1, actual: sale.PaymentCount); }
public void Cancel_throws_InvalidOperationException_if_sale_has_undelivered_items() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(1.00M) { RequiresDelivery = true }); Assert.Throws <InvalidOperationException>(() => SaleStateManager.Fire(sale, SaleEvent.Cancel)); }
public void AddPayment_on_Open_sale_sets_state_ChangeDue_if_items_delivered_and_negative_balance() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 1.00M, state: SaleItemState.Delivered)); var payment = new Payment(amount: 3.00M); SaleStateManager.Fire(sale, SaleEvent.AddPayment, payment); Assert.Equal(SaleState.ChangeDue, sale.State); }
public void AddPayment_on_Open_sale_sets_state_WaitingForDelivery_if_items_to_deliver() { var sale = new Sale(); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 1.00M)); var payment = new Payment(amount: 1.00M); SaleStateManager.Fire(sale, SaleEvent.AddPayment, payment); Assert.Equal(SaleState.WaitingForDelivery, sale.State); }
public void AddItem_adds_the_item() { var sale = new Sale(); var saleItem = new SaleItem(price: 1.00M); Assert.Equal(expected: 0, actual: sale.ItemCount); SaleStateManager.Fire(sale, SaleEvent.AddItem, saleItem); Assert.Equal(expected: 1, actual: sale.ItemCount); }
public void Cancel_cancels_all_items() { var sale = new Sale(); var saleItem = new SaleItem(price: 1.00M); sale.AddItem(saleItem); Assert.Equal(SaleItemState.NotDelivered, saleItem.State); SaleStateManager.Fire(sale, SaleEvent.Cancel); Assert.Equal(SaleItemState.Cancelled, saleItem.State); }
public void AddItem_on_Authorized_sets_state_to_PartiallyAuthorized() { var sale = new Sale(); var saleItem = new SaleItem(price: 4.55M); SaleStateManager.Fire(sale, SaleEvent.AddItem, saleItem); SaleStateManager.Fire(sale, SaleEvent.ItemDelivered, saleItem); SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(amount: 5.55M)); SaleStateManager.Fire(sale, SaleEvent.AddItem, new SaleItem(price: 2.22M)); Assert.Equal(SaleState.PartiallyAuthorized, sale.State); }
public void ItemDelivered_sets_state_to_Completed_if_fully_balanced_and_delivered() { var sale = new Sale(); var saleItem = new SaleItem(price: 4.55M); SaleStateManager.Fire(sale, SaleEvent.AddItem, saleItem); SaleStateManager.Fire(sale, SaleEvent.AddPayment, new Payment(amount: 4.55M)); Assert.Equal(SaleState.WaitingForDelivery, sale.State); SaleStateManager.Fire(sale, SaleEvent.ItemDelivered, saleItem); Assert.Equal(SaleState.Completed, sale.State); }
public void AddPayment_on_CancelledSale_throws_InvalidOperationException() { Assert.Throws <InvalidOperationException>(() => SaleStateManager.Fire(new Sale(SaleState.Cancelled), SaleEvent.AddPayment, new Payment(amount: 1))); }