Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        public void ConstructorTakingParameters()
        {
            XmlDocumentFactory.Type = typeof(HasConstructorWithParameter);
            IXmlDocument doc = XmlDocumentFactory.CreateInstance();

            Assert.Null(doc);
        }
Beispiel #3
0
        public void CreateCustomXmlDocument()
        {
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            IXmlDocument doc = XmlDocumentFactory.CreateInstance();

            Assert.Equals(typeof(XmlDocumentMock), doc.GetType());
        }
Beispiel #4
0
        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");
        }
Beispiel #6
0
        public void CreateTest()
        {
            var p = new paypal {
                landingPage  = "a",
                addrOverride = "b"
            };

            var xml = XmlDocumentFactory.Create(p);

            log.Info(xml.OuterXml);
        }
Beispiel #7
0
        public void ConvertTest()
        {
            var p = new paypal {
                landingPage  = "a",
                addrOverride = "b"
            };

            var xmlDoc = XmlDocumentFactory.Create(p);
            var xDoc   = XDocumentFactory.CreateDocFromXmlSerializer(p);

            log.Info(xmlDoc.ToXDocument().ToString());
            log.Info(xDoc.ToXmlDocument().OuterXml);
        }
Beispiel #8
0
        /// <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);
            }
        }
Beispiel #9
0
        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();
     }
 }
Beispiel #11
0
        public void CreateInstanceOfDefaultType()
        {
            IXmlDocument doc = XmlDocumentFactory.CreateInstance();

            Assert.Equals(typeof(XmlDocumentFacade), doc.GetType());
        }
Beispiel #12
0
        private static void Main(string[] args)
        {
            var xml = XmlDocumentFactory.Parse(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>
<verzeichnis x:a=""12"" xmlns:x=""http://www.w3.org/1999/xhtml"">
     <titel>Wikipedia Städteverzeichnis</titel>
     <eintrag>
          <stichwort>Genf</stichwort>
          <eintragstext>Genf ist der Sitz von ...</eintragstext>
     </eintrag>
     <eintrag>
          <stichwort>Köln</stichwort>
          <eintragstext>Köln ist eine Stadt, die ...</eintragstext>
     </eintrag>
</verzeichnis>");

            var xml2 = new XmlDocument();

            xml2.LoadXml(xml.ToString());

            foreach (var e in xml.Elements())
            {
                foreach (var a in e.Attributes())
                {
                }

                foreach (var n2 in e)
                {
                }
            }

            var r  = new CryptoRandom();
            var rv = r.Next(-1000, 1000);

            ObjectFactory of = ObjectFactory.Instance;

            var obj = of.CreateProxyForInterface <ITest>();

            dynamic dynObj = obj;

            dynObj.IchBinEinKunterbuntesProperty  = true;
            dynObj.IchBinEinKunterbuntesProperty2 = "TM";

            if (obj != null)
            {
            }

            var workflow = DelegateWorkflow.Create(Station_A1);

            var t2 = new Test2();

            var t3 = new Test3();

            t3.A = 5979;
            t3.A = 5979;
            t3.A = 23979;

            var workflow2 = AttributeWorkflow.Create(t2);

            var aggWF = new AggregateWorkflow();

            aggWF.Add(workflow);
            aggWF.Add(workflow2);

            aggWF.Execute();
        }