public void ExecutePolicy(string filename) { var ruleStore = new FileRuleStore(filename); var ruleSetInfo = GetRuleSetInfo(filename); var ruleSet = ruleStore.GetRuleSet(ruleSetInfo); ExecutePolicy(ruleSet); }
public RuleSet LoadRuleFromFile(string filename, string rulesetName) { RuleStore store = new FileRuleStore(filename); RuleSetInfoCollection ruleSets = store.GetRuleSets(rulesetName, RuleStore.Filter.Latest); if (ruleSets.Count != 1) { throw new ApplicationException(string.Format("EXCEPTION: No Ruleset named {0} exists in rule store {1}", rulesetName, filename)); } return(store.GetRuleSet(ruleSets[0])); }
/// <summary> /// ITestStep.Execute() implementation /// </summary> /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public void Execute(System.Xml.XmlNode testConfig, Context context) { // Using Policy Tester // Retrieve Rule-Set from Policy file string RuleStoreName = context.ReadConfigAsString(testConfig, "RuleStoreName"); string RuleSetInfoCollectionName = context.ReadConfigAsString(testConfig, "RuleSetInfoCollectionName"); string DebugTracking = context.ReadConfigAsString(testConfig, "DebugTracking"); string SampleXML = context.ReadConfigAsString(testConfig, "SampleXML"); string XSD = context.ReadConfigAsString(testConfig, "XSD"); string ResultFile = context.ReadConfigAsString(testConfig, "ResultFile"); RuleStore ruleStore = new FileRuleStore(RuleStoreName); RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(); } RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor DebugTrackingInterceptor dti = new DebugTrackingInterceptor(DebugTracking); // Create an instance of the Policy Tester class PolicyTester policyTester = new PolicyTester(ruleset); XmlDocument xd1 = new XmlDocument(); xd1.Load(SampleXML); TypedXmlDocument doc1 = new TypedXmlDocument(XSD, xd1); // Execute Policy Tester try { policyTester.Execute(doc1, dti); } catch (Exception e) { context.LogException(e); throw; } FileInfo f = new FileInfo(ResultFile); StreamWriter w = f.CreateText(); w.Write(doc1.Document.OuterXml); w.Close(); }
public void ExecutePolicy() { // Retrieve Rule-Set from the filestore RuleStore ruleStore = new FileRuleStore("MedicalInsurancePolicy.xml"); //Grab the latest version of the rule-set RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets("MedicalInsurancePolicy", RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(); } RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor to provide an output trace DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtrace.txt"); //Create an instance of the Policy Tester class PolicyTester policyTester = new PolicyTester(ruleset); //Create the set of short term facts //XML facts XmlDocument xd1 = new XmlDocument(); xd1.Load(@"..\..\sampleClaim.xml"); TypedXmlDocument doc1 = new TypedXmlDocument("MedicalClaims", xd1); // .NET facts Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults results = new Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults(); object[] shortTermFacts = new object[] { doc1, results, new TimeStamp(DateTime.Now) }; //Execute Policy Tester try { policyTester.Execute(shortTermFacts, dti); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } System.Console.WriteLine("Status: " + results.Status); System.Console.WriteLine("Reason: " + results.Reason); }
static RuleSet LoadFromFile(string filename, string rulesetName) { // load the ruleset from a file RuleStore ruleStore = new FileRuleStore(filename); RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets(rulesetName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(); } RuleSet newRS = ruleStore.GetRuleSet(rsInfo[0]); return(newRS); }
} // End of Cleanup() public void Execute() { //Using Policy Tester // Retrieve Rule-Set from Policy file RuleStore ruleStore = new FileRuleStore("LoanProcessing.xml"); RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets("LoanProcessing", RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(); } RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtraceforLoanPocessing.txt"); //Create an instance of the Policy Tester class PolicyTester policyTester = new PolicyTester(ruleset); XmlDocument xd1 = new XmlDocument(); xd1.Load("sampleLoan.xml"); TypedXmlDocument doc1 = new TypedXmlDocument("Microsoft.Samples.BizTalk.LoansProcessor.Case", xd1); //Execute Policy Tester try { policyTester.Execute(doc1, dti); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } FileInfo f = new FileInfo("LoanPocessingResults.xml"); StreamWriter w = f.CreateText(); w.Write(doc1.Document.OuterXml); w.Close(); }
/// <summary> /// TestStepBase.Execute() implementation /// </summary> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public override void Execute(Context context) { var fi = new System.IO.FileInfo(RuleStoreName); if (!fi.Exists) { throw new FileNotFoundException("RuleStoreName", RuleStoreName); } var ruleStore = new FileRuleStore(fi.FullName); var rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(String.Format("RuleStore {0} did not contain RuleSet {1}", RuleStoreName, RuleSetInfoCollectionName)); } var ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor var dti = new DebugTrackingInterceptor(DebugTracking); // Create an instance of the Policy Tester class var policyTester = new PolicyTester(ruleset); // load the facts into array var facts = new object[_factsList.Count]; var i = 0; foreach (var currentFact in _factsList) { switch (currentFact.GetFactType) { case "ObjectFact": { var fact = currentFact as ObjectFact; object[] objectArgs = null; if (null != fact.Args) { objectArgs = fact.Args.Split(new char[] { ',' }); } System.Reflection.Assembly asm; Type type; if (fact.AssemblyPath.Length > 0) { asm = System.Reflection.Assembly.LoadWithPartialName(fact.AssemblyPath); if (asm == null) { // fail throw (new Exception("failed to create type " + fact.Type)); } type = asm.GetType(fact.Type, true, false); } else { // must be in path type = Type.GetType(fact.Type); } facts[i] = Activator.CreateInstance(type, objectArgs); break; } case "DocumentFact": { var fact = currentFact as DocumentFact; var xd1 = new XmlDocument(); xd1.Load(fact.InstanceDocument); var txd = new TypedXmlDocument(fact.SchemaType, xd1); facts[i] = txd; break; } case "DataConnectionFact": { var fact = currentFact as DataConnectionFact; var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var dc = new DataConnection(fact.Dataset, fact.TableName, conn); facts[i] = dc; break; } case "dataTable": case "dataRow": { var fact = currentFact as DataTableFact; var dAdapt = new SqlDataAdapter(); dAdapt.TableMappings.Add("Table", fact.TableName); var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var myCommand = new SqlCommand(fact.Command, conn) {CommandType = CommandType.Text}; dAdapt.SelectCommand = myCommand; var ds = new DataSet(fact.Dataset); dAdapt.Fill(ds); var tdt = new TypedDataTable(ds.Tables[fact.TableName]); if (fact.Type == "dataRow") { var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt); facts[i] = tdr; } else { facts[i] = tdt; } break; } } i++; } // Execute Policy Tester try { policyTester.Execute(facts, dti); } catch (Exception e) { context.LogException(e); throw; } finally { dti.CloseTraceFile(); } // write out all document instances passed in foreach (object fact in facts) { switch (fact.GetType().Name) { case "TypedXmlDocument": { var txd = (TypedXmlDocument)fact; context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml); Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml); // Validate if configured... // HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS") { foreach (var subStep in SubSteps) { data = subStep.Execute(data, context); } } break; } case "DataConnection": { var dc = (DataConnection)fact; dc.Update(); // persist any changes break; } case "TypedDataTable": { var tdt = (TypedDataTable)fact; tdt.DataTable.AcceptChanges(); break; } case "TypedDataRow": { var tdr = (TypedDataRow)fact; tdr.DataRow.AcceptChanges(); break; } } } }
/// <summary> /// TestStepBase.Execute() implementation /// </summary> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public override void Execute(Context context) { var fi = new FileInfo(RuleStoreName); if (!fi.Exists) { throw new FileNotFoundException("RuleStoreName", RuleStoreName); } var ruleStore = new FileRuleStore(fi.FullName); var rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new InvalidOperationException(string.Format("RuleStore {0} did not contain RuleSet {1}", RuleStoreName, RuleSetInfoCollectionName)); } var ruleset = ruleStore.GetRuleSet(rsInfo[0]); // load the facts into array var facts = new List <object>(FactsList.Count); // Create an instance of the Policy Tester class using (var policyTester = new PolicyTester(ruleset)) { foreach (var currentFact in FactsList) { switch (currentFact.GetType().ToString()) { case "ObjectFact": { var fact = currentFact as ObjectFact; object[] objectArgs = null; if (null != fact.Args) { objectArgs = fact.Args.Split(',').Cast <object>().ToArray(); } Type type; if (fact.AssemblyPath.Length > 0) { var asm = Assembly.Load(fact.AssemblyPath); if (asm == null) { // fail throw (new InvalidOperationException("failed to create type " + fact.Type)); } type = asm.GetType(fact.Type, true, false); } else { // must be in path type = Type.GetType(fact.Type); } facts.Add(Activator.CreateInstance(type, objectArgs)); break; } case "DocumentFact": { var fact = currentFact as DocumentFact; var xd1 = new XmlDocument(); xd1.Load(fact.InstanceDocument); var txd = new TypedXmlDocument(fact.SchemaType, xd1); facts.Add(txd); break; } case "DataConnectionFact": { var fact = currentFact as DataConnectionFact; var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var dc = new DataConnection(fact.Dataset, fact.TableName, conn); facts.Add(dc); break; } case "dataTable": case "dataRow": { var fact = currentFact as DataTableFact; var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var myCommand = new SqlCommand(fact.Command, conn) { CommandType = CommandType.Text }; var dAdapt = new SqlDataAdapter(); dAdapt.TableMappings.Add("Table", fact.TableName); dAdapt.SelectCommand = myCommand; var ds = new DataSet(fact.Dataset); dAdapt.Fill(ds); var tdt = new TypedDataTable(ds.Tables[fact.TableName]); if (fact.Type == "dataRow") { var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt); facts.Add(tdr); } else { facts.Add(tdt); } break; } } } // Create an instance of the DebugTrackingInterceptor using (var dti = new DebugTrackingInterceptor(DebugTracking)) { // Execute Policy Tester try { policyTester.Execute(facts.ToArray(), dti); } catch (Exception e) { context.LogException(e); throw; } } } // write out all document instances passed in foreach (var fact in facts) { switch (fact.GetType().Name) { case "TypedXmlDocument": { var txd = (TypedXmlDocument)fact; context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml); using (var data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml)) { if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS") { SubSteps.Aggregate(data, (current, subStep) => subStep.Execute(current, context)); } } break; } case "DataConnection": { var dc = (DataConnection)fact; dc.Update(); // persist any changes break; } case "TypedDataTable": { var tdt = (TypedDataTable)fact; tdt.DataTable.AcceptChanges(); break; } case "TypedDataRow": { var tdr = (TypedDataRow)fact; tdr.DataRow.AcceptChanges(); break; } } } }
/// <summary> /// TestStepBase.Execute() implementation /// </summary> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public override void Execute(Context context) { var fi = new System.IO.FileInfo(RuleStoreName); if (!fi.Exists) { throw new FileNotFoundException("RuleStoreName", RuleStoreName); } var ruleStore = new FileRuleStore(fi.FullName); var rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(String.Format("RuleStore {0} did not contain RuleSet {1}", RuleStoreName, RuleSetInfoCollectionName)); } var ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor var dti = new DebugTrackingInterceptor(DebugTracking); // Create an instance of the Policy Tester class var policyTester = new PolicyTester(ruleset); // load the facts into array var facts = new object[_factsList.Count]; var i = 0; foreach (var currentFact in _factsList) { switch (currentFact.GetType().ToString()) { case "ObjectFact": { var fact = currentFact as ObjectFact; object[] objectArgs = null; if (null != fact.Args) { objectArgs = fact.Args.Split(new char[] { ',' }); } System.Reflection.Assembly asm; Type type; if (fact.AssemblyPath.Length > 0) { asm = System.Reflection.Assembly.LoadWithPartialName(fact.AssemblyPath); if (asm == null) { // fail throw (new Exception("failed to create type " + fact.Type)); } type = asm.GetType(fact.Type, true, false); } else { // must be in path type = Type.GetType(fact.Type); } facts[i] = Activator.CreateInstance(type, objectArgs); break; } case "DocumentFact": { var fact = currentFact as DocumentFact; var xd1 = new XmlDocument(); xd1.Load(fact.InstanceDocument); var txd = new TypedXmlDocument(fact.SchemaType, xd1); facts[i] = txd; break; } case "DataConnectionFact": { var fact = currentFact as DataConnectionFact; var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var dc = new DataConnection(fact.Dataset, fact.TableName, conn); facts[i] = dc; break; } case "dataTable": case "dataRow": { var fact = currentFact as DataTableFact; var dAdapt = new SqlDataAdapter(); dAdapt.TableMappings.Add("Table", fact.TableName); var conn = new SqlConnection(fact.ConnectionString); conn.Open(); var myCommand = new SqlCommand(fact.Command, conn) { CommandType = CommandType.Text }; dAdapt.SelectCommand = myCommand; var ds = new DataSet(fact.Dataset); dAdapt.Fill(ds); var tdt = new TypedDataTable(ds.Tables[fact.TableName]); if (fact.Type == "dataRow") { var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt); facts[i] = tdr; } else { facts[i] = tdt; } break; } } i++; } // Execute Policy Tester try { policyTester.Execute(facts, dti); } catch (Exception e) { context.LogException(e); throw; } finally { dti.CloseTraceFile(); } // write out all document instances passed in foreach (object fact in facts) { switch (fact.GetType().Name) { case "TypedXmlDocument": { var txd = (TypedXmlDocument)fact; context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml); Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml); // Validate if configured... // HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS") { foreach (var subStep in SubSteps) { data = subStep.Execute(data, context); } } break; } case "DataConnection": { var dc = (DataConnection)fact; dc.Update(); // persist any changes break; } case "TypedDataTable": { var tdt = (TypedDataTable)fact; tdt.DataTable.AcceptChanges(); break; } case "TypedDataRow": { var tdr = (TypedDataRow)fact; tdr.DataRow.AcceptChanges(); break; } } } }
/// <summary> /// ITestStep.Execute() implementation /// </summary> /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param> /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param> public void Execute(System.Xml.XmlNode testConfig , Context context) { // Using Policy Tester // Retrieve Rule-Set from Policy file string RuleStoreName = context.ReadConfigAsString(testConfig, "RuleStoreName"); string RuleSetInfoCollectionName =context.ReadConfigAsString(testConfig, "RuleSetInfoCollectionName"); string DebugTracking = context.ReadConfigAsString(testConfig, "DebugTracking"); string SampleXML = context.ReadConfigAsString(testConfig, "SampleXML"); string XSD = context.ReadConfigAsString(testConfig, "XSD"); string ResultFile = context.ReadConfigAsString(testConfig, "ResultFile"); RuleStore ruleStore = new FileRuleStore(RuleStoreName); RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest); if (rsInfo.Count != 1) { // oops ... error throw new ApplicationException(); } RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]); // Create an instance of the DebugTrackingInterceptor DebugTrackingInterceptor dti = new DebugTrackingInterceptor(DebugTracking); // Create an instance of the Policy Tester class PolicyTester policyTester = new PolicyTester(ruleset); XmlDocument xd1 = new XmlDocument(); xd1.Load(SampleXML); TypedXmlDocument doc1 = new TypedXmlDocument(XSD, xd1); // Execute Policy Tester try { policyTester.Execute(doc1, dti); } catch (Exception e) { context.LogException(e); throw; } FileInfo f = new FileInfo(ResultFile); StreamWriter w = f.CreateText(); w.Write(doc1.Document.OuterXml); w.Close(); }