示例#1
0
        public void Adhoc_PerformanceTest_Harness()
        {
            var ruleAppDef = RuleApplicationDef.Load("InvoiceForKpis.ruleappx");

            var entityState = new string[100];

            for (var i = 1; i < 101; i++)
            {
                entityState[i - 1] = File.ReadAllText($"InvoiceJsonFiles\\Invoice{i}.json");
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (var i = 1; i < 101; i++)
            {
                using (var session = new RuleSession(ruleAppDef))
                {
                    session.Settings.MetricLogger      = new MetricLogger(DatabaseConnectionString);
                    session.Settings.MetricServiceName = "Integration Tests";

                    var invoice = session.CreateEntity("Invoice");
                    invoice.ParseJson(entityState[i - 1]);

                    session.ApplyRules();
                }
            }

            stopWatch.Stop();
            Console.WriteLine("Execution Time:" + stopWatch.ElapsedMilliseconds);
        }
示例#2
0
        public void DuplicateEntityNameTest()
        {
            Helper             h       = new Helper();
            RuleApplicationDef source  = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest    = RuleApplicationDef.Load(_destPath);
            EntityDef          entity  = new EntityDef();
            EntityDef          entity2 = new EntityDef();

            entity.Name  = "HelloWorld";
            entity2.Name = "HelloWorld";
            source.Entities.Add(entity);
            dest.Entities.Add(entity2);


            try
            {
                h.ImportToolkit(source, dest);
                Assert.Fail("Expected InvalidImportException.");
            }
            catch (Exception ex)
            {
                if (ex.GetType().ToString().Contains("InvalidImportException"))
                {
                    Assert.Pass("Got the expected exception");
                }
                else
                {
                    Assert.Fail("Did not get the expected exception.  Instead got: " + ex.GetType().ToString());
                }
            }
        }
示例#3
0
        public void ToolkitIntegrationTests()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            Assert.IsTrue(source.Entities.Count == dest.Entities.Count);
            Assert.IsTrue(source.EndPoints.Count == dest.EndPoints.Count);
            Assert.IsTrue(source.UdfLibraries.Count == dest.UdfLibraries.Count);
            Assert.IsTrue(source.Categories.Count == dest.Categories.Count);
            Assert.IsTrue(source.DataElements.Count == dest.DataElements.Count);
            Assert.IsTrue(source.RuleSets.Count == dest.RuleSets.Count);
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Ruleapps\\dest_" + Guid.NewGuid() + ".ruleappx";

            dest.SaveToFile(path);

            h.RemoveToolkit(source, dest);
            Assert.IsTrue(dest.Entities.Count == 0);           //all imported entities are gone
            Assert.IsTrue(dest.RuleSets.Count == 0);           //all imported RuleSets are gone
            Assert.IsTrue(dest.EndPoints.Count == 0);          //all endpoints are gone
            Assert.IsTrue(dest.Categories.Count == 0);         //all categories are gone
            Assert.IsTrue(dest.DataElements.Count == 0);       //all data elements are gone
            Assert.IsTrue(dest.UdfLibraries.Count == 0);       //All udfs are gone
            Assert.IsTrue(dest.Attributes.Default.Count == 0); //the base 64 encoded source ruleapp is removed
        }
示例#4
0
        public void TestDeepFindDef()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            RuleRepositoryDefBase found = h.FindDefDeep(dest, "ece7c19a-f8c1-4212-9cc2-90f6dcf837cf");

            Assert.NotNull(found);
        }
示例#5
0
        public void IsToolkitMatchTest()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            EntityDef          ent    = new EntityDef();
            string             key    = h.MakeKey(source);

            h.StampAttribute(ent, key);
            Assert.IsTrue(h.IsToolkitMatch(ent, key));              //the purpose is to test the helper method look for a stamped attribute
            Assert.IsFalse(h.IsToolkitMatch(new EntityDef(), key)); //no stamp should be false
        }
示例#6
0
        public void TestCountSummary()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            ObservableCollection <ArtifactCount> result = new ObservableCollection <ArtifactCount>();

            h.CountArtifactsByType(source, result);
            foreach (ArtifactCount item in result)
            {
                Console.WriteLine(item.ArtifcatType + " - " + item.Count);
            }
        }
示例#7
0
 public void RemoveToolkit(string sourceRuleappPath, string destinationRuleappPath)
 {
     try
     {
         RemoveToolkit(RuleApplicationDef.Load(sourceRuleappPath),
                       RuleApplicationDef.Load(destinationRuleappPath), destinationRuleappPath);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message + ex.StackTrace + ex.InnerException);
     }
 }
示例#8
0
 public void ImportRuleApp(string sourceRuleappPath, string destRuleappPath)
 {
     try
     {
         ImportRuleApp(RuleApplicationDef.Load(sourceRuleappPath),
                       RuleApplicationDef.Load(destRuleappPath), destRuleappPath);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message + ex.StackTrace + ex.InnerException);
     }
 }
示例#9
0
        public void GetToolkitsTest()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            ObservableCollection <ToolkitContents> toolkits = h.GetToolkits(dest);

            Console.WriteLine("Toolkits Count: " + toolkits[0].Contents.Count);
            Assert.NotNull(toolkits);
            Assert.AreEqual(toolkits[0].Name, source.Name);
            Assert.AreEqual(toolkits[0].Revision, source.Revision.ToString());
            Assert.AreEqual(toolkits[0].GUID, source.Guid.ToString());
        }
示例#10
0
        /// <summary>
        /// Extracts a specific toolkit from a Rule Application.
        /// </summary>
        public RuleApplicationDef  GetSourceRuleapp(string key, RuleApplicationDef dest)
        {
            RuleApplicationDef def = null;

            //Get from attribute
            XmlSerializableStringDictionary.XmlSerializableStringDictionaryItem att = FindSourceAttribute(key, dest);
            if (att != null)
            {
                string file    = att.Value;
                string tmpPath = GetTmpPath();
                DecodeFile(file, tmpPath);
                def = RuleApplicationDef.Load(tmpPath);
            }
            return(def);
        }
示例#11
0
        private RuleApplicationDef GetInvoiceRuleAppDef()
        {
            // lookup the rule appfile name as a relative path
            string   exPath          = AppDomain.CurrentDomain.BaseDirectory;
            string   ruleAppFileName = "ObjectAsStateInvoice.ruleappx";
            FileInfo outputFile      = new FileInfo(System.IO.Path.Combine(exPath, ruleAppFileName));

            if (outputFile.Exists == false)
            {
                throw new ApplicationException(string.Format("Rule app '{0}' was not found", outputFile.FullName));
            }

            RuleApplicationDef ruleApp = RuleApplicationDef.Load(outputFile.FullName);

            return(ruleApp);
        }
示例#12
0
        public void ImportRuleAppIntegrationTests()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportRuleApp(source, dest);
            Assert.IsTrue(source.Entities.Count == dest.Entities.Count);
            Assert.IsTrue(source.EndPoints.Count == dest.EndPoints.Count);
            Assert.IsTrue(source.UdfLibraries.Count == dest.UdfLibraries.Count);
            Assert.IsTrue(source.Categories.Count == dest.Categories.Count);
            Assert.IsTrue(source.DataElements.Count == dest.DataElements.Count);
            Assert.IsTrue(source.RuleSets.Count == dest.RuleSets.Count);
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Ruleapps\\dest_import_only_" + Guid.NewGuid() + ".ruleappx";

            dest.SaveToFile(path);
        }
示例#13
0
        public void DuplicateToolkitTest()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            try
            {
                h.ImportToolkit(source, dest);
                Assert.Fail("Expected an exception from adding a duplicate");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType().FullName.Contains("DuplicateToolkitException"));
                Assert.Pass("Threw an expected exception");
            }
        }
示例#14
0
        public MainWindow()
        {
            InitializeComponent();

            // Load rule application from file system
            var ruleAppDef = RuleApplicationDef.Load("InvoiceLineItem.ruleappx");

            // Create control factory
            var controlFactory = new ControlFactory();

            // Open the rule applicationo
            controlFactory.OpenRuleApplication(ruleAppDef);

            // Find the def for the control we want to show
            var ruleDef = controlFactory.RuleApplicationDef.AsEnumerable().Where(def => def.Name == "LanguageRule1").First();

            // Get the control and populate the content control
            contentControl.Content = controlFactory.GetControl(ruleDef);
        }
示例#15
0
        public void TestGetDef()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);
            EntityDef          entity = new EntityDef();

            entity.Name = "HelloWorld";
            source.Entities.Add(entity);
            h.ImportToolkit(source, dest);
            ToolkitsContainer tc = new ToolkitsContainer();

            tc.Toolkits = h.GetToolkits(dest);
            RuleRepositoryDefBase def = tc.GetDef(entity.Guid);

            Assert.IsNotNull(def);
            def = tc.GetDef(Guid.NewGuid());
            Assert.IsNull(def); //should return null becuase it's not there
        }
示例#16
0
        public void MakeStampTest()
        {
            Helper h = new Helper();

            Console.WriteLine(_sourcePath);
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);

            Assert.NotNull(source);
            Console.WriteLine(source.Name);
            Console.WriteLine(source.Guid);
            Console.WriteLine(source.Revision);
            Console.WriteLine(h.MakeKey(source));
            Assert.AreEqual("SourceRuleApplication,1,9dd52e90-cdbb-4d1b-81f2-9956608c8793", h.MakeKey(source));
            //Test the method that sets the member variable fo the stamp
            //h._source = def;
            //h.MakeStamp();
            string key = h.MakeKey(source);

            Assert.AreEqual("SourceRuleApplication,1,9dd52e90-cdbb-4d1b-81f2-9956608c8793", key);
        }
示例#17
0
 public void CountArtifactsByTypeBatch(string path, ObservableCollection <ArtifactCount> summary)
 {
     string[] files =
         Directory.GetFiles(path, "*.ruleapp*", SearchOption.AllDirectories);
     foreach (string file in files)
     {
         RuleApplicationDef source = null;
         try
         {
             source = RuleApplicationDef.Load(file);
         }
         ///todo: don't bury this exception and add a logger
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
         if (source != null)
         {
             CountArtifactsByType(source, summary);
         }
     }
 }
示例#18
0
        public void TestImportDefByCategory()
        {
            Helper h          = new Helper();
            string sourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
                                                                                             AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_SourceRuleApplication_Import_By_Category.ruleappx");

            string destPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
                                                                                           AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_DestRuleApplication_Import_By_Category.ruleappx");

            RuleApplicationDef source = RuleApplicationDef.Load(sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(destPath);

            h.ImportRuleApp(source, dest, "Category1");
            RuleRepositoryDefBase retval = h.FindDefDeep(dest, "FireNotification1");

            Assert.NotNull(retval);

            RuleApplicationValidationErrorCollection err = dest.Validate();
            string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", Guid.NewGuid() + "TempRuleApplication.ruleappx");

            dest.SaveToFile(tempPath);
        }
示例#19
0
        private void OpenClick(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.CheckPathExists = false;
            dialog.CheckFileExists = false;
            dialog.Filter          = "Rule Apps|*.ruleapp";
            dialog.ShowDialog();

            if (!String.IsNullOrEmpty(dialog.FileName))
            {
                Cursor.Current = Cursors.WaitCursor;

                Reset();

                _ruleAppDef     = RuleApplicationDef.Load(dialog.FileName);
                _controlFactory = new ControlFactory(_ruleAppDef);

                LoadDefs();

                Cursor.Current = Cursors.Default;
            }
        }
 public static RuleApplicationDef GetRuleApplicationDef(string filePath)
 {
     return(RuleApplicationDef.Load(filePath));
 }
 public static RuleApplicationDef GetRuleApplicationDefFromFile(RuleExecutionInfo ruleExecutionInfo)
 {
     return(RuleApplicationDef.Load(ruleExecutionInfo.RuleAppFilePath));
 }