private void TestValidateReportSettings(string name, string path, List <Tuple <string, string> > scripts, string expectedError) { try { var invalidReport = new ReportInfo(name, path, scripts); invalidReport.Validate(); Assert.Fail("Should have failed to validate ReportInfo"); } catch (ArgumentException e) { Assert.AreEqual(expectedError, e.Message); } }
public void TestValidateConfig() { TestUtils.InitializeInstallations(); var validName = "Name"; var invalidName = ""; var validSkyr = TestUtils.GetTestFilePath("UniqueReport.skyr"); var invalidSkyr = "invalidPath.skyr"; var validRScripts = new List <Tuple <string, string> >(); var invalidRscripts = new List <Tuple <string, string> > { new Tuple <string, string>("invalidPath.r", "1.2.3") }; TestValidateReportSettings(validName, invalidSkyr, validRScripts, "Report \"Name\": Report path invalidPath.skyr is not a valid path."); TestValidateReportSettings(validName, validSkyr, invalidRscripts, "Report \"Name\": R script path invalidPath.r is not a valid path."); TestValidateReportSettings(invalidName, validSkyr, validRScripts, "Report must have name."); try { var validReport = new ReportInfo(validName, validSkyr, validRScripts); validReport.Validate(); } catch (Exception) { Assert.Fail("Should have validated valid ReportInfo"); } var validTemplatePath = TestUtils.GetTestFilePath("emptyTemplate.sky"); var invalidTemplatePath = TestUtils.GetTestFilePath("nonexistent.sky"); var validAnalysisFolder = TestUtils.GetTestFilePath("") + "folderToCreate"; var invalidAnalysisFolder = TestUtils.GetTestFilePath("") + @"nonexistentOne\nonexistentTwo\"; var validDataDir = TestUtils.GetTestFilePath("emptyData"); var invalidDataDir = TestUtils.GetTestFilePath("nonexistentData"); var validPattern = ""; TestValidateMainSettings(invalidTemplatePath, validAnalysisFolder, validDataDir, validPattern, string.Format("Skyline file {0} does not exist.", invalidTemplatePath)); TestValidateMainSettings(validTemplatePath, invalidAnalysisFolder, validDataDir, validPattern, string.Format("Analysis folder directory {0} does not exist.", TestUtils.GetTestFilePath("") + @"nonexistentOne\nonexistentTwo")); TestValidateMainSettings(validTemplatePath, validAnalysisFolder, invalidDataDir, validPattern, string.Format("Data folder {0} does not exist.", invalidDataDir)); TestValidateMainSettings(invalidTemplatePath, invalidAnalysisFolder, invalidDataDir, validPattern, string.Format("Skyline file {0} does not exist.", invalidTemplatePath)); try { var testValidMainSettings = new MainSettings(validTemplatePath, validAnalysisFolder, validDataDir, null); testValidMainSettings.Validate(); } catch (Exception) { Assert.Fail("Should have validated valid MainSettings"); } var validMainSettings = new MainSettings(validTemplatePath, validAnalysisFolder, validDataDir, null); var validReportSettings = new ReportSettings(new List <ReportInfo>()); var validSkylineSettings = new SkylineSettings(SkylineType.Custom, "C:\\Program Files\\Skyline"); try { var invalidConfig = new SkylineBatchConfig(invalidName, DateTime.MinValue, DateTime.MinValue, validMainSettings, validReportSettings, validSkylineSettings); invalidConfig.Validate(); Assert.Fail("Should have failed to validate invalid config"); } catch (Exception e) { Assert.AreEqual("Please enter a name for the configuration.", e.Message); } try { var validConfig = new SkylineBatchConfig(validName, DateTime.MinValue, DateTime.MinValue, validMainSettings, validReportSettings, validSkylineSettings); validConfig.Validate(); } catch (Exception e) { Assert.Fail("Should have validated valid config"); } }