public HttpResponseMessage PostShipmentState(Guid key, ShipmentStateRequestModel requestModel) { var createdShipmentState = _shipmentService.AddShipmentState( key, RetrieveShipmentStatus(requestModel.ShipmentStatus)); if (!createdShipmentState.IsSuccess) { return new HttpResponseMessage(HttpStatusCode.Conflict); } var response = Request.CreateResponse(HttpStatusCode.Created, createdShipmentState.Entity.ToShipmentStateDto()); return response; }
private static Tuple<HttpConfiguration, HttpRequestMessage> GetConfigAndRequestMessage( Guid[] shipmentKeys, Guid validshipmentKey, ShipmentStateRequestModel requestModel) { var config = IntegrationTestHelper .GetInitialIntegrationTestConfig(GetContainer(shipmentKeys)); var request = HttpRequestMessageHelper .ConstructRequest( httpMethod: HttpMethod.Post, uri: string.Format( "https://localhost/{0}", string.Format(ApiBaseRequestPathFormat, validshipmentKey)), mediaType: "application/json", username: Constants.ValidEmployeeUserName, password: Constants.ValidEmployeePassword); if (requestModel != null) { request.Content = new ObjectContent<ShipmentStateRequestModel>( requestModel, new JsonMediaTypeFormatter()); } return Tuple.Create(config, request); }
public async Task Returns_400_If_Request_Authorized_But_Invalid() { // Arrange Guid[] shipmentKeys = IntegrationTestHelper.GetKeys(9); var validshipmentKey = shipmentKeys[1]; var shipmentStateRequestModel = new ShipmentStateRequestModel { ShipmentStatus = "Done" }; var configAndRequest = GetConfigAndRequestMessage( shipmentKeys, validshipmentKey, shipmentStateRequestModel); // Act var httpError = await IntegrationTestHelper .GetResponseMessageBodyAsync<HttpError>( configAndRequest.Item1, configAndRequest.Item2, HttpStatusCode.BadRequest); var modelState = (HttpError)httpError["ModelState"]; var shipmentStatusModelError = modelState["requestModel.ShipmentStatus"] as string[]; // Assert Assert.NotNull(shipmentStatusModelError); }
public async Task Returns_409_If_Request_Authorized_But_Conflicted() { // Arrange Guid[] shipmentKeys = IntegrationTestHelper.GetKeys(9); var validshipmentKey = shipmentKeys[1]; var shipmentStateRequestModel = new ShipmentStateRequestModel { ShipmentStatus = "Ordered" }; var configAndRequest = GetConfigAndRequestMessage( shipmentKeys, validshipmentKey, shipmentStateRequestModel); // Act var response = await IntegrationTestHelper .GetResponseAsync(configAndRequest.Item1, configAndRequest.Item2); // Assert Assert.Equal(HttpStatusCode.Conflict, response.StatusCode); }
public async Task Returns_201_And_ShipmentState_If_Request_Authorized_And_Success() { // Arrange Guid[] shipmentKeys = IntegrationTestHelper.GetKeys(9); var validshipmentKey = shipmentKeys[1]; var shipmentStateRequestModel = new ShipmentStateRequestModel { ShipmentStatus = "InTransit" }; var configAndRequest = GetConfigAndRequestMessage( shipmentKeys, validshipmentKey, shipmentStateRequestModel); // Act var shipmentStateDto = await IntegrationTestHelper .GetResponseMessageBodyAsync<ShipmentStateDto>( configAndRequest.Item1, configAndRequest.Item2, HttpStatusCode.Created); // Assert Assert.Equal(shipmentStateRequestModel.ShipmentStatus, shipmentStateDto.ShipmentStatus); Assert.Equal(validshipmentKey, shipmentStateDto.ShipmentKey); }