public void TestSimpleCreateFromTemplate() { XElement templateRoot; XElement generatedRoot; XDocument referenceTree = XDocument.Load(TestDataHelper.Instance.PathToTestFile("forTestJdfCreator.xml")); templateRoot = referenceTree.Root; var nameValues = new Dictionary<string,object>(); nameValues.Add("IntegerSpan", "11"); nameValues.Add("Amount1","101.36"); var template = new Template(TestDataHelper.Instance.PathToTestFile("sampleJDFTemplate.xml")); var generated = template.Generate(nameValues, "fooey"); generatedRoot = generated.Root; AssertionHelper.IsTrue("Tree created from template is currently not null", generated != null); AssertionHelper.IsTrue("The value of 'JobID' attribute will be 'fooey'", generatedRoot.GetJobId() == "fooey"); AssertionHelper.IsTrue("The number of elements contained in both roots should be the same", templateRoot.Descendants().Count() == generatedRoot.Descendants().Count()); var templateResource = templateRoot.ResourcePoolElement().Elements().First(); var generatedResource = generatedRoot.ResourcePoolElement().Elements().First(); AssertionHelper.IsTrue("The number of ResourceLink that links to the first resource in the first Jdf Node should be the same", templateResource.ReferencingElements().Count() == generatedResource.ReferencingElements().Count()); AssertionHelper.IsTrue("The resource from the template should have different id than the generated resource", templateResource.GetId() != generatedResource.GetId()); templateResource = templateResource.ElementsAfterSelf().First(); generatedResource = generatedResource.ElementsAfterSelf().First(); AssertionHelper.IsTrue("The number of ResourceLink that links to the second resource in the first Jdf Node should be the same", templateResource.ReferencingElements().Count() == generatedResource.ReferencingElements().Count()); generatedResource = generatedRoot.FirstChild().FirstChild().NextSibling().NextSibling().NextSibling().NextSibling(); var amount = generatedResource.GetAttributeValueAsDoubleOrNull("Amount"); AssertionHelper.IsTrue("The value of 'amount' attribute should be 101.36", amount == 101.36); var generatedElement = generatedRoot.FirstChild().FirstChild().NextSibling().NextSibling().NextSibling().FirstChild().NextSibling(); var preferedValue = generatedElement.GetAttributeValueAsIntOrNull("Preferred"); AssertionHelper.IsTrue("The value of 'preferred' attribute should be 11", preferedValue == 11); AssertionHelper.IsTrue("The descriptive name of the first resource should start with an I because it was generated", generatedRoot.ResourcePoolElement().FirstChild().GetDescriptiveName().Substring(0, 1) == "I"); AssertionHelper.IsTrue("First child of audit pool has a non-null timestamp", generatedRoot.AuditPoolElement().FirstChild().GetAttributeValueOrNull("TimeStamp") != null); AssertionHelper.IsTrue("First child of audit pool has a timestamp that parses properly to a date time", generatedRoot.AuditPoolElement().FirstChild().GetTimeStamp() != null); AssertionHelper.IsTrue("The root node does not have a descriptive name because jdfDefault generated null", generatedRoot.GetDescriptiveName() == null); AssertionHelper.IsTrue("The value of Template in the root is false", generatedRoot.IsTemplate() == false); }
/// <summary> /// Generate the document. /// </summary> /// <returns></returns> public XDocument Generate() { Template template; if (templateStream != null) { template = new Template(templateStream, Globals.CreateUniqueId("Template_"), customFormulas); } else { template = new Template(templateFileName, customFormulas); } return template.Generate(nameValues, jobId, makeIdsUnique); }