Example #1
0
        public SendTrackNotificationResult SendTrackNotification(OrderTrackingInformation orderTrackingInformation)
        {
            OrderTrackingInfoAdapter adaptee = new OrderTrackingInfoAdapter();

            using (var client = new HttpClient())
            {
                /*
                 * Autenticacao pode ser feita aqui
                 */
                var url = ServiceConfiguration.GetConfigurations()
                          .Configuration
                          .GetConfiguration()
                          .ApiUrl;

                HttpResponseMessage response = null;
                try
                {
                    response = client.PostAsync(url, new JsonContent(adaptee.Adapt(orderTrackingInformation))).Result;
                }
                catch (Exception ex)
                {
                    return(new SendTrackNotificationResult(response));
                }

                return(new SendTrackNotificationResult(response));
            }
        }
Example #2
0
        public void TrackingInfoIsConvertingRightToSalePlatformInfo()
        {
            DateTime date = DateTime.Now;
            OrderTrackingInformation info = new OrderTrackingInformation()
            {
                Order_id = 123,
                Event    = new OrderTrackingEvent()
                {
                    Date      = date,
                    Status_id = 1,
                }
            };

            SalePlatformTrackInfo expected = new SalePlatformTrackInfo()
            {
                Date    = date,
                OrderId = 123,
                Status  = "in_transit"
            };

            OrderTrackingInfoAdapter adapter = new OrderTrackingInfoAdapter();
            var dest = adapter.Adapt(info);

            Assert.Equal(expected.Date, dest.Date);
            Assert.Equal(expected.OrderId, dest.OrderId);
            Assert.Equal(expected.Status, dest.Status);
        }
Example #3
0
        public void SendTrackInformationIsBeingSent()
        {
            IPlatformProxy proxy = IntegrationProxy.GetInstance(new IntegrationProxyArgs.IntegrationProxyArgsBuilder().BuildDefault()).Proxy;

            var input = new OrderTrackingInformation()
            {
                Order_id = 12,
                Event    = new OrderTrackingEvent()
                {
                    Date      = DateTime.Now,
                    Status_id = 1
                }
            };

            Assert.True(proxy.SendTrackNotification(input).IsSuccess);
        }
Example #4
0
        public async Task RegularPostShoudReturn200()
        {
            TrackingController controller = new TrackingController();

            var input = new OrderTrackingInformation()
            {
                Order_id = 12,
                Event    = new OrderTrackingEvent()
                {
                    Date      = DateTime.Now,
                    Status_id = 1
                }
            };

            var resultapi = await controller.Post(input);

            OkResult result = Assert.IsType <OkResult>(resultapi);

            Assert.Equal <int>(200, result.StatusCode);
        }
Example #5
0
        public async void MissingFieldShouldReturn400()
        {
            TrackingController controller = new TrackingController();

            var input = new OrderTrackingInformation()
            {
                Order_id = null,
                Event    = new OrderTrackingEvent()
                {
                    Date      = DateTime.Now,
                    Status_id = 1
                }
            };

            var result = await controller.Post(input);

            BadRequestObjectResult viewResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal <int>(400, viewResult.StatusCode.Value);
        }
Example #6
0
        public async Task <IActionResult> Post([FromBody] OrderTrackingInformation value)
        {
            TrackingValidationManager validator = new TrackingValidationManager(this, value);

            if (!validator.Validate(this.ModelState))
            {
                return(this.BadRequest(this.ModelState));
            }

            var args = new IntegrationProxyArgsBuilder()
                       .SetPlatformType(SuportedPlatforms.SalePlatform)
                       .SetBaseURI("/api")
                       .Build();

            var result = IntegrationProxy.GetInstance(args)
                         .Proxy.SendTrackNotification(value);

            if (!result.IsSuccess)
            {
                return(this.BadRequest(result.Message));
            }

            return(this.Ok("Platform was notified successfully"));
        }
Example #7
0
 public async Task <IActionResult> Post([FromBody] OrderTrackingInformation value)
 {
     return(this.Ok());//se chegou aqui, retorna 200 (case desse erro a API do middleware iria tratar )
 }
Example #8
0
 public TrackingValidationManager(TrackingController subject, OrderTrackingInformation model) : base(subject)
 {
     this.model = model;
 }