コード例 #1
0
        public ShipmentDisplay NewShipment(OrderDisplay order)
        {
            try
            {
                if (!order.Items.Any())
                {
                    throw new InvalidOperationException("The shipment did not include any line items");
                }

                var merchOrder = _orderService.GetByKey(order.Key);

                var builder = new ShipmentBuilderChain(MerchelloContext, order.ToOrder(merchOrder));

                var attempt = builder.Build();

                if (!attempt.Success)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception));
                }

                return(attempt.Result.ToShipmentDisplay());
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message)));
            }
        }
コード例 #2
0
        public ShipmentDisplay NewShipment(ShipmentRequestDisplay shipmentRequest)
        {
            try
            {
                if (!shipmentRequest.Order.Items.Any())
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The shipment did not include any line items"));
                }

                var merchOrder = _orderService.GetByKey(shipmentRequest.Order.Key);

                var builder = new ShipmentBuilderChain(MerchelloContext, merchOrder, shipmentRequest.Order.Items.Select(x => x.Key), shipmentRequest.ShipMethodKey, shipmentRequest.ShipmentStatusKey, shipmentRequest.TrackingNumber);

                var attempt = builder.Build();

                if (!attempt.Success)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception));
                }

                return(attempt.Result.ToShipmentDisplay());
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, string.Format("{0}", ex.Message)));
            }
        }
コード例 #3
0
        public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated()
        {
            //// Arrage
            var builder = new ShipmentBuilderChain(MerchelloContext, _order);

            //// Act
            var attempt = builder.Build();
            if(!attempt.Success) Console.WriteLine(attempt.Exception.Message);

            //// Assert
            Assert.IsTrue(attempt.Success);
        }
コード例 #4
0
        public void Can_Create_The_Default_Shipment_Builder_With_Tasks()
        {
            //// Arrange
            const int taskCount = 3;

            //// Act
            var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.DefaultKeys.ShipmentStatus.Quoted, "test-tracking");

            //// Assert
            Assert.NotNull(builder);
            Assert.AreEqual(taskCount, builder.TaskCount);
        }
コード例 #5
0
        public void Can_Create_The_Default_Shipment_Builder_With_Tasks()
        {
            //// Arrange
            const int taskCount = 3;

            //// Act
            var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.ShipmentStatus.Quoted, "test-tracking", "http://somewhere.com", "carrier");

            //// Assert
            Assert.NotNull(builder);
            Assert.AreEqual(taskCount, builder.TaskCount);
        }
コード例 #6
0
        public void Can_Create_The_Default_Shipment_Builder_With_Tasks()
        {
            //// Arrange
            const int taskCount = 3;

            //// Act
            var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key));

            //// Assert
            Assert.NotNull(builder);
            Assert.AreEqual(taskCount, builder.TaskCount);
        }
コード例 #7
0
        public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated()
        {
            //// Arrange
            var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.DefaultKeys.ShipmentStatus.Quoted, "test-tracking");

            //// Act
            var attempt = builder.Build();
            if (!attempt.Success) Console.WriteLine(attempt.Exception.Message);

            //// Assert
            Assert.IsTrue(attempt.Success);
        }
コード例 #8
0
        public void Can_Create_The_Default_Shipment_Builder_With_Tasks()
        {
            //// Arrange
            const int taskCount = 3;

            //// Act
            var builder = new ShipmentBuilderChain(MerchelloContext, _order);

            //// Assert
            Assert.NotNull(builder);
            Assert.AreEqual(taskCount, builder.TaskCount);
        }
コード例 #9
0
        public void Can_Save_A_Shipment_After_Its_Built()
        {
            //// Arrange
            var shipmentService = MerchelloContext.Services.ShipmentService;
            var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key));
            var attempt = builder.Build();
            Assert.IsTrue(attempt.Success, "Failed to build shipment");

            //// Act
            var shipment = attempt.Result;
            shipmentService.Save(shipment);

            //// Assert
            Assert.IsTrue(shipment.HasIdentity);
        }
コード例 #10
0
        public void Can_Save_A_Shipment_After_Its_Built()
        {
            //// Arrange
            var shipmentService = MerchelloContext.Current.Services.ShipmentService;
            var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.DefaultKeys.ShipmentStatus.Quoted, "test-tracking");
            var attempt = builder.Build();
            Assert.IsTrue(attempt.Success, "Failed to build shipment");

            //// Act
            var shipment = attempt.Result;
            shipmentService.Save(shipment);

            //// Assert
            Assert.IsTrue(shipment.HasIdentity);
        }
コード例 #11
0
        public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated()
        {
            //// Arrange
            var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.ShipmentStatus.Quoted, "test-tracking", "http://somewhere.com", "carrier");

            //// Act
            var attempt = builder.Build();

            if (!attempt.Success)
            {
                Console.WriteLine(attempt.Exception.Message);
            }

            //// Assert
            Assert.IsTrue(attempt.Success);
        }
コード例 #12
0
        public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated()
        {
            //// Arrage
            var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key));

            //// Act
            var attempt = builder.Build();

            if (!attempt.Success)
            {
                Console.WriteLine(attempt.Exception.Message);
            }

            //// Assert
            Assert.IsTrue(attempt.Success);
        }
コード例 #13
0
        public void Can_Detect_A_ShipmentStatusChange()
        {
            //// Arrange
            var address = new Address()
            {
                Address1    = "111 Somewhere St.",
                Locality    = "Bellingham",
                Region      = "WA",
                PostalCode  = "98225",
                CountryCode = "US",
                Name        = "Merchello"
            };

            var invoice = MockInvoiceDataMaker.GetMockInvoiceForTaxation();

            var payment = new Payment(PaymentMethodType.Cash, invoice.Total)
            {
                Collected = true, Authorized = true
            };

            MerchelloContext.Current.Services.PaymentService.Save(payment);

            MerchelloContext.Current.Services.InvoiceService.Save(invoice);

            var appliedPaymentService = ((ServiceContext)(MerchelloContext.Current.Services)).AppliedPaymentService;

            var appliedPayment = appliedPaymentService.CreateAppliedPaymentWithKey(
                payment.Key,
                invoice.Key,
                AppliedPaymentType.Debit,
                "Payment applied",
                payment.Amount);

            invoice = MerchelloContext.Current.Services.InvoiceService.GetByKey(invoice.Key);

            Assert.NotNull(invoice);

            var order = invoice.PrepareOrder();

            MerchelloContext.Current.Services.OrderService.Save(order);

            var builder = new ShipmentBuilderChain(MerchelloContext.Current, order, order.Items.Select(x => x.Key), Guid.NewGuid(), Constants.DefaultKeys.ShipmentStatus.Packaging, "Track", "http://url.com", "carrier");

            var attempt = builder.Build();

            Assert.IsTrue(attempt.Success);
        }
コード例 #14
0
        public void Can_Save_A_Shipment_After_Its_Built()
        {
            //// Arrange
            var shipmentService = MerchelloContext.Services.ShipmentService;
            var builder         = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key), Constants.DefaultKeys.ShipmentStatus.Quoted);
            var attempt         = builder.Build();

            Assert.IsTrue(attempt.Success, "Failed to build shipment");

            //// Act
            var shipment = attempt.Result;

            shipmentService.Save(shipment);

            //// Assert
            Assert.IsTrue(shipment.HasIdentity);
        }
コード例 #15
0
        public void Can_Save_A_Shipment_After_Its_Built()
        {
            //// Arrange
            var shipmentService = MerchelloContext.Current.Services.ShipmentService;
            var builder         = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.ShipmentStatus.Quoted, "test-tracking", "http://somewhere.com", "carrier");
            var attempt         = builder.Build();

            Assert.IsTrue(attempt.Success, "Failed to build shipment");

            //// Act
            var shipment = attempt.Result;

            shipmentService.Save(shipment);

            //// Assert
            Assert.IsTrue(shipment.HasIdentity);
        }
コード例 #16
0
        public void Can_Detect_A_ShipmentStatusChange()
        {
            //// Arrange
            var address = new Address()
                              {
                                  Address1 = "111 Somewhere St.",
                                  Locality = "Bellingham",
                                  Region = "WA",
                                  PostalCode = "98225",
                                  CountryCode = "US",
                                  Name = "Merchello"
                              };

            var invoice = MockInvoiceDataMaker.GetMockInvoiceForTaxation();

            var payment = new Payment(PaymentMethodType.Cash, invoice.Total) { Collected = true, Authorized = true };

            MerchelloContext.Current.Services.PaymentService.Save(payment);

            MerchelloContext.Current.Services.InvoiceService.Save(invoice);

            var appliedPaymentService = ((ServiceContext)(MerchelloContext.Current.Services)).AppliedPaymentService;

            var appliedPayment = appliedPaymentService.CreateAppliedPaymentWithKey(
                payment.Key,
                invoice.Key,
                AppliedPaymentType.Debit,
                "Payment applied",
                payment.Amount);

            invoice = MerchelloContext.Current.Services.InvoiceService.GetByKey(invoice.Key);

            Assert.NotNull(invoice);

            var order = invoice.PrepareOrder();

            MerchelloContext.Current.Services.OrderService.Save(order);

            var builder = new ShipmentBuilderChain(MerchelloContext.Current, order, order.Items.Select(x => x.Key), Guid.NewGuid(), Constants.DefaultKeys.ShipmentStatus.Packaging, "Track");

            var attempt = builder.Build();

            Assert.IsTrue(attempt.Success);
        }
コード例 #17
0
        public ShipmentDisplay NewShipment(OrderDisplay order)
        {
            try
            {
                if(!order.Items.Any()) throw new InvalidOperationException("The shipment did not include any line items");

                var merchOrder = _orderService.GetByKey(order.Key);

                var builder = new ShipmentBuilderChain(MerchelloContext, order.ToOrder(merchOrder));

                var attempt = builder.Build();

                if(!attempt.Success)
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception));

                return attempt.Result.ToShipmentDisplay();

            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message)));
            }
        }
コード例 #18
0
        public ShipmentDisplay NewShipment(ShipmentRequestDisplay shipmentRequest)
        {
            try
            {
                if (!shipmentRequest.Order.Items.Any()) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The shipment did not include any line items"));

                var merchOrder = _orderService.GetByKey(shipmentRequest.Order.Key);

                var builder = new ShipmentBuilderChain(MerchelloContext, merchOrder, shipmentRequest.Order.Items.Select(x => x.Key), shipmentRequest.ShipMethodKey, shipmentRequest.ShipmentStatusKey, shipmentRequest.TrackingNumber);

                var attempt = builder.Build();

                if (!attempt.Success)
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception));

                return attempt.Result.ToShipmentDisplay();

            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message)));
            }
        }