public void PutThrowsErrorWithInvalidInput() { // Arrange const string ID = "deviceModelId"; var deviceModel = this.GetDeviceModelById(ID); // Act & Assert Assert.ThrowsAsync <BadRequestException>( async() => await this.target.PutAsync(DeviceModelApiModel.FromServiceModel(deviceModel))) .Wait(Constants.TEST_TIMEOUT); }
public void ItReturnsDeviceModelFromServiceModel() { // Arrange var deviceModel = this.GetDeviceModel(); // Act var result = DeviceModelApiModel.FromServiceModel(deviceModel); // Assert Assert.IsType <DeviceModelApiModel>(result); Assert.Equal(deviceModel.Id, result.Id); }
public async Task <DeviceModelApiModel> PostAsync( [FromBody] DeviceModelApiModel deviceModel) { if (deviceModel == null) { this.log.Warn("No data provided"); throw new BadRequestException("No data provided."); } deviceModel.ValidateInputRequest(this.log); return(DeviceModelApiModel.FromServiceModel(await this.deviceModelsService.InsertAsync(deviceModel.ToServiceModel()))); }
public async Task <DeviceModelApiModel> PutAsync( [FromBody] DeviceModelApiModel deviceModel, string id = "") { if (deviceModel == null) { this.log.Warn("No data provided", () => new { }); throw new BadRequestException("No data provided."); } deviceModel.ValidateInputRequest(this.log); return(DeviceModelApiModel.FromServiceModel( await this.deviceModelsService.UpsertAsync(deviceModel.ToServiceModel(id)))); }
public void PostCreatesTheDeviceModelWithValidInput() { // Arrange const string ID = "deviceModelId"; var deviceModel = this.GetDeviceModelById(ID); DeviceModelApiModel deviceModelApiModel = GetValidDeviceModelApiModel(ID); this.deviceModelsService .Setup(x => x.InsertAsync(It.IsAny <DeviceModel>())) .ReturnsAsync(deviceModel); // Act var result = this.target.PostAsync(deviceModelApiModel).Result; // Assert Assert.NotNull(result); Assert.Equal(deviceModel.Id, result.Id); }
private DeviceModelApiModel GetValidDeviceModelApiModel() { var deviceModelApiModel = new DeviceModelApiModel { Id = "id", Type = "Custom", ETag = "Etag_1", Protocol = "AMQP", Telemetry = new List <DeviceModelTelemetry>() { new DeviceModelTelemetry() { Interval = "00:00:10", MessageTemplate = "template", MessageSchema = new DeviceModelTelemetryMessageSchema() { Name = "name", Format = "JSON", Fields = new Dictionary <string, string>() { { "key", "value" } } } } }, Simulation = new DeviceModelSimulation() { Interval = "00:00:10", Scripts = new List <DeviceModelSimulationScript>() { new DeviceModelSimulationScript() { Type = "type", Path = "path", Params = JObject.Parse("{\"ccc\":{\"Min\":\"1\",\"Max\":\"11\",\"Step\":1,\"Unit\":\"y\"}}") } } } }; return(deviceModelApiModel); }
public async Task <DeviceModelApiModel> GetAsync(string id) { return(DeviceModelApiModel.FromServiceModel(await this.deviceModelsService.GetAsync(id))); }
public DeviceModelApiModel Get(string id) { return(DeviceModelApiModel.FromServiceModel(this.deviceModelsService.Get(id))); }