Esempio n. 1
0
        public void GivenTwoParcelsOf1CMDimension_WhenCreateDelivery_ThenCorrectTotalIsReturned()
        {
            var expectedTotalCost = 6m;
            var parcel1           = _parcelService.CreateParcel(1, 1, 1, 1);
            var parcel2           = _parcelService.CreateParcel(1, 1, 1, 1);
            var parcels           = new List <Parcel> {
                parcel1, parcel2
            };
            var delivery = _deliveryService.CreateDelivery(parcels);

            delivery.TotalDeliveryCost.ShouldBe(expectedTotalCost);
            _testOutputHelper.WriteLine(ReturnDeliveryOutput(delivery));
        }
Esempio n. 2
0
        public async void CanRemoveDelivery()
        {
            var newDelivery = await deliveryService.CreateDelivery(new Delivery
            {
                OrderId      = 50,
                Status       = DeliveryStatus.Approved,
                AccessWindow = new AccessWindow
                {
                    StartTime = DateTime.Now,
                    EndTime   = DateTime.Now.AddHours(2)
                },
                Sender = new Partner
                {
                    Name = "Ikea"
                },
                Recipient = new User
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    Email     = "*****@*****.**",
                    Address   = "Test Street, London",
                    Phone     = "0845345"
                }
            });

            var delivery = await deliveryService.RemoveDelivery(newDelivery.Id);

            Assert.NotNull(delivery);
        }
Esempio n. 3
0
        public async Task <IActionResult> Post([FromBody] CreateDeliveryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await deliveryService.DeliveryExists(model.OrderId))
            {
                return(BadRequest("Delivery for this order already exists"));
            }

            if (DateTime.Now > model.EndTime)
            {
                return(BadRequest($"{nameof(model.EndTime)} is already expired"));
            }

            if (model.StartTime > model.EndTime)
            {
                return(BadRequest($"{nameof(model.StartTime)} cannot be greater than {nameof(model.EndTime)}"));
            }

            var newDelivery = mapper.Map <Delivery>(model);

            var delivery = await deliveryService.CreateDelivery(newDelivery);

            // TODO: inject using constructor   integration require restructuring of the application
            // TODO: messages should be sent to specific user channels
            // TODO: also on each update of delivery a message should be published to relevent partner or user
            var ably    = new AblyRealtime("E9RI8g.3I-QYw:F0Q-ZJK5Xwm2bGvf");
            var channel = ably.Channels.Get("Users");

            // Publish a message to the test channel
            channel.Publish("Delivery Add", $"A new delivery is added");
            // TODO: needs a better strategy to return the complete delivery view model
            var deliveryModel = mapper.Map <DeliveryViewModel>(await deliveryService.GetDeliveryById(delivery.Id));

            return(Ok(deliveryModel));
        }
 public async Task <IActionResult> Post([FromBody] DeliveryBindingModel model)
 {
     return(Ok(_mapper.Map <DeliveryBindingModel>(await _deliveryService.CreateDelivery(_mapper.Map <Delivery>(model)))));
 }
        public IActionResult Create(int orderId)
        {
            var modelData = deliveryService.CreateDelivery(orderId);

            return(View(modelData));
        }