public async Task GetAllSensorsAsync() { await DataBaseHelper.ClearDatabaseAsync(); var newFirstSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.Deployed }; var newSecondSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.Refurbished }; var firstSensor = SensorsApi.ApiV1SensorsPost(newFirstSensor); var secondSensor = SensorsApi.ApiV1SensorsPost(newSecondSensor); var result = SensorsApi.ApiV1SensorsGet(); Assert.Equal(2, result.Count); Assert.Equal(firstSensor.Id, result[0].Id); Assert.Equal(firstSensor.FarmId, result[0].FarmId); Assert.Equal(firstSensor.State, result[0].State); Assert.Equal(secondSensor.Id, result[1].Id); Assert.Equal(secondSensor.FarmId, result[1].FarmId); Assert.Equal(secondSensor.State, result[1].State); }
/// <summary> /// /// </summary> /// <param name="body"></param> /// <returns>Sensor</returns> public Sensor ApiV1SensorsPost(CreateSensorCommand body) { var path = "/api/v1/sensors"; 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(body); // 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 ApiV1SensorsPost: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling ApiV1SensorsPost: " + response.ErrorMessage, response.ErrorMessage); } return((Sensor)ApiClient.Deserialize(response.Content, typeof(Sensor), response.Headers)); }
public CreateEntityCommandResult Create([FromBody] CreateSensorCommand command) { if (command == null) { command = new CreateSensorCommand(); } return(Execute <CreateSensorCommand, CreateEntityCommandResult>(command)); }
public Task Put(Guid id, [FromBody] CreateSensorCommand request) { var update = new UpdateSensorCommand { Id = id, FarmId = request.FarmId, State = request.State }; return(_mediator.Send(update)); }
public void CreateSensor() { var newSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.Deployed }; var Sensor = SensorsApi.ApiV1SensorsPost(newSensor); Assert.Equal(newSensor.FarmId, Sensor.FarmId); Assert.Equal(newSensor.State, Sensor.State); Assert.NotEqual(Guid.Empty, Sensor.Id); }
public void GetSensor() { var newSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.Refurbished }; var Sensor = SensorsApi.ApiV1SensorsPost(newSensor); var result = SensorsApi.ApiV1SensorsIdGet(Sensor.Id); Assert.Equal(newSensor.FarmId, Sensor.FarmId); Assert.Equal(newSensor.State, Sensor.State); Assert.Equal(Sensor.FarmId, result.FarmId); Assert.Equal(Sensor.State, result.State); Assert.Equal(Sensor.Id, result.Id); }
public void DeleteSensor() { var newSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.FarmerTriage }; var Sensor = SensorsApi.ApiV1SensorsPost(newSensor); var result = SensorsApi.ApiV1SensorsIdGet(Sensor.Id); Assert.Equal(newSensor.FarmId, Sensor.FarmId); Assert.Equal(newSensor.State, Sensor.State); Assert.Equal(Sensor.FarmId, result.FarmId); Assert.Equal(Sensor.State, result.State); Assert.Equal(Sensor.Id, result.Id); SensorsApi.ApiV1SensorsIdDelete(Sensor.Id); result = SensorsApi.ApiV1SensorsIdGet(Sensor.Id); Assert.Null(result); }
public void UpdateSensor() { var newSensor = new CreateSensorCommand { FarmId = Guid.NewGuid(), State = SensorState.Inventory }; var Sensor = SensorsApi.ApiV1SensorsPost(newSensor); newSensor.FarmId = Guid.NewGuid(); newSensor.State = SensorState.Deployed; SensorsApi.ApiV1SensorsIdPut(Sensor.Id, newSensor); var result = SensorsApi.ApiV1SensorsIdGet(Sensor.Id); Assert.Equal(newSensor.FarmId, result.FarmId); Assert.Equal(newSensor.State, result.State); Assert.Equal(Sensor.Id, result.Id); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="body"></param> /// <returns></returns> public void ApiV1SensorsIdPut(Guid?id, CreateSensorCommand body) { // verify the required parameter 'id' is set if (id == null) { throw new ApiException(400, "Missing required parameter 'id' when calling ApiV1SensorsIdPut"); } var path = "/api/v1/sensors/{id}"; path = path.Replace("{format}", "json"); path = path.Replace("{" + "id" + "}", ApiClient.ParameterToString(id)); 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(body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling ApiV1SensorsIdPut: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling ApiV1SensorsIdPut: " + response.ErrorMessage, response.ErrorMessage); } return; }
public async Task <ActionResult <int> > Create([FromBody] CreateSensorCommand command) { int result = await Mediator.Send(command); return(Ok(result)); }
public Task <Sensor> Post([FromBody] CreateSensorCommand request) { return(_mediator.Send(request)); }
public async Task <GenericCommandResult> Create([FromBody] CreateSensorCommand command, [FromServices] SensorHandler handler) { return((GenericCommandResult)await handler.Handle(command)); }