Exemplo n.º 1
0
        public void When_Full_DCC_Payment_Made_Results_In_An_Order_With_Payments()
        {
            var _orderCreated = new ESInv.Messages.OrderCreated(
                Guid.NewGuid(),
                Guid.NewGuid(),
                10001,
                new ESInv.Messages.Money("EUR", 100M),
                new[]
            {
                new ESInv.Messages.PaymentOffer(1M, new ESInv.Messages.Money("EUR", 100M)),
                new ESInv.Messages.PaymentOffer(1.27M, new ESInv.Messages.Money("USD", 127M))
            },
                DateTimeOffset.Now);
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 127M),
                DateTimeOffset.Now);

            var _SUT = new ESInv.Domain.OrderState(new[] { _orderCreated });

            _SUT.Mutate(_orderPaymentMade);

            Assert.IsTrue(_SUT.PaymentsHaveBeenMade);
            Assert.AreEqual(_orderPaymentMade.Value.Currency, _SUT.NetPaymentsValue.Currency);
            Assert.AreEqual(_orderPaymentMade.Value.Amount, _SUT.NetPaymentsValue.Amount);
            Assert.AreEqual(1, _SUT.Entries.Count());
            Assert.AreEqual(2, _SUT.Version);
        }
Exemplo n.º 2
0
        public void When_A_Partial_Refund_Made_After_Payment_Results_In_An_Order_With_A_Net_Payment()
        {
            var _orderCreated = new ESInv.Messages.OrderCreated(
                Guid.NewGuid(),
                Guid.NewGuid(),
                10001,
                new ESInv.Messages.Money("EUR", 100M),
                new[]
                    {
                        new ESInv.Messages.PaymentOffer(1M, new ESInv.Messages.Money("EUR", 100M)),
                        new ESInv.Messages.PaymentOffer(1.27M, new ESInv.Messages.Money("USD", 127M))
                    },
                DateTimeOffset.Now);
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 107M),
                DateTimeOffset.Now);
            var _SUT = new ESInv.Domain.OrderState(new ESInv.Messaging.IEvent[] { _orderCreated, _orderPaymentMade });

            var _orderRefundMade = new ESInv.Messages.OrderRefundMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 100M),
                DateTimeOffset.Now);

            _SUT.Mutate(_orderRefundMade);

            Assert.IsTrue(_SUT.PaymentsHaveBeenMade);
            Assert.AreEqual("USD", _SUT.NetPaymentsValue.Currency);
            Assert.AreEqual(7M, _SUT.NetPaymentsValue.Amount);
            Assert.AreEqual(2, _SUT.Entries.Count());
            Assert.AreEqual(3, _SUT.Version);
        }
Exemplo n.º 3
0
        public void When_A_Full_Refund_Made_After_Payment_Results_In_An_Order_With_A_Net_Payment_Of_Zero()
        {
            var _orderCreated = new ESInv.Messages.OrderCreated(
                Guid.NewGuid(),
                Guid.NewGuid(),
                10001,
                new ESInv.Messages.Money("EUR", 100M),
                new[]
            {
                new ESInv.Messages.PaymentOffer(1M, new ESInv.Messages.Money("EUR", 100M)),
                new ESInv.Messages.PaymentOffer(1.27M, new ESInv.Messages.Money("USD", 127M))
            },
                DateTimeOffset.Now);
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 107M),
                DateTimeOffset.Now);
            var _SUT = new ESInv.Domain.OrderState(new ESInv.Messaging.IEvent[] { _orderCreated, _orderPaymentMade });

            var _orderRefundMade = new ESInv.Messages.OrderRefundMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 107M),
                DateTimeOffset.Now);

            _SUT.Mutate(_orderRefundMade);

            Assert.IsTrue(_SUT.PaymentsHaveBeenMade);
            Assert.AreEqual("USD", _SUT.NetPaymentsValue.Currency);
            Assert.AreEqual(0M, _SUT.NetPaymentsValue.Amount);
            Assert.AreEqual(2, _SUT.Entries.Count());
        }
Exemplo n.º 4
0
		private void When(
			ESInv.Messages.OrderPaymentMade @event)
		{
			ESInv.DBC.Ensure.That(this.Id != Guid.Empty, "Order has NOT already been created");

			this.c_entries.Add(
				new OrderEntry(
					OrderEntryType.Debit,
					@event.Value.FromMessage(),
					DateTimeOffset.Now));
		}
Exemplo n.º 5
0
        public void When_Payment_Made_For_Order_Not_Already_Created_Results_In_An_Exception()
        {
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 127M),
                DateTimeOffset.Now);

            var _SUT = new ESInv.Domain.OrderState(new ESInv.Messaging.IEvent[0]);

            _SUT.Mutate(_orderPaymentMade);
        }
Exemplo n.º 6
0
        public void MakePayment(
            Money value)
        {
            ESInv.DBC.Ensure.That(base.State.Id != Guid.Empty, "Order has not already been created");
            ESInv.DBC.Ensure.That(base.State.IsAnOfferCurrency(value.Currency), "Currency {0} is not an offer currency", value.Currency);
            if (base.State.PaymentsHaveBeenMade)
            {
                ESInv.DBC.Ensure.That(value.Currency == base.State.ExistingPaymentsCurrency, "Currency {0} is in conflict with existing payment(s) currency {1}", value.Currency, base.State.ExistingPaymentsCurrency);
            }

            var _orderPaymentMadeEvent = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                value.ToMessage(),
                DateTimeOffset.Now);

            base.Apply(_orderPaymentMadeEvent);
        }
Exemplo n.º 7
0
        public void When_Full_DCC_Payment_Made_Results_In_An_Order_With_Payments()
        {
            var _orderCreated = new ESInv.Messages.OrderCreated(
                Guid.NewGuid(),
                Guid.NewGuid(),
                10001,
                new ESInv.Messages.Money("EUR", 100M),
                new[]
                    {
                        new ESInv.Messages.PaymentOffer(1M, new ESInv.Messages.Money("EUR", 100M)),
                        new ESInv.Messages.PaymentOffer(1.27M, new ESInv.Messages.Money("USD", 127M))
                    },
                DateTimeOffset.Now);
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 127M),
                DateTimeOffset.Now);

            var _SUT = new ESInv.Domain.OrderState(new[] { _orderCreated });

            _SUT.Mutate(_orderPaymentMade);

            Assert.IsTrue(_SUT.PaymentsHaveBeenMade);
            Assert.AreEqual(_orderPaymentMade.Value.Currency, _SUT.NetPaymentsValue.Currency);
            Assert.AreEqual(_orderPaymentMade.Value.Amount, _SUT.NetPaymentsValue.Amount);
            Assert.AreEqual(1, _SUT.Entries.Count());
            Assert.AreEqual(2, _SUT.Version);
        }
Exemplo n.º 8
0
        public void When_Payment_Made_For_Order_Not_Already_Created_Results_In_An_Exception()
        {
            var _orderPaymentMade = new ESInv.Messages.OrderPaymentMade(
                Guid.NewGuid(),
                new ESInv.Messages.Money("USD", 127M),
                DateTimeOffset.Now);

            var _SUT = new ESInv.Domain.OrderState(new ESInv.Messaging.IEvent[0]);

            _SUT.Mutate(_orderPaymentMade);
        }