public ShipmentTypeDto PutShipmentType(
            Guid key,
            ShipmentTypeRequestModel requestModel) {

            var shipmentType = _shipmentService.GetShipmentType(key);
            if (shipmentType == null) {

                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var updatedShipmentType = _shipmentService.UpdateShipmentType(
                requestModel.ToShipmentType(shipmentType));

            return updatedShipmentType.ToShipmentTypeDto();
        }
        public HttpResponseMessage PostShipmentType(
            ShipmentTypeRequestModel requestModel) {

            var createdShipmentTypeResult = _shipmentService
                .AddShipmentType(requestModel.ToShipmentType());

            if (!createdShipmentTypeResult.IsSuccess) {

                return new HttpResponseMessage(HttpStatusCode.Conflict);
            }

            var response = Request.CreateResponse(HttpStatusCode.Created,
                createdShipmentTypeResult.Entity.ToShipmentTypeDto());

            response.Headers.Location = new Uri(Url.Link("DefaultHttpRoute",
                    new { key = createdShipmentTypeResult.Entity.Key }));

            return response;
        }
                Returns_200_And_Updated_ShipmentType_If_Request_Authorized_But_Request_Is_Valid() {

                // Arrange
                Guid[] keys = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var requestKey = keys[1];
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(GetContainer(keys));

                var shipmentTypeRequestModel = new ShipmentTypeRequestModel {
                    Name = "X-Large",
                    Price = 40.00M
                };

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

                request.Content = new ObjectContent<ShipmentTypeRequestModel>(
                    shipmentTypeRequestModel, new JsonMediaTypeFormatter());

                // Act
                var shipmentTypeDto = await IntegrationTestHelper
                    .GetResponseMessageBodyAsync<ShipmentTypeDto>(
                        config, request, HttpStatusCode.OK);

                // Assert
                Assert.Equal(requestKey, shipmentTypeDto.Key);
                Assert.Equal(shipmentTypeRequestModel.Name, shipmentTypeDto.Name);
                Assert.Equal(shipmentTypeRequestModel.Price, shipmentTypeDto.Price);
            }
                Returns_400_If_Request_Authorized_But_Invalid() {

                // Arrange
                Guid[] keys = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var requestKey = keys[1];
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(GetContainer(keys));

                var shipmentTypeRequestModel = new ShipmentTypeRequestModel {
                    Name = "ANameWhichIsMoreThan50CharsANameWhichIsMoreThan50Chars",
                    Price = 40.00M
                };

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

                request.Content = new ObjectContent<ShipmentTypeRequestModel>(
                    shipmentTypeRequestModel, new JsonMediaTypeFormatter());

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

                var modelState = (HttpError)httpError["ModelState"];
                var nameError = modelState["requestModel.Name"] as string[];

                // Assert
                Assert.NotNull(nameError);
            }
                Returns_404_If_Request_Authorized_But_ShipmentType_Does_Not_Exist() {

                // Arrange
                Guid[] keys = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
                var invalidRequestKey = Guid.NewGuid();
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(GetContainer(keys));

                var shipmentTypeRequestModel = new ShipmentTypeRequestModel { 
                    Name = "X-Large",
                    Price = 40.00M
                };

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

                request.Content = new ObjectContent<ShipmentTypeRequestModel>(
                    shipmentTypeRequestModel, new JsonMediaTypeFormatter());

                // Act
                var response = await IntegrationTestHelper
                    .GetResponseAsync(config, request);

                // Assert
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
                Returns_409_If_Request_Authorized_But_Conflicted() {

                // Arrange
                var shipmentTypes = GetDummyShipmentTypes(new[] { 
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() });
                var targetShipmentType = shipmentTypes.FirstOrDefault();
                var config = IntegrationTestHelper
                    .GetInitialIntegrationTestConfig(
                        GetContainer(shipmentTypes));

                var shipmentTypeRequestModel = new ShipmentTypeRequestModel {
                    Name = targetShipmentType.Name,
                    Price = 40.00M
                };

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

                request.Content = new ObjectContent<ShipmentTypeRequestModel>(
                    shipmentTypeRequestModel, new JsonMediaTypeFormatter());

                // Act
                var response = await IntegrationTestHelper
                    .GetResponseAsync(config, request);

                // Assert
                Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
            }