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 void WhenInstallPathIsParameterisedAbsolutePath_InstallationPathIsExactlyInstallPathParameter() { var configuration = new DeploydConfiguration(); var instance = new InstanceConfiguration() { AppName = "SomeApplication", InstallPath = @"c:\installfolder" }; var fileSystem = new MockFileSystem(); var installationRoot = new InstallationRoot(configuration, instance, fileSystem); Assert.That(installationRoot.Path, Is.EqualTo(@"c:\installfolder")); }
public void create_random_installation_fail() { InstallationRoot testInst = new InstallationRoot(); // set data of installation to avoid null reference testInst.installation = new Installation(); testInst.installation.name = "TEST_INSTALLATION"; InstallationSim instSim = simHandler.createFailedInstallationByChance(testInst, 100); Assert.True(instSim.shouldFail); }
public void WhenInstallPathIsParameterisedRelativePath_InstallationPathIsRelativeToConfiguredPath() { var configuration = new DeploydConfiguration() { InstallRoot = @"c:\" }; var instance = new InstanceConfiguration() { AppName = "SomeApplication", InstallPath = @"relativepath" }; var fileSystem = new MockFileSystem(); var installationRoot = new InstallationRoot(configuration, instance, fileSystem); Assert.That(installationRoot.Path, Is.EqualTo(@"c:\relativepath")); }
public void WhenInstallRootIsConfigured_InstallationPathIsInstallRootPlusApplicationName() { var configuration = new DeploydConfiguration() { InstallRoot = @"c:\" }; var instance = new InstanceConfiguration() { AppName = "SomeApplication" }; var fileSystem = new MockFileSystem(); var installationRoot = new InstallationRoot(configuration, instance, fileSystem); Assert.That(installationRoot.Path, Is.EqualTo(@"c:\SomeApplication")); }
public InstallationSim createFailedInstallationByChance(InstallationRoot installation, int chance) { InstallationSim randomInstallation; int installationChance = rand.Next(1, 101); int rndMin = rand.Next(3000, 6001); int rndMax = rand.Next(4000, 10001); if (installationChance <= chance) { randomInstallation = new InstallationSim(installation, rndMin, rndMax, true, 2000); } else { randomInstallation = new InstallationSim(installation, rndMin, rndMax, false, 0); } return(randomInstallation); }
public async Task <IActionResult> getState([FromQuery] string name, [FromQuery] string repo = "scdfiles") { string path = "installations/" + name + "/" + name + ".json"; try { var content = await GitController.getFile(path, repo); var res = content.ElementAt <RepositoryContent>(0); InstallationRoot installation = JsonConvert.DeserializeObject <InstallationRoot>(res.Content); string state = installation.installation.state; return(Ok(state)); } catch (Exception) { return(BadRequest("Error getting state.")); } }
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 + "\"}")); }
public void create_random_installations() { int numOfFailedInstallations = 0; InstallationRoot testInst = new InstallationRoot(); // set data of installation to avoid null reference testInst.installation = new Installation(); testInst.installation.name = "TEST_INSTALLATION"; for (int i = 0; i < 1000; i++) { InstallationSim instSim = simHandler.createFailedInstallationByChance(testInst, 50); if (instSim.shouldFail) { numOfFailedInstallations++; } } // Assume that at least 1 installation will fail on a thousand runs with a 50% chance of failing Assert.True(numOfFailedInstallations > 0); }
public InstallationSim createFailedInstallation(InstallationRoot installation, int startTime, int runTime, int failTime) { InstallationSim installationFail = new InstallationSim(installation, startTime, runTime, true, failTime); return(installationFail); }
public InstallationSim createFailedInstallation(InstallationRoot installation, int startTime, int runTime, int failTime, ITestOutputHelper output) { InstallationSim installationFail = new InstallationSim(installation, startTime, runTime, true, failTime, output); return(installationFail); }
public InstallationSim createSuccessfulInstallation(InstallationRoot installation, int startTime, int runTime) { InstallationSim installationSuccess = new InstallationSim(installation, startTime, runTime, false, 0); return(installationSuccess); }
public InstallationSim createSuccessfulInstallation(InstallationRoot installation, int startTime, int runTime, ITestOutputHelper output) { InstallationSim installationSuccess = new InstallationSim(installation, startTime, runTime, false, 0, output); return(installationSuccess); }