public ActionResult addSlotToCustomizedProduct(long id, [FromBody] AddCustomizedDimensionsModelView slotDimensions, [FromHeader(Name = "UserToken")] string userAuthToken) { if (slotDimensions == null) { return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE))); } try { AddSlotModelView addSlotModelView = new AddSlotModelView(); addSlotModelView.customizedProductId = id; addSlotModelView.slotDimensions = slotDimensions; addSlotModelView.userAuthToken = userAuthToken; GetCustomizedProductModelView customizedProductModelView = new core.application.CustomizedProductController().addSlotToCustomizedProduct(addSlotModelView); return(Created(Request.Path, customizedProductModelView)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (NotAuthorizedException notAuthorizedException) { return(StatusCode(401, new SimpleJSONMessageService(notAuthorizedException.Message))); } catch (ArgumentException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (InvalidOperationException e) { return(BadRequest(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
public void ensureFromModelViewThrowsExceptionIfModelViewIsNull() { AddCustomizedDimensionsModelView addCustomizedDimensionsModelView = null; Action fromModelView = () => CustomizedDimensionsModelViewService.fromModelView(addCustomizedDimensionsModelView); Assert.Throws <ArgumentException>(fromModelView); }
public void ensureFromModelViewDoesNotConvertValuesIfNoUnitIsProvided() { AddCustomizedDimensionsModelView addCustomizedDimensionsModelView = new AddCustomizedDimensionsModelView(); addCustomizedDimensionsModelView.height = 30; addCustomizedDimensionsModelView.width = 50; addCustomizedDimensionsModelView.depth = 15; CustomizedDimensions customizedDimensions = CustomizedDimensionsModelViewService.fromModelView(addCustomizedDimensionsModelView); Assert.Equal(addCustomizedDimensionsModelView.height, customizedDimensions.height); Assert.Equal(addCustomizedDimensionsModelView.width, customizedDimensions.width); Assert.Equal(addCustomizedDimensionsModelView.depth, customizedDimensions.depth); }
public void ensureFromModelViewConvertsValuesToProvidedUnit() { AddCustomizedDimensionsModelView addCustomizedDimensionsModelView = new AddCustomizedDimensionsModelView(); string unit = "cm"; addCustomizedDimensionsModelView.height = 30; addCustomizedDimensionsModelView.width = 50; addCustomizedDimensionsModelView.depth = 15; addCustomizedDimensionsModelView.unit = unit; //the customized dimensions' values should be in the minimum unit CustomizedDimensions customizedDimensions = CustomizedDimensionsModelViewService.fromModelView(addCustomizedDimensionsModelView); Assert.Equal(addCustomizedDimensionsModelView.height, MeasurementUnitService.convertToUnit(customizedDimensions.height, unit)); Assert.Equal(addCustomizedDimensionsModelView.width, MeasurementUnitService.convertToUnit(customizedDimensions.width, unit)); Assert.Equal(addCustomizedDimensionsModelView.depth, MeasurementUnitService.convertToUnit(customizedDimensions.depth, unit)); }