internal static Shipment ToShipment(this ShipmentRequestModel requestModel) => new Shipment
 {
     AffiliateKey      = requestModel.AffiliateKey.Value,
     ShipmentTypeKey   = requestModel.ShipmentTypekey.Value,
     Price             = requestModel.Price.Value,
     ReceiverName      = requestModel.ReceiverName,
     ReceiverSurname   = requestModel.ReceiverSurname,
     ReceiverAddress   = requestModel.ReceiverAddress,
     ReceiverZipCode   = requestModel.ReceiverZipCode,
     ReceiverCity      = requestModel.ReceiverCity,
     ReceiverCountry   = requestModel.ReceiverCountry,
     ReceiverTelephone = requestModel.ReceiverTelephone,
     ReceiverEmail     = requestModel.ReceiverEmail
 };
            Returns_201_And_Shipment_If_Request_Authorized_And_Success()
            {
                // Arange
                Guid[] availableShipmentTypeKeys = new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                };

                var config = IntegrationTestHelper
                             .GetInitialIntegrationTestConfig(GetContainer(availableShipmentTypeKeys));

                var shipmentRequestModel = new ShipmentRequestModel {
                    ShipmentTypeKey   = availableShipmentTypeKeys[1],
                    AffiliateKey      = Guid.NewGuid(),
                    Price             = 12.23M,
                    ReceiverName      = "Receiver 1 Name",
                    ReceiverSurname   = "Receiver 1 Surname",
                    ReceiverAddress   = "Receiver 1 Address",
                    ReceiverCity      = "Receiver 1 City",
                    ReceiverCountry   = "Receiver 1 Country",
                    ReceiverTelephone = "Receiver 1 Country",
                    ReceiverZipCode   = "12345",
                    ReceiverEmail     = "*****@*****.**"
                };

                var request = HttpRequestMessageHelper
                              .ConstructRequest(
                    httpMethod: HttpMethod.Post,
                    uri: string.Format(
                        "https://localhost/{0}",
                        ApiBaseRequestPath),
                    mediaType: "application/json",
                    username: Constants.ValidAdminUserName,
                    password: Constants.ValidAdminPassword);

                request.Content = new ObjectContent <ShipmentRequestModel>(
                    shipmentRequestModel, new JsonMediaTypeFormatter());

                // Act
                var shipmentDto = await IntegrationTestHelper
                                  .GetResponseMessageBodyAsync <ShipmentDto>(
                    config, request, HttpStatusCode.Created);

                // Assert
                Assert.Equal(shipmentRequestModel.Price, shipmentDto.Price);
                Assert.Equal(shipmentRequestModel.ReceiverName, shipmentDto.ReceiverName);
                Assert.Equal(shipmentRequestModel.ReceiverEmail, shipmentDto.ReceiverEmail);
                Assert.NotNull(shipmentDto.ShipmentType);
                Assert.True(shipmentDto.ShipmentStates.Count() > 0);
            }
        public HttpResponseMessage PostShipment(ShipmentRequestModel requestModel)
        {
            var createdShipmentResult =
                _shipmentService.AddShipment(requestModel.ToShipment());

            if (!createdShipmentResult.IsSuccess)
            {
                return(new HttpResponseMessage(HttpStatusCode.Conflict));
            }

            var response = Request.CreateResponse(HttpStatusCode.Created,
                                                  createdShipmentResult.Entity.ToShipmentDto());

            response.Headers.Location = new Uri(
                Url.Link(RouteName, new {
                key = createdShipmentResult.Entity.Key
            })
                );

            return(response);
        }
            Returns_400_If_Request_Authorized_But_Invalid()
            {
                // Arange
                Guid[] availableShipmentTypeKeys = new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                };

                var config = IntegrationTestHelper
                             .GetInitialIntegrationTestConfig(GetContainer(availableShipmentTypeKeys));

                var shipmentRequestModel = new ShipmentRequestModel {
                    ReceiverName      = "ANameWhichIsMoreThan50CharsANameWhichIsMoreThan50Chars",
                    ReceiverSurname   = "ASurnameWhichIsMoreThan50CharsASurnameWhichIsMoreThan50Chars",
                    ReceiverAddress   = "AnAddressWhichIsMoreThan50CharsAnAddressWhichIsMoreThan50Chars",
                    ReceiverCity      = "ACityWhichIsMoreThan50CharsACityWhichIsMoreThan50Chars",
                    ReceiverTelephone = "ATelephoneWhichIsMoreThan50CharsATelephoneWhichIsMoreThan50Chars",
                    ReceiverEmail     = "fooexample.com"
                };

                var request = HttpRequestMessageHelper
                              .ConstructRequest(
                    httpMethod: HttpMethod.Post,
                    uri: string.Format(
                        "https://localhost/{0}",
                        ApiBaseRequestPath),
                    mediaType: "application/json",
                    username: Constants.ValidAdminUserName,
                    password: Constants.ValidAdminPassword);

                request.Content = new ObjectContent <ShipmentRequestModel>(
                    shipmentRequestModel, new JsonMediaTypeFormatter());

                var httpError = await IntegrationTestHelper.
                                GetResponseMessageBodyAsync <HttpError>(
                    config, request, HttpStatusCode.BadRequest);

                var modelState             = (HttpError)httpError["ModelState"];
                var affiliateKeyError      = modelState["requestModel.AffiliateKey"] as string[];
                var shipmentTypeKeyError   = modelState["requestModel.ShipmentTypeKey"] as string[];
                var priceError             = modelState["requestModel.Price"] as string[];
                var receiverNameError      = modelState["requestModel.ReceiverName"] as string[];
                var receiverSurnameError   = modelState["requestModel.ReceiverSurname"] as string[];
                var receiverAddressError   = modelState["requestModel.ReceiverAddress"] as string[];
                var receiverCityError      = modelState["requestModel.ReceiverCity"] as string[];
                var receiverCountryError   = modelState["requestModel.ReceiverCountry"] as string[];
                var receiverTelephoneError = modelState["requestModel.ReceiverTelephone"] as string[];
                var receiverEmailError     = modelState["requestModel.ReceiverEmail"] as string[];
                var receiverZipCodeError   = modelState["requestModel.ReceiverZipCode"] as string[];

                // Assert
                Assert.NotNull(affiliateKeyError);
                Assert.NotNull(shipmentTypeKeyError);
                Assert.NotNull(priceError);
                Assert.NotNull(receiverNameError);
                Assert.NotNull(receiverSurnameError);
                Assert.NotNull(receiverAddressError);
                Assert.NotNull(receiverCityError);
                Assert.NotNull(receiverCountryError);
                Assert.NotNull(receiverTelephoneError);
                Assert.NotNull(receiverEmailError);
                Assert.NotNull(receiverZipCodeError);
            }