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 fromServiceModelTask =
                SimulationApiModel.FromServiceModelAsync(
                    simulation,
                    this.servicesConfig.Object,
                    this.deploymentConfig.Object,
                    this.connectionStringManager.Object,
                    this.simulationRunner.Object,
                    this.rateReporter.Object
                    );

            fromServiceModelTask.Wait(Constants.TEST_TIMEOUT);

            var result = this.target.PutAsync(
                fromServiceModelTask.Result,
                DEFAULT_SIMULATION_ID
                ).Result;

            // Assert
            Assert.Equal(DEFAULT_SIMULATION_ID, result.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 fromServiceModelTask =
                SimulationApiModel.FromServiceModelAsync(
                    simulation,
                    this.servicesConfig.Object,
                    this.deploymentConfig.Object,
                    this.connectionStringManager.Object,
                    this.simulationRunner.Object,
                    this.rateReporter.Object);

            fromServiceModelTask.Wait(Constants.TEST_TIMEOUT);

            var postAsyncTask = this.target.PostAsync(fromServiceModelTask.Result);

            postAsyncTask.Wait(Constants.TEST_TIMEOUT);
            var result = postAsyncTask.Result;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(simulation.Id, result.Id);
        }
Beispiel #3
0
        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(await SimulationApiModel.FromServiceModelAsync(
                       simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter));
        }
Beispiel #4
0
        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(await SimulationApiModel.FromServiceModelAsync(
                       simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter));
        }
Beispiel #5
0
        public async Task <SimulationApiModel> GetAsync(string id)
        {
            var simulation = await this.simulationsService.GetAsync(id);

            var simulationApiModel = await SimulationApiModel.FromServiceModelAsync(
                simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter);

            return(simulationApiModel);
        }
        public void ItThrowsExceptionWhenCreateASimulationWithInValidInput()
        {
            // Arrange
            var simulation = new Simulation();

            // Act & Assert
            Assert.ThrowsAsync <BadRequestException>(
                async() => await this.target.PostAsync(
                    await SimulationApiModel.FromServiceModelAsync(
                        simulation,
                        this.servicesConfig.Object,
                        this.deploymentConfig.Object,
                        this.connectionStringManager.Object,
                        this.simulationRunner.Object,
                        this.rateReporter.Object
                        )
                    )
                )
            .Wait(Constants.TEST_TIMEOUT);
        }
Beispiel #7
0
        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.connectionStringManager);

            // 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, id));

            return(await SimulationApiModel.FromServiceModelAsync(
                       simulation, this.servicesConfig, this.deploymentConfig, this.connectionStringManager, this.simulationRunner, this.rateReporter));
        }