public async Task <IActionResult> postJson([FromBody] InstallationRoot payload, [FromQuery] string repo = "scdfiles") { try { // create installation with a 10% chance of failing InstallationSim instSim = simHandler.createFailedInstallationByChance(payload, 10); StatusType status = await instSim.runSetup(); if (status == StatusType.STATUS_FINISHED_SUCCESS) { var jsonString = JsonConvert.SerializeObject(payload, Formatting.Indented); await GitController.createFile("Create: " + payload.installation.name, jsonString, "./installations/" + payload.installation.name + "/" + payload.installation.name + ".json", repo); return(Ok("{\"status\": 200, \"message\": \"Success.\", \"installation_status\": \"" + status + "\"}")); } else { return(BadRequest("{\"status\": 400, \"message\": \"Creation of installation failed.\", \"installation_status\": \"" + StatusType.STATUS_FINISHED_FAILED + "\"}")); } } catch (ApiValidationException) { return(BadRequest("{\"status\": 400, \"message\": \"File already exists in github repo.\", \"installation_status\": \"" + StatusType.STATUS_FINISHED_FAILED + "\"}")); } catch (Exception) { return(BadRequest("{\"status\": 400, \"message\": \"Unknown error.\", \"installation_status\": \"" + StatusType.STATUS_FINISHED_FAILED + "\"}")); } }
public async Task createInstallation_installation_fail() { InstallationSim i1 = simHandler.createFailedInstallation("failed installation 1", 1000, 1000, 1000, output); await Task.Run(async() => { await i1.runSetup(); }); Assert.Equal(StatusType.STATUS_FINISHED_FAILED, i1.status); }
public async Task createInstallation_installations_success(string inst, int startTime, int runTime) { // sending output as func param to avoid test output bugs compared to making a class field in simHandler InstallationSim i1 = simHandler.createSuccessfulInstallation(inst, startTime, runTime, output); // use whenall to make it run parallel and speed up mulitple setups await Task.WhenAll( Task.Run(() => i1.runSetup()) ); Assert.Equal(StatusType.STATUS_FINISHED_SUCCESS, i1.status); }
public async Task createInstallation_installations_success_and_fail() { InstallationSim i1 = simHandler.createSuccessfulInstallation("success installation 3", 1000, 1000, output); InstallationSim i2 = simHandler.createFailedInstallation("failed installation 2", 1000, 1000, 1000, output); // use whenall to make it run parallel and speed up mulitple setups await Task.WhenAll( Task.Run(() => i1.runSetup()), Task.Run(() => i2.runSetup()) ); Assert.Equal(StatusType.STATUS_FINISHED_SUCCESS, i1.status); Assert.Equal(StatusType.STATUS_FINISHED_FAILED, i2.status); }
public async Task <IActionResult> copyJson([FromBody] CopyData data, [FromQuery] string repo = "scdfiles") { try { IActionResult actionResult = await getJson(data.oldName, repo); var content = actionResult as OkObjectResult; string jsonString = content.Value.ToString(); jsonString = jsonString.Replace(data.oldName, data.newName); InstallationRoot newInstallation = JsonConvert.DeserializeObject <InstallationRoot>(jsonString); // create installation with a 10% chance of failing InstallationSim sim = simHandler.createFailedInstallationByChance(newInstallation, 10); await sim.runSetup(); if (sim.status == StatusType.STATUS_FINISHED_SUCCESS) { await GitController.CopyFile(data.newName, data.oldName, repo, jsonString); } else { return(BadRequest("{\"status\": 400, \"message\": \"Failed to create file.\", \"installation_status\": \"" + sim.status + "\"}")); } } catch (NullReferenceException) { return(BadRequest("{\"status\": 400, \"message\": \"Could not find file with the given filename.\"}")); } catch (ApiValidationException) { return(BadRequest("{\"status\": 400, \"message\": \"File already exists in github repo.\"}")); } catch (Exception) { return(BadRequest("{\"status\": 400, \"message\": \"Unknown error.\"}")); } return(Ok("{\"status\": 200, \"message\": \"Success.\", \"installation_status\": \"" + StatusType.STATUS_FINISHED_SUCCESS + "\"}")); }