public async Task can_start_application() { var builder = new WebHostBuilder() .UseKestrel() .UseUrls("http://localhost:5111") .UseStartup <Startup>(); var input = new RunInput { WebHostBuilder = builder }; var command = new RunCommand(); var task = Task.Factory.StartNew(() => command.Execute(input)); command.Started.Wait(5.Seconds()); using (var client = new HttpClient()) { var text = await client.GetStringAsync("http://localhost:5111"); text.ShouldBe("Hello"); } command.Reset.Set(); await task; }
public ActionResult Create(RunInput runInput) { _context.RunInputs.Add(runInput); _context.SaveChanges(); return(RedirectToAction("Index", "RunInput")); }
private BatchRunResponse execute(Action <RunInput> configure) { var path = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory() .AppendPath("Storyteller.Samples"); var input = new RunInput { Path = path }; configure(input); var controller = input.BuildRemoteController(); var task = controller.Start(EngineMode.Batch).ContinueWith(t => { var systemRecycled = t.Result; if (!systemRecycled.success) { systemRecycled.WriteSystemUsage(); throw new Exception("Unable to start the system"); } return(input.StartBatch(controller)); }); task.Wait(); task.Result.Wait(); return(task.Result.Result); }
private BatchRunResponse execute(Action <RunInput> configure) { var path = TestingContext.FindParallelDirectory("Storyteller.Samples"); var input = new RunInput { Path = path }; configure(input); var controller = input.BuildEngine(); var task = controller.Start().ContinueWith(t => { var systemRecycled = t.Result; if (!systemRecycled.success) { systemRecycled.WriteSystemUsage(); throw new Exception("Unable to start the system"); } return(input.StartBatch(controller)); }); task.Wait(); task.Result.Wait(); controller.Dispose(); return(task.Result.Result); }
public void exits_with_failure_if_workspace_does_not_exist() { var input = new RunInput { Path = Path, WorkspaceFlag = "Does-Not-Exist" }; new RunCommand().Execute(input).ShouldBe(false); }
public void configures_break_on_wrongs_false() { var input = new RunInput(); // default value input.BreakOnWrongsFlag.ShouldBeFalse(); input.ConfigureProject(); Project.CurrentProject.StopConditions.BreakOnWrongs.ShouldBeFalse(); }
public void write_json_results() { var file = "perf-" + Guid.NewGuid().ToString() + ".csv"; var input = new RunInput { Path = Path, JsonFlag = file }; new RunCommand().Execute(input); File.Exists(file).ShouldBe(true); }
public void use_specific_system_in_multi_system_project() { var directory = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory() .AppendPath("MultipleSystems"); var input = new RunInput { Path = directory, SystemNameFlag = "System2" }; var multiSystemController = input.BuildRemoteController(); var task = multiSystemController.Start(EngineMode.Batch); task.Wait(3.Seconds()); task.Result.system_name.ShouldBe("MultipleSystems.System2"); multiSystemController.Dispose(); }
public async Task PostRunOk() { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonFile("AppSettings.json"); IConfiguration configuration = configurationBuilder.Build(); RunService srv = new RunService( new DBRunContext(new DbContextOptionsBuilder <DBRunContext>().UseInMemoryDatabase("DBRuns").Options), configuration ); RunsController rc = new RunsController(srv); var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "00000000-0000-0000-0000-000000000000")); identity.AddClaim(new Claim(ClaimTypes.Role, "USER")); rc.ControllerContext = new ControllerContext(); rc.ControllerContext.HttpContext = new DefaultHttpContext(); rc.HttpContext.User = new ClaimsPrincipal(identity); // Arrange RunInput runInput01 = new RunInput() { Date = new System.DateTime(2020, 6, 20, 19, 51, 0), Distance = 5600, Time = 1100, Location = "Poggibonsi,IT" }; // Act IActionResult retValue = await rc.PostRun( new Guid("00000000-0000-0000-0000-000000000000"), runInput01 ); // Assert Assert.IsTrue(retValue is OkResult); }
public void SetUp() { var directory = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory() .AppendPath("Storyteller.Samples"); theController = new RemoteController(directory); theInput = new RunInput { Path = directory, RetriesFlag = 1 }; theController = theInput.BuildRemoteController(); var task = theController.Start(EngineMode.Batch); task.Wait(3.Seconds()); theFixtures = task.Result.fixtures; }
public async Task can_start_application() { var builder = Host.CreateDefaultBuilder(); var input = new RunInput { HostBuilder = builder }; var command = new RunCommand(); var task = Task.Factory.StartNew(() => command.Execute(input)); command.Started.Wait(5.Seconds()); command.Reset.Set(); await task; }
public async Task InsertOk() { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonFile("AppSettings.json"); IConfiguration configuration = configurationBuilder.Build(); RunService srv = new RunService( new DBRunContext(new DbContextOptionsBuilder <DBRunContext>().UseInMemoryDatabase("DBRuns").Options), configuration ); // Arrange int expected = 1; RunInput runInput01 = new RunInput() { Date = new System.DateTime(2020, 6, 20, 19, 51, 0), Distance = 5600, Time = 1100, Location = "Poggibonsi,IT" }; // Act int retValue = await srv.InsertRunAsync( new Guid("00000000-0000-0000-0000-000000000000"), runInput01 ); // Assert int actual = retValue; Assert.AreEqual(expected, actual, 0, "Ok, record inserted"); }
public run_command_integration_specs() { var directory = TestingContext.FindParallelDirectory("Storyteller.Samples"); var project = Project.LoadForFolder(directory); #if NET46 theController = new RemoteController(project, new AppDomainSystemLauncher(project)); #else throw new NotImplementedException("Not done yet for CoreCLR"); #endif theInput = new RunInput { Path = directory, RetriesFlag = 1 }; theController = theInput.BuildRemoteController(); var task = theController.Start(); task.Wait(3.Seconds()); theFixtures = task.Result.fixtures; }
public run_command_integration_specs() { TestUtility.CleanUpHangingProcesses(); var directory = TestingContext.FindParallelDirectory("Storyteller.Samples"); var project = Project.LoadForFolder(directory); #if NET46 theController = new EngineController(project, new AppDomainSystemLauncher(project)); #else theController = new EngineController(project, new ProcessRunnerSystemLauncher(project)); #endif theInput = new RunInput { Path = directory, RetriesFlag = 1 }; theController = theInput.BuildEngine(); var task = theController.Start(); task.Wait(3.Seconds()); theFixtures = task.Result.fixtures; }
public async Task InsertDistanceTimeLEZero(int distance, int time) { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonFile("AppSettings.json"); IConfiguration configuration = configurationBuilder.Build(); RunService srv = new RunService( new DBRunContext(new DbContextOptionsBuilder <DBRunContext>().UseInMemoryDatabase("DBRuns").Options), configuration ); // Arrange RunInput runInput01 = new RunInput() { Date = new System.DateTime(2020, 6, 20, 19, 51, 0), Distance = distance, Time = time, Location = "Poggibonsi,IT" }; // Assert await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>( () => srv.InsertRunAsync( new Guid("00000000-0000-0000-0000-000000000000"), runInput01 ) ); }
public async Task <int> InsertRunAsync(Guid userId, RunInput runInput) { if (runInput.Distance <= 0) { throw new ArgumentOutOfRangeException("Distance must be greater than zero"); } if (runInput.Time <= 0) { throw new ArgumentOutOfRangeException("Time must be greater than zero"); } DateTime dd = runInput.Date.AddDays(-1); string dt = new DateTimeOffset(dd, TimeSpan.Zero).ToUnixTimeSeconds().ToString(); string weather = ""; string weatherReqUri; HttpResponseMessage response; using (HttpClient httpClient = new HttpClient()) { weatherReqUri = Configuration["WeatherByCityReq"]; weatherReqUri = weatherReqUri.Replace("{cityCountry}", runInput.Location); response = await httpClient.GetAsync(weatherReqUri); string s = await response.Content.ReadAsStringAsync(); s = s.Substring(16); int cp = s.IndexOf(','); string lon = s.Substring(0, cp); s = s.Substring(lon.Length + 7); cp = s.IndexOf('}'); string lat = s.Substring(0, cp); weatherReqUri = Configuration["HistoricalWeatherReq"]; weatherReqUri = weatherReqUri .Replace("{lat}", lat) .Replace("{lon}", lon) .Replace("{time}", dt); response = await httpClient.GetAsync(weatherReqUri); weather = await response.Content.ReadAsStringAsync(); } if (weather.Length > 1000) // Limitazione alla lunghezza della colonna nel db { weather = weather.Substring(0, 1000); } Run run = new Run() { Id = Guid.NewGuid(), UserId = userId, Date = runInput.Date, Distance = runInput.Distance, Time = runInput.Time, Location = runInput.Location, Weather = weather }; Context.Runs.Add(run); return(await Context.SaveChangesAsync()); }
public async Task <IActionResult> PostRun([FromQuery(Name = "userId")] Guid userId, RunInput runInput) { if (!ModelState.IsValid) { return(BadRequest()); } if (Utils.GetUserRole(this.User) != Roles.ADMIN) { userId = Utils.GetUserId(this.User); } int result = await RunService.InsertRunAsync( userId, runInput ); if (result == 1) { return(Ok()); } else { return(Problem("Record creation was not possible")); } }