Ejemplo n.º 1
0
        public async Task <IBookShipmentResponse> BookShipment(Action <IBookShipmentRequest> requestBuilder)
        {
            if (string.IsNullOrEmpty(_secretKey) || string.IsNullOrEmpty(_privateKey))
            {
                throw new NotImplementedException();
            }

            var request = new BookShipmentRequest(Endpoint);

            requestBuilder(request);

            var rawJson     = JsonConvert.SerializeObject(request, _serializerSettings);
            var httpRequest = new HttpRequest <BookShipmentRequest, BookShipmentResponse>(request);

            httpRequest.ConstructRequest(() => {
                var requestDateTime = DateTime.Now;

                var message = new HttpRequestMessage(request.Method, request.Endpoint)
                {
                    Content = new StringContent(rawJson)
                };

                message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                var authentication = SignRequest(request.Method, rawJson, message.Content.Headers.ContentType.ToString(),
                                                 "/api/shipment/", requestDateTime);

                message.Headers.TryAddWithoutValidation("Authorization", $"{_privateKey}:{authentication}");
                message.Headers.Date = requestDateTime;
                return(message);
            });

            return(await SendWithLock(httpRequest));
        }
Ejemplo n.º 2
0
        public async Task WhenCreatingRequest_ShouldMatchApproved()
        {
            // Arrange
            var request = new BookShipmentRequest("/")
                          .WithReadyByDate(new DateTime(2021, 01, 25, 14, 0, 0))
                          .WithHawb("123123123")
                          .WithDescription("test Clothing")
                          .WithDocuments()
                          .WithPieces(pieces => pieces
                                      .AddPiece(piece => piece
                                                .Depth(1.00m)
                                                .Height(1.00m)
                                                .Width(1.00m)
                                                .Weight(1.00m)
                                                .NumberOfPieces(1)))
                          .WithConsignee(consignee => consignee
                                         .ContactName("Test")
                                         .Company("Test")
                                         .Address1("2 Willow Road")
                                         .Zipcode("SL3 0BS")
                                         .City("Slough")
                                         .CountryCode("GB"))
                          .WithServiceCode("IEL");

            // Act
            var bookingJson = JsonConvert.SerializeObject(request, Formatting.Indented, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new [] {
                    new StringEnumConverter()
                }
            });

            // Assert
            bookingJson.ShouldMatchApproved();
        }