예제 #1
0
        public void NotAllowToAddItemToUnopenInvoice()
        {
            var addItemCommand = new AddInvoiceItemCommand(new InvoiceItem("1", 2m, 2));

            using (this.invoiceRoot.Subscribe(_ => { }))
                Assert.Throws <InvalidOperationException>(
                    () => this.invoiceRoot.Execute(this.invoice.Object, addItemCommand));
        }
예제 #2
0
        public void AllowToAddItemToOpenInvoice()
        {
            var item           = new InvoiceItem("1", 1m, 1u);
            var addItemCommand = new AddInvoiceItemCommand(item);

            InvoiceItemAddedEvent invoiceEvent = null;

            using (this.invoiceRoot
                   .Where(x => x is InvoiceItemAddedEvent)
                   .Select(x => x as InvoiceItemAddedEvent)
                   .Subscribe(x => invoiceEvent = x))
            {
                this.invoice.SetupGet(x => x.IsOpen).Returns(true);

                this.invoiceRoot.Execute(this.invoice.Object, addItemCommand);
                Assert.Equal(item, invoiceEvent.Item);
            }
        }
예제 #3
0
 public void Handle(IInvoice state, AddInvoiceItemCommand command)
 {
     RequireOpenInvoice(state);
     Publish(new InvoiceItemAddedEvent(command.Item));
 }