コード例 #1
0
        public void ProjectMgaOpen()
        {
            var mgaReference = "MGA=" + mgaFile;

            MgaProject project = new MgaProject();

            project.OpenEx(mgaReference, "CyPhyML", null);
            MgaHelper.CheckParadigmVersionUpgrade(project);
            project.Close(true);
            Assert.True(File.Exists(mgaReference.Substring("MGA=".Length)));
        }
コード例 #2
0
        //[Fact]
        public void TestCodeSample()
        {
            string ProjectConnStr;

            MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);

            MgaProject project = new MgaProject();
            bool       ro_mode;

            project.Open(ProjectConnStr, out ro_mode);

            MgaHelper.CheckParadigmVersionUpgrade(project);

            try
            {
                List <IMgaFCO> objectsToCheck = null;

                project.BeginTransactionInNewTerr();
                try
                {
                    // discover objects

                    var allObjects = project
                                     .RootFolder
                                     .ChildFolders
                                     .Cast <MgaFolder>()
                                     .Where(x => x.Name.StartsWith("0"))
                                     .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>())
                                     .Where(x => x.RootFCO == x);

                    // get all objects from folders starts with 0 within the root folder.
                    objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("ProcessorTypesForContexts")).ToList();

                    objectsToCheck.Sort((x, y) =>
                    {
                        return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
                               x.Meta.Name.CompareTo(y.Meta.Name) :
                               x.AbsPath.CompareTo(y.AbsPath));
                    });
                }
                finally
                {
                    project.AbortTransaction();
                }

                Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked.");

                int numContexts = objectsToCheck.Count;
                int numSuccess  = 0;
                int numFailures = 0;

                bool success = true;

                foreach (var subject in objectsToCheck)
                {
                    // single test
                    CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null;

                    project.BeginTransactionInNewTerr();
                    try
                    {
                        Assert.ThrowsDelegate d = () =>
                        {
                            analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(subject as MgaModel);
                        };

                        MgaObject parent = null;
                        GME.MGA.Meta.objtype_enum type;
                        subject.GetParent(out parent, out type);

                        var contextSupportExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true;
                        if (contextSupportExpected)
                        {
                            Assert.DoesNotThrow(d);
                            Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", subject.Name, subject.Meta.Name));

                            if (subject.Name.Contains(analysisModelProcessor.GetType().Name))
                            {
                                numSuccess++;
                                Console.Out.WriteLine("[Passed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name);
                            }
                            else
                            {
                                success = false;
                                numFailures++;
                                Console.Out.WriteLine("[Failed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name);
                            }
                        }
                        else
                        {
                            Assert.Throws <CyPhyMasterInterpreter.AnalysisModelContextNotSupportedException>(d);
                            numSuccess++;
                            Console.Out.WriteLine("[Passed] Context not supported {0} [{1}]", subject.Name, subject.Meta.Name);
                        }
                    }
                    finally
                    {
                        project.AbortTransaction();
                    }
                }

                if (success)
                {
                    Console.Out.WriteLine("[OK] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
                }
                else
                {
                    Console.Error.WriteLine("[FAILED] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
                }

                Assert.True(success, "At least one analysis model processor was not instantiated as expected.");
            }
            finally
            {
                project.Close(true);
            }
        }
コード例 #3
0
ファイル: ContextChecker.cs プロジェクト: landunin/meta-core
        //[Fact]
        public void TestCodeSample()
        {
            string ProjectConnStr;

            MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);

            MgaProject project = new MgaProject();
            bool       ro_mode;

            project.Open(ProjectConnStr, out ro_mode);

            MgaHelper.CheckParadigmVersionUpgrade(project);

            try
            {
                List <IMgaFCO> objectsToCheck = null;

                project.BeginTransactionInNewTerr();
                try
                {
                    // discover objects

                    var allObjects = project
                                     .RootFolder
                                     .ChildFolders
                                     .Cast <MgaFolder>()
                                     .Where(x => x.Name.StartsWith("0"))
                                     .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>())
                                     .Where(x => x.RootFCO == x);

                    // get all objects from folders starts with 0 within the root folder.
                    objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker") && x.Name.Contains("ReadOnly") == false).ToList();

                    objectsToCheck.Sort((x, y) =>
                    {
                        return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
                               x.Meta.Name.CompareTo(y.Meta.Name) :
                               x.AbsPath.CompareTo(y.AbsPath));
                    });
                }
                finally
                {
                    project.AbortTransaction();
                }

                Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked.");

                int numContexts = objectsToCheck.Count;
                int numSuccess  = 0;
                int numFailures = 0;

                bool success = true;

                foreach (var subject in objectsToCheck)
                {
                    // single test
                    using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
                    {
                        CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null;

                        // check context
                        var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults);

                        List <CyPhyMasterInterpreter.Rules.ContextCheckerResult> sortedResults = contextCheckerResults.ToList();

                        // sort results Passed, Failed, then alphabetically based on message.
                        sortedResults.Sort((x, y) => { return(x.Success == y.Success ? x.Message.CompareTo(y.Message) : y.Success.CompareTo(x.Success)); });

                        project.BeginTransactionInNewTerr();
                        try
                        {
                            MgaObject parent = null;
                            GME.MGA.Meta.objtype_enum type;
                            subject.GetParent(out parent, out type);

                            var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true;

                            if (successExpected == checkerSuccess)
                            {
                                numSuccess++;
                                //GMEConsole.Info.WriteLine("OK");
                            }
                            else
                            {
                                success = false;

                                foreach (var result in sortedResults)
                                {
                                    TextWriter    tw = null;
                                    StringBuilder sb = new StringBuilder();
                                    if (result.Success)
                                    {
                                        sb.Append("[Passed]");
                                        tw = Console.Out;
                                    }
                                    else
                                    {
                                        sb.Append("[Failed]");
                                        tw = Console.Error;
                                    }

                                    sb.AppendFormat(" {0} - {1} ", result.Subject.Name, result.Subject.AbsPath);

                                    sb.Append(result.Message);

                                    tw.WriteLine(sb);
                                }

                                numFailures++;
                                Console.Error.WriteLine("========= FAILED ==========");
                                Console.Error.WriteLine("= {0}", subject.Name);
                                Console.Error.WriteLine("= {0}", subject.AbsPath);
                                Console.Error.WriteLine("===========================");
                            }
                        }
                        finally
                        {
                            project.AbortTransaction();
                        }
                    }
                }

                if (success)
                {
                    Console.Out.WriteLine("[OK] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
                }
                else
                {
                    Console.Error.WriteLine("[FAILED] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
                }

                Assert.True(success, "At least one context was failed to check against the expected results.");
            }
            finally
            {
                project.Close(true);
            }
        }
コード例 #4
0
        //[Fact]
        public void TestCodeSample()
        {
            string ProjectConnStr;

            MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);

            MgaProject project = new MgaProject();
            bool       ro_mode;

            project.Open(ProjectConnStr, out ro_mode);

            MgaHelper.CheckParadigmVersionUpgrade(project);

            try
            {
                List <IMgaFCO> objectsToGetConfigurations = null;

                project.BeginTransactionInNewTerr();
                try
                {
                    // discover objects

                    var allObjects = project
                                     .RootFolder
                                     .ChildFolders
                                     .Cast <MgaFolder>()
                                     .Where(x => x.Name.StartsWith("0"))
                                     .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>())
                                     .Where(x => x.RootFCO == x);

                    // get all objects from folders starts with 0 within the root folder.
                    objectsToGetConfigurations = allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")).ToList();

                    objectsToGetConfigurations.Sort((x, y) =>
                    {
                        return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
                               x.Meta.Name.CompareTo(y.Meta.Name) :
                               x.AbsPath.CompareTo(y.AbsPath));
                    });
                }
                finally
                {
                    project.AbortTransaction();
                }

                Assert.True(objectsToGetConfigurations != null, "There are no object in the project that has to be checked.");

                int numContexts = objectsToGetConfigurations.Count;
                int numSuccess  = 0;
                int numFailures = 0;

                bool success = true;

                foreach (var subject in objectsToGetConfigurations)
                {
                    // single test
                    using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
                    {
                        IMgaFCOs configurations = null;

                        Assert.ThrowsDelegate d = () =>
                        {
                            configurations = masterInterpreter.GetConfigurations(subject as MgaModel);
                        };

                        Assert.DoesNotThrow(d);
                        //Assert.True(configurations != null, "GetConfiguration returned with null.");

                        if (configurations == null)
                        {
                            numFailures++;
                        }
                        else
                        {
                            numSuccess++;
                        }

                        // print out nicely in the GME console
                        project.BeginTransactionInNewTerr();
                        try
                        {
                            Console.Out.WriteLine("{0} [{1}] has {2} configurations.", subject.Name, subject.Meta.Name, configurations.Count);
                            foreach (IMgaFCO configuration in configurations)
                            {
                                Console.Out.WriteLine(" > {0} - {1}", configuration.Name, configuration.ID);
                            }
                        }
                        finally
                        {
                            project.AbortTransaction();
                        }
                    }
                }

                if (success)
                {
                    Console.Out.WriteLine("[OK] Got configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures);
                }
                else
                {
                    Console.Error.WriteLine("[FAILED] Tried to get configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures);
                }

                Assert.True(success, "At least one context was failed to check against the expected results.");
            }
            finally
            {
                project.Close(true);
            }
        }