From 5a7cc274e41708afcffb23f3d1bb317240f2b413 Mon Sep 17 00:00:00 2001 From: Lukzas Date: Sun, 1 Mar 2020 18:44:08 +0100 Subject: [PATCH 1/5] Added XML related namespace to CSharp resolver template --- NBi.Core/Scalar/Resolver/CSharpScalarResolver.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/NBi.Core/Scalar/Resolver/CSharpScalarResolver.cs b/NBi.Core/Scalar/Resolver/CSharpScalarResolver.cs index 77d1a74f5..18eca4dc3 100644 --- a/NBi.Core/Scalar/Resolver/CSharpScalarResolver.cs +++ b/NBi.Core/Scalar/Resolver/CSharpScalarResolver.cs @@ -6,6 +6,8 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; +using System.Xml.XPath; namespace NBi.Core.Scalar.Resolver { @@ -38,6 +40,10 @@ private MethodInfo CreateFunction(string code) { string codeTemplate = @" using System; + using System.Xml; + using System.Xml.Linq; + using System.Linq; + using System.Xml.XPath; namespace {1} {{ @@ -59,6 +65,14 @@ public static object Function() { GenerateInMemory = true, GenerateExecutable = false, + ReferencedAssemblies = + { + "System.Xml.dll", + "System.Xml.Linq.dll", + "System.Linq.dll", + "System.Core.dll", + "System.Xml.XPath.dll" + } }; var results = provider.CompileAssemblyFromSource(parameters, finalCode); From 8f5111ea9f2c3b47fa9f3b61f98470f42f4dea76 Mon Sep 17 00:00:00 2001 From: Lukzas Date: Sun, 1 Mar 2020 18:45:29 +0100 Subject: [PATCH 2/5] Added Xml related tests to CSharpScalarResolver suite --- NBi.Testing.Core/NBi.Testing.Core.csproj | 6 +- .../Resolver/CSharpScalarResolverTest.cs | 30 +++++ .../Resolver/Resources/PurchaseOrders.xml | 122 ++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 NBi.Testing.Core/Scalar/Resolver/Resources/PurchaseOrders.xml diff --git a/NBi.Testing.Core/NBi.Testing.Core.csproj b/NBi.Testing.Core/NBi.Testing.Core.csproj index 22cdf7cd7..9eaddd3c4 100644 --- a/NBi.Testing.Core/NBi.Testing.Core.csproj +++ b/NBi.Testing.Core/NBi.Testing.Core.csproj @@ -347,7 +347,11 @@ - + + + Always + + diff --git a/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs b/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs index df3b0ab8c..572c06d11 100644 --- a/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs +++ b/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; +using System.Xml.XPath; namespace NBi.Testing.Core.Scalar.Resolver { @@ -33,5 +35,33 @@ public void Instantiate_GetValueInt_CorrectComputation() Assert.That(output, Is.EqualTo(DateTime.Now.Year)); } + [Test] + public void Instantiate_GetValueXmlLinq_CorrectComputation() + { + var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Resources.PurchaseOrders.xml")).AbsolutePath; + string xmlDoc = string.Format(@"XDocument.Load(""{0}"").Root.Name.ToString()", xmlPath); + + var args = new CSharpScalarResolverArgs(xmlDoc); + var resolver = new CSharpScalarResolver(args); + + var output = resolver.Execute(); + + Assert.That(output, Is.EqualTo(XDocument.Load(xmlPath).Root.Name.ToString())); + } + + [Test] + public void Instantiate_GetValueXmlXpath_CorrectComputation() + { + var xPath = "./PurchaseOrders/PurchaseOrder/Address/Name"; + var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Resources.PurchaseOrders.xml")).AbsolutePath; + string xmlDoc = string.Format(@"XDocument.Load(""{0}"").XPathSelectElement(""{1}"").Value.ToString()", xmlPath, xPath); + + var args = new CSharpScalarResolverArgs(xmlDoc); + var resolver = new CSharpScalarResolver(args); + + var output = resolver.Execute(); + + Assert.That(output, Is.EqualTo(XDocument.Load(xmlPath).XPathSelectElement(xPath).Value.ToString())); + } } } diff --git a/NBi.Testing.Core/Scalar/Resolver/Resources/PurchaseOrders.xml b/NBi.Testing.Core/Scalar/Resolver/Resources/PurchaseOrders.xml new file mode 100644 index 000000000..2ea8b1bd4 --- /dev/null +++ b/NBi.Testing.Core/Scalar/Resolver/Resources/PurchaseOrders.xml @@ -0,0 +1,122 @@ + + + +
+ Ellen Adams + 123 Maple Street + Mill Valley + CA + 10999 + USA +
+
+ Tai Yee + 8 Oak Avenue + Old Town + PA + 95819 + USA +
+ Please leave packages in shed by driveway. + + + Lawnmower + 1 + 148.95 + Confirm this is electric + + + Baby Monitor + 2 + 39.98 + 1999-05-21 + + +
+ +
+ Cristian Osorio + 456 Main Street + Buffalo + NY + 98112 + USA +
+
+ Cristian Osorio + 456 Main Street + Buffalo + NY + 98112 + USA +
+ Please notify by email before shipping. + + + Power Supply + 1 + 45.99 + + +
+ +
+ Jessica Arnold + 4055 Madison Ave + Seattle + WA + 98112 + USA +
+
+ Jessica Arnold + 4055 Madison Ave + Buffalo + NY + 98112 + USA +
+ Please do not deliver on Saturday. + + + Computer Keyboard + 1 + 29.99 + + + Wireless Mouse + 1 + 14.99 + + +
+ + + Chris Preston + 123 Main St. + Seattle + WA + 98113 + USA + + + Chris Preston + 123 Main St. + Seattle + WA + 98113 + USA + + Ship only complete order. + + Litware Networking Card + 1 + 20.99 + + + Litware 17in LCD Monitor + 1 + 199.99 + + +
From 377f6ca45115054f1c35282209fbab107ff8ed4e Mon Sep 17 00:00:00 2001 From: Lukzas Date: Sun, 1 Mar 2020 18:46:18 +0100 Subject: [PATCH 3/5] Added acceptance XML variable test --- .../Resources/Positive/Variable.nbits | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits b/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits index ea3f5cff5..1a9e5a6c0 100644 --- a/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits +++ b/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits @@ -29,6 +29,9 @@ @prevcommon + + + @@ -142,4 +145,21 @@ + + + + + @xmlVar + select @var; + + + + + + + 10999 + + + + From 1dd6ec7f7dbd6e9cc36b032da8fb19c6ddaf3ad7 Mon Sep 17 00:00:00 2001 From: Lukasz Zasada Date: Sun, 1 Mar 2020 20:13:52 +0100 Subject: [PATCH 4/5] Fixed test xml file location --- NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs b/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs index 572c06d11..872ee8f10 100644 --- a/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs +++ b/NBi.Testing.Core/Scalar/Resolver/CSharpScalarResolverTest.cs @@ -38,7 +38,7 @@ public void Instantiate_GetValueInt_CorrectComputation() [Test] public void Instantiate_GetValueXmlLinq_CorrectComputation() { - var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Resources.PurchaseOrders.xml")).AbsolutePath; + var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Scalar.Resolver.Resources.PurchaseOrders.xml")).AbsolutePath; string xmlDoc = string.Format(@"XDocument.Load(""{0}"").Root.Name.ToString()", xmlPath); var args = new CSharpScalarResolverArgs(xmlDoc); @@ -53,7 +53,7 @@ public void Instantiate_GetValueXmlLinq_CorrectComputation() public void Instantiate_GetValueXmlXpath_CorrectComputation() { var xPath = "./PurchaseOrders/PurchaseOrder/Address/Name"; - var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Resources.PurchaseOrders.xml")).AbsolutePath; + var xmlPath = new Uri(FileOnDisk.CreatePhysicalFile("PurchaseOrders.xml", "NBi.Testing.Core.Scalar.Resolver.Resources.PurchaseOrders.xml")).AbsolutePath; string xmlDoc = string.Format(@"XDocument.Load(""{0}"").XPathSelectElement(""{1}"").Value.ToString()", xmlPath, xPath); var args = new CSharpScalarResolverArgs(xmlDoc); From 0fffdccef23ae0ab666559f50f932522c3153672 Mon Sep 17 00:00:00 2001 From: Lukzas Date: Sun, 1 Mar 2020 20:25:33 +0100 Subject: [PATCH 5/5] Fixed acceptance test xml file location --- NBi.Testing/Acceptance/Resources/Positive/Variable.nbits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits b/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits index 1a9e5a6c0..02c5f90af 100644 --- a/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits +++ b/NBi.Testing/Acceptance/Resources/Positive/Variable.nbits @@ -30,7 +30,7 @@ - +