public void StringEndsWithTest() { string input = @"this is a test"; Assert.IsTrue(HgUtility.StringEndsWith(input, @"test")); Assert.IsFalse(HgUtility.StringEndsWith(input, @"plop")); }
public void HashFileTest() { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data", @"HgUtility", @"HashFile.txt"); string hash = HgUtility.HashFile(path); Assert.AreEqual(@"2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c", hash); }
private string HashFile() { string hash = HgUtility.HashFile(FileFullName); if (string.IsNullOrEmpty(hash)) { return(""); } return(hash); }
public void StringTrimTest() { string input = @" this is a test "; string value = HgUtility.StringTrim(input); Assert.AreEqual(@"this is a test", value); input = @" this is a test "; value = HgUtility.StringTrim(input); Assert.AreEqual(@"this is a test", value); }
public void StringSplitTest() { string input = @"this is a test"; string[] values = HgUtility.StringSplit(input, " ", StringSplitOptions.None); Assert.AreEqual(4, values.Length); input = @"this,is,another,test"; values = HgUtility.StringSplit(input, ",", StringSplitOptions.None); Assert.AreEqual(4, values.Length); input = @"this,is,,another,test"; values = HgUtility.StringSplit(input, ",", StringSplitOptions.None); Assert.AreEqual(5, values.Length); input = @"this,is,,another,test"; values = HgUtility.StringSplit(input, ",", StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(4, values.Length); input = @"this is again, a test"; values = HgUtility.StringSplit(input, " ,", StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(5, values.Length); }
protected void CreateProfile(DataSet dataSet) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSet.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); Assert.AreEqual(dataSet.Name, engineScript.Name); Assert.AreEqual(dataSet.Title, engineScript.Title); Assert.AreEqual(dataSet.Author, engineScript.Author); Assert.AreEqual(dataSet.FileCount, engineScript.Files.Count); Assert.IsTrue(engineScript.IsValid()); Assert.IsFalse(engineScript.IsAltered(true)); Assert.IsTrue(engineScript.Official); LuaManager luaManager = new LuaManager(); bool loadEngine = luaManager.LoadEngine(engineScript); Assert.IsTrue(loadEngine); if (!Directory.Exists(dataSet.SourceFolder)) { Directory.CreateDirectory(dataSet.SourceFolder); } foreach (var setting in luaManager.ActiveEngine.Settings.Where(s => s.Kind == EngineSettingKind.Setup).OrderBy(s => - s.Index)) { Assert.IsTrue(dataSet.Settings.ContainsKey(setting.Name)); if (setting is EngineSettingCombobox settingCombobox) { settingCombobox.Value = (int)dataSet.Settings[setting.Name]; } if (setting is EngineSettingFolderBrowser settingFolder) { Assert.IsTrue(settingFolder.CanAutoDetect == dataSet.CanAutoDetect); if (dataSet.CanAutoDetect) { Assert.IsNotNull(settingFolder.OnAutoDetect); Assert.DoesNotThrow(() => { string s = settingFolder.OnAutoDetect?.Call().FirstOrDefault() as string; Assert.IsNotNull(s); }); } settingFolder.Value = (string)dataSet.Settings[setting.Name]; } } Assert.IsNotNull(luaManager.ActiveEngine.OnSetupValidate); Assert.DoesNotThrow(() => { bool?b = luaManager.ActiveEngine.OnSetupValidate.Call().First() as bool?; Assert.IsNotNull(b); Assert.IsTrue(b.Value); }); if (luaManager.ActiveEngine.OnSetupSuggestProfileName != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.OnSetupSuggestProfileName.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); Assert.IsTrue(HgUtility.IsValidFileName(s)); Assert.AreEqual(dataSet.SuggestProfileName, s); }); } if (luaManager.ActiveEngine.ReadMe != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.ReadMe.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); }); } var profileFile = new ProfileFile { EngineScriptName = engineScript.Name, Name = dataSet.ProfileName }; luaManager.SaveSnapshots(profileFile); luaManager.SaveSettings(profileFile); string filePath = Path.Combine(dataSet.SourceFolder, dataSet.ProfileName + "_Create.shp"); profileFile.FilePath = filePath; ProfileFile.Save(profileFile); Assert.DoesNotThrow(() => { profileFile.Release(); }); string expected = File.ReadAllText(Path.Combine(dataSet.DataRoot, "Original", dataSet.ProfileName + "_Create.shp")); expected = expected.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); string produced = File.ReadAllText(filePath); Assert.AreEqual(expected, produced); luaManager.Release(); Directory.Delete(dataSet.SourceFolder, true); }
public void HashStringTest() { string hash = HgUtility.HashString(@"this is a test"); Assert.AreEqual(@"2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c", hash); }