/// <summary> /// Load and construct a recipe from a file. /// </summary> /// <param name="pathName">Path and name of the recipe file.</param> /// <returns>An object implementing the IRecipe interface.</returns> /// <remarks>If any of the assemblies cannot be found the recipe will /// still be loaded, but without the assembly that couldn't be found. /// If the recipe couldn't be found, the current recipe will stay /// open. /// For any file that couldn't be found a LoadFailed event is fired. /// </remarks> public static IRecipe Load(string pathName) { var doc = XmlDocumentFactory.CreateInstance(); if (doc.Exists(pathName)) { doc.Load(pathName); var retrieved = CreateInstance(pathName); var fileNotFounds = retrieved.LoadFromXml(doc); if (LoadFailed != null) { foreach (var ex in fileNotFounds) { LoadFailed(null, new RecipeEventArgs(ex.Message + " " + ex.FileName)); } } Current = retrieved; return(retrieved); } if (LoadFailed != null) { LoadFailed(null, new RecipeEventArgs("Couldn't load recipe '" + pathName + "'.")); } return(null); }
public void ConstructorTakingParameters() { XmlDocumentFactory.Type = typeof(HasConstructorWithParameter); IXmlDocument doc = XmlDocumentFactory.CreateInstance(); Assert.Null(doc); }
public void CreateCustomXmlDocument() { XmlDocumentFactory.Type = typeof(XmlDocumentMock); IXmlDocument doc = XmlDocumentFactory.CreateInstance(); Assert.Equals(typeof(XmlDocumentMock), doc.GetType()); }
public void StoresRelativePaths() { // ReSharper disable AssignNullToNotNullAttribute // ReSharper disable PossibleNullReferenceException XmlDocumentFactory.Type = typeof(XmlDocumentMock); LoaderFactory.Type = typeof(LoaderMock); var codeBase = GetType().Assembly.CodeBase; var url = new Uri(codeBase); var assemblyPathName = url.AbsolutePath; var fi = new FileInfo(assemblyPathName); var path = fi.DirectoryName; var src = RecipeFactory.NewRecipe(Path.Combine(path, "StoresRelativePaths.recipe")); src.Clear(); src.AddAssembly(assemblyPathName); src.Save(); var doc = XmlDocumentFactory.CreateInstance(); doc.Load(Path.Combine(path, "StoresRelativePaths.recipe")); var elem = doc["recipe"]["assembly"]; Assert.Equals("csUnit.Core.Tests.DLL", elem.Attributes["path"].Value); // ReSharper restore AssignNullToNotNullAttribute // ReSharper restore PossibleNullReferenceException }
public void InvalidContentThrowsOnLoad() { // The idea is that we don't want the parsing happen when we set the // content but at the same time as it would happen if we would read // from the file. XmlDocumentMock.RawContent = "bla"; // Must not throw! IXmlDocument doc = XmlDocumentFactory.CreateInstance(); doc.Load("whatever.xml"); }
/// <summary> /// Saves the recipe to a file. /// </summary> /// <param name="pathName">Path and name of the recipe file.</param> public void Save(string pathName) { if (!Path.IsPathRooted(pathName)) { throw new ArgumentException("Path must be rooted.", "pathName"); } var doc = XmlDocumentFactory.CreateInstance(); var recipeElem = doc.CreateElement("recipe"); doc.AppendChild(recipeElem); FileInfo fi; try { fi = new FileInfo(pathName); foreach (var testAssembly in Assemblies) { var assemblyElem = doc.CreateElement("assembly"); var attr = doc.CreateAttribute("path"); if (fi.Directory != null) { var url = new Uri(testAssembly.Name.CodeBase); attr.Value = Util.GetRelativeFilename(fi.Directory.FullName, url.AbsolutePath); } assemblyElem.Attributes.Append(attr); recipeElem.AppendChild(assemblyElem); } SaveFilters(recipeElem); doc.Save(pathName); _recipePathName = pathName; IsModified = false; if (Saved != null) { Saved(this, new RecipeEventArgs()); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void Hookup(IRecipe recipe) { _document = XmlDocumentFactory.CreateInstance(); WriteDocumentHeader(recipe.DisplayName); recipe.Started += _recipeStarted; recipe.Finished += _recipeFinished; recipe.Aborted += _recipeFinished; foreach (var ta in recipe.Assemblies) { ta.AssemblyStarted += _assemblyStarted; ta.AssemblyFinished += _assemblyFinished; ta.TestPassed += _testPassed; ta.TestFailed += _testFailed; ta.TestError += _testError; ta.TestSkipped += _testSkipped; } }
private void TryLoadFromXmlFile() { if (!string.IsNullOrEmpty(_xmlPathFileName)) { var dataRows = new List <DataRow>(); try { var document = XmlDocumentFactory.CreateInstance(); document.Load(_xmlPathFileName); var rowNodes = document.SelectNodes("dataTable/dataRow"); foreach (XmlNode rowNode in rowNodes) { var valueNodes = rowNode.SelectNodes("value"); if (valueNodes != null) { var values = new string[valueNodes.Count]; for (var i = 0; i < valueNodes.Count; i++) { values[i] = valueNodes[i].InnerText; } var exceptionNodes = rowNode.SelectNodes("expectedException"); if (exceptionNodes != null && exceptionNodes.Count > 0) { dataRows.Add(new DataRow(exceptionNodes[0].InnerText, values)); } else { dataRows.Add(new DataRow(values)); } } } } catch (XmlException ex) { Console.WriteLine(ex.ToString()); } _dataRows = dataRows.ToArray(); } }
public void CreateInstanceOfDefaultType() { IXmlDocument doc = XmlDocumentFactory.CreateInstance(); Assert.Equals(typeof(XmlDocumentFacade), doc.GetType()); }