public void ItCreatesSimulationWithValidInput() { // Arrange const string ID = "1"; var simulation = this.GetSimulationById(ID); this.simulationsService .Setup(x => x.InsertAsync(It.IsAny <Simulation>(), It.IsAny <string>())) .ReturnsAsync(simulation); // Act var result = this.target.PostAsync( SimulationApiModel.FromServiceModel( simulation, this.servicesConfig.Object, this.deploymentConfig.Object, this.connectionStringManager.Object, this.simulationRunner.Object, this.rateReporter.Object ) ).Result; // Assert Assert.NotNull(result); Assert.Equal(simulation.Id, result.Id); }
public async Task <SimulationApiModel> PatchAsync( string id, [FromBody] SimulationPatchApiModel patch) { if (patch == null) { this.log.Warn("NULL patch provided", () => new { id }); throw new BadRequestException("No data or invalid data provided"); } SimulationPatch patchServiceModel = patch.ToServiceModel(id); if (patchServiceModel.Enabled == false) { patchServiceModel.Statistics = new SimulationStatistics { AverageMessagesPerSecond = this.rateReporter.GetThroughputForMessages(), TotalMessagesSent = this.simulationRunner.TotalMessagesCount }; } var simulation = await this.simulationsService.MergeAsync(patchServiceModel); return(SimulationApiModel.FromServiceModel( simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter)); }
public void ItUpdatesSimulationThroughPutMethod() { // Arrange const string DEFAULT_SIMULATION_ID = "1"; var simulation = this.GetSimulationById(DEFAULT_SIMULATION_ID); this.simulationsService .Setup(x => x.UpsertAsync(It.IsAny <Simulation>())) .ReturnsAsync(simulation); // Act var result = this.target.PutAsync( SimulationApiModel.FromServiceModel( simulation, this.servicesConfig.Object, this.deploymentConfig.Object, this.connectionStringManager.Object, this.simulationRunner.Object, this.rateReporter.Object ), DEFAULT_SIMULATION_ID ).Result; // Assert Assert.Equal(DEFAULT_SIMULATION_ID, result.Id); }
public void ItUpdatesSimulationThroughPutMethod() { // Arrange const string DEFAULT_SIMULATION_ID = "1"; var simulation = this.GetSimulationById(DEFAULT_SIMULATION_ID); this.simulationsService .Setup(x => x.UpsertAsync(It.IsAny <Simulation>(), true)) .ReturnsAsync(simulation); // Act var simulationApiModel = SimulationApiModel.FromServiceModel( simulation); var result = this.target.PutAsync( simulationApiModel, DEFAULT_SIMULATION_ID ).Result; // Assert Assert.Equal(DEFAULT_SIMULATION_ID, result.Id); // Assert - The simulation is created validating the connection string this.simulationsService.Verify( x => x.UpsertAsync(It.IsAny <Simulation>(), true), Times.Once); }
public async Task <SimulationApiModel> PostAsync( [FromBody] SimulationApiModel simulationApiModel, [FromQuery(Name = "template")] string template = "") { if (simulationApiModel != null) { await simulationApiModel.ValidateInputRequestAsync(this.log, this.connectionStringManager); } else { if (string.IsNullOrEmpty(template)) { this.log.Warn("No data or invalid data provided", () => new { simulationApiModel, template }); throw new BadRequestException("No data or invalid data provided."); } // Simulation can be created with `template=default` other than created with input data simulationApiModel = new SimulationApiModel(); } var simulation = await this.simulationsService.InsertAsync(simulationApiModel.ToServiceModel(null), template); return(SimulationApiModel.FromServiceModel( simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter)); }
public async Task <SimulationApiModel> GetAsync(string id) { var simulation = await this.simulationsService.GetAsync(id); var simulationApiModel = SimulationApiModel.FromServiceModel( simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter); return(simulationApiModel); }
public void ItReturnsSimulationApiModelFromServiceModel() { // Arrange var simulation = this.GetSimulationModel(); // Act var result = SimulationApiModel.FromServiceModel(simulation); // Assert Assert.IsType <SimulationApiModel>(result); Assert.Equal(simulation.Id, result.Id); }
public void ItThrowsExceptionWhenCreateASimulationWithInValidInput() { // Arrange var simulation = new Simulation(); // Act & Assert Assert.ThrowsAsync <BadRequestException>( async() => await this.target.PostAsync( SimulationApiModel.FromServiceModel(simulation) ) ).CompleteOrTimeout(); }
public async Task <SimulationApiModel> PatchAsync( string id, [FromBody] SimulationPatchApiModel patch) { if (patch == null) { this.log.Warn("NULL patch provided", () => new { id }); throw new BadRequestException("No data or invalid data provided"); } return(SimulationApiModel.FromServiceModel( await this.simulationsService.MergeAsync(patch.ToServiceModel(id)))); }
public async Task <SimulationApiModel> PutAsync( [FromBody] SimulationApiModel simulation, string id = "") { simulation?.ValidateInputRequest(this.log, this.connectionStringManager); if (simulation == null) { this.log.Warn("No data or invalid data provided", () => new { simulation }); throw new BadRequestException("No data or invalid data provided."); } return(SimulationApiModel.FromServiceModel( await this.simulationsService.UpsertAsync(simulation.ToServiceModel(id)))); }
public void ItCreatesSimulationWithValidInput() { // Arrange const string ID = "1"; var simulation = this.GetSimulationById(ID); this.simulationsService .Setup(x => x.InsertAsync(It.IsAny <Simulation>(), It.IsAny <string>())) .ReturnsAsync(simulation); // Act var simulationApiModel = SimulationApiModel.FromServiceModel(simulation); var result = this.target.PostAsync(simulationApiModel).CompleteOrTimeout().Result; // Assert Assert.NotNull(result); Assert.Equal(simulation.Id, result.Id); }
public async Task <SimulationApiModel> PutAsync([FromBody] SimulationApiModel simulationApiModel, string id = "") { if (simulationApiModel == null) { this.log.Warn("No data provided, request object is null"); throw new BadRequestException("No data provided, request object is empty."); } await simulationApiModel.ValidateInputRequestAsync(this.log, this.connectionStringValidation); // Load the existing resource, so that internal properties can be copied var existingSimulation = await this.GetExistingSimulationAsync(id); var simulation = await this.simulationsService.UpsertAsync(simulationApiModel.ToServiceModel(existingSimulation, this.defaultRatingConfig, id)); return(SimulationApiModel.FromServiceModel(simulation)); }
public void ItThrowsExceptionWhenCreateASimulationWithInValidInput() { // Arrange var simulation = new Simulation(); // Act & Assert Assert.ThrowsAsync <BadRequestException>( async() => await this.target.PostAsync( SimulationApiModel.FromServiceModel( simulation, this.servicesConfig.Object, this.deploymentConfig.Object, this.connectionStringManager.Object, this.simulationRunner.Object, this.rateReporter.Object ) ) ) .Wait(Constants.TEST_TIMEOUT); }
public async Task <SimulationApiModel> PostAsync( [FromBody] SimulationApiModel simulation, [FromQuery(Name = "template")] string template = "") { simulation?.ValidateInputRequest(this.log, this.connectionStringManager); if (simulation == null) { if (string.IsNullOrEmpty(template)) { this.log.Warn("No data or invalid data provided", () => new { simulation, template }); throw new BadRequestException("No data or invalid data provided."); } simulation = new SimulationApiModel(); } return(SimulationApiModel.FromServiceModel( await this.simulationsService.InsertAsync(simulation.ToServiceModel(), template))); }
public async Task <SimulationApiModel> GetAsync(string id) { var simulation = await this.simulationsService.GetWithStatisticsAsync(id); return(SimulationApiModel.FromServiceModel(simulation)); }
public async Task <SimulationApiModel> GetAsync(string id) { return(SimulationApiModel.FromServiceModel(await this.simulationsService.GetAsync(id))); }