private void TestRemoveTask(TestCase t, SyncProfile curProfile) { char[] delimiters = new char[] { ',' }; String parameters = t.Param1; String[] inputParameters = parameters.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); if (curProfile.TaskExists(inputParameters[0])) { curProfile.RemoveTask(curProfile.GetTask(inputParameters[0]), ""); t.Actual = "True"; } else { t.Actual = "False"; } t.Passed = (t.Actual.Equals(t.Param2)) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void TestCompareFoldersOutput(TestCase t, Detector tester) { Console.WriteLine("Comparing Output..."); t.Actual = ""; int M = 0; int C = 0; int D = 0; // Add sCleanFiles output t.Actual += "sCleanFiles[" + tester.SCleanFiles.Primary.Count + "], "; #region Add sDirtyFiles output foreach (var info in tester.SDirtyFiles.PriSub) { String start = info.Value.Substring(0, 1); switch (start) { case "M": M++; break; case "C": C++; break; case "D": D++; break; } } t.Actual += "sDirtyFiles[" + tester.SDirtyFiles.PriSub.Count + ", " + M + "M" + C + "C" + D + "D], "; #endregion // Add tCleanFiles output t.Actual += "tCleanFiles[" + tester.TCleanFiles.Primary.Count + "], "; #region Add tDirtyFiles output M = 0; C = 0; D = 0; foreach (var info in tester.TDirtyFiles.PriSub) { String start = info.Value.Substring(0, 1); switch (start) { case "M": M++; break; case "C": C++; break; case "D": D++; break; } } t.Actual += "tDirtyFiles[" + tester.TDirtyFiles.PriSub.Count + ", " + M + "M" + C + "C" + D + "D], "; #endregion // Add sCleanFolders output t.Actual += "sCleanFolders[" + tester.SCleanDirs.Primary.Count + "], "; #region Add sDirtyFolders output C = 0; D = 0; foreach (var info in tester.SDirtyDirs.PriSub) { String start = info.Value.Substring(0, 1); switch (start) { case "C": C++; break; case "D": D++; break; } } t.Actual += "sDirtyFolders[" + tester.SDirtyDirs.PriSub.Count + ", " + C + "C" + D + "D], "; #endregion // Add tCleanFolders output t.Actual += "tCleanFolders[" + tester.TCleanDirs.Primary.Count + "], "; #region Add tDirtyFolders output C = 0; D = 0; foreach (var info in tester.TDirtyDirs.PriSub) { String start = info.Value.Substring(0, 1); switch (start) { case "C": C++; break; case "D": D++; break; } } t.Actual += "tDirtyFolders[" + tester.TDirtyDirs.PriSub.Count + ", " + C + "C" + D + "D]"; #endregion t.Passed = (t.Actual.Equals(t.Param4.Trim())) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; Console.WriteLine(); }
private void TestGetTask(TestCase t, SyncProfile curProfile) { char[] delimiters = new char[] { ',' }; String parameters = t.Param1; String[] inputParameters = parameters.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); SyncTask retrievedTask = curProfile.GetTask(inputParameters[0]); if (retrievedTask == null) { t.Actual = "null"; } else { t.Actual = retrievedTask.Name; } t.Passed = (t.Actual.Equals(t.Param2)) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void TestCompareFolders(TestCase t, SyncTask curTask) { RemoveExistingDirectories(curTask); Thread.Sleep(25); CreateTestDirectories(curTask); Thread.Sleep(25); CustomDictionary<String, String, FileUnit> srcMeta = new CustomDictionary<string, string, FileUnit>(); CustomDictionary<String, String, FileUnit> tgtMeta = new CustomDictionary<string, string, FileUnit>(); int srcLength = curTask.Source.Length; int tgtLength = curTask.Target.Length; char[] delimiters = new char[] { ',' }; String createScenario = t.Param2; String[] createFiles = createScenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); CreateOldState(curTask, t, createFiles, srcMeta, srcLength, tgtMeta, tgtLength); Thread.Sleep(25); String scenario = t.Param3; String[] performChanges = scenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); SimulateChanges(curTask, performChanges); Detector tester; TestCompareFolders(curTask, t, srcMeta, tgtMeta, out tester); TestCompareFoldersOutput(t, tester); }
private void TestCompareFolders(SyncTask curTask, TestCase t, CustomDictionary<string, string, FileUnit> srcMeta, CustomDictionary<string, string, FileUnit> tgtMeta, out Detector tester) { Console.WriteLine("Performing compareFolders()..."); tester = new Detector("TestCases", curTask); if (t.Param1.Equals("Y")) { tester.SMetaData = srcMeta; tester.TMetaData = tgtMeta; } else { tester.SMetaData = null; tester.TMetaData = null; } tester.CompareFolders(); }
private void TestCheckAutoRun(TestCase t, SyncSharpLogic curLogic) { char[] delimiters = new char[] { ',' }; String parameters = t.Param1; String[] inputParameters = parameters.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); bool autoRun = (inputParameters[0].Equals("True")) ? true : false; curLogic.CheckAutorun(autoRun); t.Actual = File.Exists(@".\Autorun.inf") ? "True" : "False"; t.Passed = t.Actual.Equals(t.Param2) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void TestCheckProfileExists(TestCase t, SyncSharpLogic curLogic) { t.Actual = (curLogic.CheckProfileExists(curLogic.GetMachineID())) ? "True" : "False"; t.Passed = (t.Actual.Equals(t.Param1)) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void TestAddTask(TestCase t, SyncProfile curProfile) { char[] delimiters = new char[] { ',' }; String parameters = t.Param1; String[] inputParameters = parameters.Split(delimiters); Validation.ErrorMsgCode errorTaskName = Validation.CheckTaskName(inputParameters[0], curProfile); Validation.ErrorMsgCode errorDuplicate = Validation.CheckFolderPair(ref inputParameters[1], ref inputParameters[2], curProfile, null); if (errorTaskName == Validation.ErrorMsgCode.NoError && errorDuplicate == Validation.ErrorMsgCode.NoError) { SyncTask newTask = new SyncTask(inputParameters[0], inputParameters[1], inputParameters[2]); curProfile.AddTask(newTask); } #region Get error msg code for task name switch (errorTaskName) { case Validation.ErrorMsgCode.EmptyTaskName: t.Actual = "EmptyTaskName"; break; case Validation.ErrorMsgCode.DuplicateTaskName: t.Actual = "DuplicateTaskName"; break; case Validation.ErrorMsgCode.InvalidTaskName: t.Actual = "InvalidTaskName"; break; default: t.Actual = "NoError"; break; } #endregion #region Get error msg code for folder pair switch (errorDuplicate) { case Validation.ErrorMsgCode.EmptySource: t.Actual += " EmptySource"; break; case Validation.ErrorMsgCode.EmptyTarget: t.Actual += " EmptyTarget"; break; case Validation.ErrorMsgCode.InvalidSource: t.Actual += " InvalidSource"; break; case Validation.ErrorMsgCode.InvalidTarget: t.Actual += " InvalidTarget"; break; case Validation.ErrorMsgCode.SameSourceTarget: t.Actual += " SameSourceTarget"; break; case Validation.ErrorMsgCode.SourceIsASubDirOfTarget: t.Actual += " SourceIsASubDirOfTarget"; break; case Validation.ErrorMsgCode.TargetIsASubDirOfSource: t.Actual += " TargetIsASubDirOfSource"; break; case Validation.ErrorMsgCode.DuplicateFolderPair: t.Actual += " DuplicateFolderPair"; break; default: t.Actual += " NoError"; break; } #endregion t.Passed = (t.Actual.Equals(t.Param2)) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void CreateOldState(SyncTask curTask, TestCase t, string[] createFiles, CustomDictionary<string, string, FileUnit> srcMeta, int srcLength, CustomDictionary<string, string, FileUnit> tgtMeta, int tgtLength) { foreach (String file in createFiles) { FileInfo newFile = new FileInfo(curTask.Source + file.Trim()); if (!newFile.Directory.Exists) { #region Create directories Directory.CreateDirectory(newFile.DirectoryName); FileInfo newFileTgt = new FileInfo(curTask.Target + file.Trim()); Directory.CreateDirectory(newFileTgt.DirectoryName); if (t.Param1.Equals("Y")) { String tempSrc = newFile.DirectoryName + @"\"; String tempTgt = newFileTgt.DirectoryName + @"\"; srcMeta.Add(tempSrc.Substring(srcLength), new FileUnit(newFile.DirectoryName)); tgtMeta.Add(tempTgt.Substring(tgtLength), new FileUnit(newFileTgt.DirectoryName)); } #endregion } #region Create files StreamWriter sw = newFile.CreateText(); sw.Close(); File.Copy(curTask.Source + file.Trim(), curTask.Target + file.Trim()); Console.WriteLine("Creating file " + file.Trim() + " on _source and _target directory..."); #endregion if (t.Param1.Equals("Y")) { #region Add to metadata list FileUnit srcFileUnit = new FileUnit(curTask.Source + file.Trim()); FileUnit tgtFileUnit = new FileUnit(curTask.Target + file.Trim()); String temp = null; if (file.Trim().StartsWith(@"\")) temp = file.Trim().Substring(1); else temp = file; srcMeta.Add(temp.Trim(), Utility.ComputeMyHash(srcFileUnit), srcFileUnit); tgtMeta.Add(temp.Trim(), Utility.ComputeMyHash(tgtFileUnit), tgtFileUnit); #endregion } } }
public void TestLoadProfile(TestCase t, SyncSharpLogic curLogic) { curLogic.LoadProfile(); curLogic.SaveProfile(); TestCheckProfileExists(t, curLogic); }
private void TestTaskExists(TestCase t, SyncProfile curProfile) { char[] delimiters = new char[] { ',' }; String parameters = t.Param1; String[] inputParameters = parameters.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); t.Actual = curProfile.TaskExists(inputParameters[0]).ToString(); t.Passed = t.Actual.Equals(t.Param2) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; }
private void TestSync(TestCase t, SyncTask curTask) { RemoveExistingDirectories(curTask); Thread.Sleep(25); CreateTestDirectories(curTask); Thread.Sleep(25); CustomDictionary<String, String, FileUnit> srcMeta = new CustomDictionary<string, string, FileUnit>(); CustomDictionary<String, String, FileUnit> tgtMeta = new CustomDictionary<string, string, FileUnit>(); int srcLength = curTask.Source.Length; int tgtLength = curTask.Target.Length; char[] delimiters = new char[] { ',' }; String createScenario = t.Param2; String[] createFiles = createScenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); CreateOldState(curTask, t, createFiles, srcMeta, srcLength, tgtMeta, tgtLength); Thread.Sleep(25); String scenario = t.Param3; String[] performChanges = scenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); SimulateChanges(curTask, performChanges); Detector tester; TestCompareFolders(curTask, t, srcMeta, tgtMeta, out tester); Reconciler reconciler = new Reconciler(tester.SourceList, tester.TargetList, curTask, ""); Console.WriteLine("Performing Sync..."); reconciler.Sync(); tester = null; tester = new Detector("", curTask); SyncMetaData.WriteMetaData(@".\srcmetatest", reconciler.UpdatedList); SyncMetaData.WriteMetaData(@".\tgtmetatest", reconciler.UpdatedList); tester.SMetaData = SyncMetaData.ReadMetaData(@".\srcmetatest"); tester.TMetaData = SyncMetaData.ReadMetaData(@".\tgtmetatest"); Console.WriteLine("Comparing Output..."); tester.CompareFolders(); tester.IsSynchronized(); t.Actual = tester.IsSynchronized() ? true.ToString() : false.ToString(); t.Passed = (t.Actual.Equals(t.Param4.Trim())) ? true : false; if (t.Passed) _totalPassed++; else _totalFailed++; Console.WriteLine(""); }