/// <summary> /// Gets the unique ID for the test case. /// </summary> private string GetUniqueID(ITestMethod testMethod) { if (testMethod is null) { throw new ArgumentNullException(nameof(testMethod)); } using (var stream = new MemoryStream()) { var assemblyName = testMethod.TestClass.TestCollection.TestAssembly.Assembly.Name; //Get just the assembly name (without version info) when obtained by reflection if (testMethod.TestClass.TestCollection.TestAssembly.Assembly is IReflectionAssemblyInfo assembly) { assemblyName = assembly.Assembly.GetName().Name; } Write(stream, assemblyName); Write(stream, testMethod.TestClass.Class.Name); Write(stream, TestNumber.ToString(CultureInfo.InvariantCulture)); stream.Position = 0; var hash = new byte[20]; var data = stream.ToArray(); var hasher = new Sha1Digest(); hasher.BlockUpdate(data, 0, data.Length); hasher.DoFinal(hash, 0); return(BytesToHexString(hash)); }
public bool addTest(Test test) { ConfigRoot = XElement.Load(ConfigPath); //ConfigRoot.Element("TestNumber").Value = (int.Parse(ConfigRoot.Element("TestNumber").Value) + 1).ToString(); //ConfigRoot.Save(ConfigPath); int TestNumber; // Load the most recently used TestNumber XElement numbElement = ConfigRoot.Element("TestNumber"); // Make sure the element exists /* * if (numbElement == null) * { * TestNumber = 0; * } * // Get the value from the element * else * { * string valString = numbElement.Value; * TestNumber = (valString == null) ? 0 : int.Parse(valString); * }*/ TestNumber = int.Parse(ConfigRoot.Element("TestNumber").Value) + 1; // Save it to make sure we don't go around the loop too many times int counter = TestNumber; // Find an available valid number while (GetTestByNumber(String.Format("{0:D8}", TestNumber)) != null) { // Increas the number TestNumber = TestNumber + 1; // Avoid Int over flow by restricting to 8 digits if (TestNumber > 99999999) { TestNumber = 0; } // Catch if we have gone around all the possible numbers and still have no answer if (TestNumber == counter) { throw new Exception("No avialable Test Number"); } } // Save the number to XML //ConfigRoot.Element("TestNumber").Value = int.Parse(ConfigRoot.Element("TestNumber").Value).ToString(); ConfigRoot.Element("TestNumber").Value = TestNumber.ToString(); ConfigRoot.Save(ConfigPath); // Add the number to the test and save test.TestNumber = String.Format("{0:D8}", TestNumber); TestsRoot.Add(ConvertTest(test)); TestsRoot.Save(TestsPath); return(true); }