public async Task <IHttpActionResult> Post([FromBody] ServerLoadRequest request) { this.serverLoadDataValidator = new ServerLoadDataValidator(request); if (!this.serverLoadDataValidator.IsValid()) { return(BadRequest("Unable to store data due to invalid properties")); } // normally would use AutoMapper here but doing it manually to keep it simple ServerLoadTransaction transaction = new ServerLoadTransaction { TimeStamp = DateTime.Now, ServerName = request.ServerName, CpuLoad = request.CpuLoad, RamLoad = request.RamLoad }; try { await this.ServerLoadService.Record(transaction); return(Ok()); // hack: this should really be Created but we don't have a route in this implementation } catch (Exception ex) { return(InternalServerError(ex)); } }
public void ServerLoadData_Validator_CpuLoadNegative_Fail() { var data = new ServerLoadRequest { ServerName = "MyServer", RamLoad = 11.009, CpuLoad = -13.23 }; var validator = new ServerLoadDataValidator(data); Assert.IsFalse(validator.IsValid()); }
public void ServerLoadData_Validator_ServerNameEmpty_Fail() { var data = new ServerLoadRequest { ServerName = string.Empty, RamLoad = 11.009, CpuLoad = 9.034 }; var validator = new ServerLoadDataValidator(data); Assert.IsFalse(validator.IsValid()); }
public void ServerLoadData_Validator_CpuLoadZero_Success() { var data = new ServerLoadRequest { ServerName = "MyServer", RamLoad = 11.009, CpuLoad = 0.0 }; var validator = new ServerLoadDataValidator(data); Assert.IsTrue(validator.IsValid()); }