/// <summary> /// /// </summary> /// <param name="record"></param> /// <returns></returns> public IRestResponse ApiPressurePost(AddPressureRecordDto record) { var path = "/api/v1/pressure"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(record); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if ((int)response.StatusCode >= 400) { throw new ApiException((int)response.StatusCode, "Error calling ApiPressurePost: " + response.Content, response.Content); } if (response.StatusCode == 0) { throw new ApiException((int)response.StatusCode, "Error calling ApiPressurePost: " + response.ErrorMessage, response.ErrorMessage); } return(response); }
public IActionResult Create([FromBody] AddPressureRecordDto record) { LastCall.lastCall = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest()); } var response = _pressureApi.ApiPressurePost(record); return(Ok(response.Content)); }
public async Task Given_Create_When_InvalidModelState_Then_ShouldRespondWithBadRequestAsync() { //Arrange var addRecord = new AddPressureRecordDto(); var controller = CreateSut(); controller.ModelState.SetModelValue("", ValueProviderResult.None); //Act var response = await controller.Create(addRecord); //Assert response.Should().BeOfType <BadRequestResult>(); }
public async Task <IActionResult> Create([FromBody] AddPressureRecordDto record) { if (!ModelState.IsValid) { return(BadRequest()); } var command = _mapper.Map <AddPressureRecordCommand>(record); var result = await _mediator.Send(command); var createdRecordId = result.Id; return(Created("api/v1/pressure/" + createdRecordId, createdRecordId)); }
public async Task Given_Create_When_ValidModelState_Then_ShouldRespondWithCreatedAsync() { //Arrange var addRecord = new AddPressureRecordDto(); var id = new Guid(); var commandResult = new AddPressureRecordCommandResult(id); Mediator.Setup(med => med.Send(It.IsAny <AddPressureRecordCommand>(), CancellationToken.None)) .Returns(Task.FromResult(commandResult)); var controller = CreateSut(); //Act var response = await controller.Create(addRecord); //Assert response.Should().BeOfType <CreatedResult>(); }