public void SubsetMandatory_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initially");
            ORMModel model  = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role     role_2 = (Role)store.ElementDirectory.GetElement(new Guid("82DF5594-2020-4CA3-8154-FD92EE83F726"));

            myTestServices.LogValidationErrors("Intoduce Error: Make a role of supertype mandatory");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Found. Calling Undo to remove error...");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error removed with undo.");


            myTestServices.LogValidationErrors("Intoduce Error: Make a role of subtype mandatory");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Found. Calling Undo to remove error...");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = false;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed with changing property value...");
        }
Exemplo n.º 2
0
        public void FCMinMaxTest2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("FrequencyConstraint1").SingleElement;
            int min = constraint.MinFrequency;
            int max = constraint.MaxFrequency;

            using (Transaction t = store.TransactionManager.BeginTransaction("Fix Constraint"))
            {
                //Make the error
                constraint.MinFrequency = max;
                constraint.MaxFrequency = min;
                t.Commit();
            }

            myTestServices.LogValidationErrors("After adding error");
        }
Exemplo n.º 3
0
        public void DTBlankTest2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];

            model.Store.ElementDirectory.FindElement(UnspecifiedDataType.DomainClassId);
            UnspecifiedDataType unspecified = model.Store.ElementDirectory.FindElements <UnspecifiedDataType>()[0];

            ObjectType o = (ObjectType)model.ObjectTypesDictionary.GetElement("WifeId").SingleElement;


            using (Transaction t = store.TransactionManager.BeginTransaction("Add invalid data type error"))
            {
                //Make the error
                o.DataType = unspecified;
                t.Commit();
            }

            myTestServices.LogValidationErrors("After adding error");
        }
Exemplo n.º 4
0
        public void PopulationSampleTest(Store store)
        {
            myTestServices.LogValidationErrors("Expect V2=100 Population Mandatory");

            myTestServices.LogMessage("Testing IsIndependent and PopulationMandatoryError associated with implied mandatory constraint");
            ORMModel   model = store.ElementDirectory.FindElements <ORMModel>()[0];
            ObjectType v2    = (ObjectType)model.ObjectTypesDictionary.GetElement("V2").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Set IsIndependent"))
            {
                v2.IsIndependent = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Set IsIndependent, No error expected after explicit transaction");
            store.UndoManager.Undo();
            DomainTypeDescriptor.CreatePropertyDescriptor(v2, ObjectType.IsIndependentDomainPropertyId).SetValue(v2, true);
            myTestServices.LogValidationErrors("Set IsIndependent, No error expected after implicit transaction");
            store.UndoManager.Undo();

            myTestServices.LogMessage("Testing PopulationMandatoryError by turning on a SimpleMandatory constraint.");
            RoleBase   rightRole  = v2.PlayedRoleCollection[0];
            RoleBase   leftRole   = rightRole.OppositeRole;
            FactType   factType   = rightRole.FactType;
            ObjectType populateMe = leftRole.Role.RolePlayer;
            LinkedElementCollection <ObjectTypeInstance> populateMeInstances = populateMe.ObjectTypeInstanceCollection;
            LinkedElementCollection <ObjectTypeInstance> v2Instances         = v2.ObjectTypeInstanceCollection;

            using (Transaction t = store.TransactionManager.BeginTransaction("Set IsMandatory"))
            {
                leftRole.Role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Set IsMandatory, expect new errors for instances 'Tom' and 'Dick'");
            FactTypeInstance factTypeInstance;

            using (Transaction t = store.TransactionManager.BeginTransaction("Populate first row"))
            {
                factTypeInstance          = new FactTypeInstance(store);
                factTypeInstance.FactType = factType;
                new FactTypeRoleInstance(leftRole.Role, populateMeInstances[0]).FactTypeInstance = factTypeInstance;
                new FactTypeRoleInstance(rightRole.Role, v2Instances[0]).FactTypeInstance        = factTypeInstance;
                t.Commit();
            }

            myTestServices.LogMessage("Adding second population row one role at a time");
            myTestServices.LogValidationErrors("Add a complete FactTypeInstance for Tom, 1 error remaining for 'Dick'");
            using (Transaction t = store.TransactionManager.BeginTransaction("Populate second row"))
            {
                factTypeInstance          = new FactTypeInstance(store);
                factTypeInstance.FactType = factType;
                new FactTypeRoleInstance(leftRole.Role, populateMeInstances[1]).FactTypeInstance = factTypeInstance;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Add a partial FactTypeInstance for Dick, 1 error remaining for partial FactTypeInstance");
            using (Transaction t = store.TransactionManager.BeginTransaction("Finish second row populations"))
            {
                new FactTypeRoleInstance(rightRole.Role, v2Instances[0]).FactTypeInstance = factTypeInstance;
                t.Commit();
            }
        }
Exemplo n.º 5
0
        public void NMinus1Test2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FactType fact  = (FactType)store.ElementDirectory.GetElement(new Guid("655E4D9B-9835-4BE2-A7BC-FEBE51A32E84"));
            LinkedElementCollection <RoleBase> roles = fact.RoleCollection;


            using (Transaction t = store.TransactionManager.BeginTransaction("Fix Constraint"))
            {
                foreach (UniquenessConstraint constraint in fact.GetInternalConstraints <UniquenessConstraint>())
                {
                    //Make the error
                    constraint.RoleCollection.Clear();
                    constraint.RoleCollection.Add(roles[0].Role);
                    break;
                }

                t.Commit();
            }
            myTestServices.LogValidationErrors("After adding error");
        }
Exemplo n.º 6
0
        public void Test1(Store store)
        {
            // The store has been preloaded at this point with the .orm file specified in the
            // Tests.Test1.Compare.orm resource embedded into this project. If an embedded resource
            // is not found with this name, then a new orm file is created by loading the default
            // 'ORM Model File' template. This creates a model called 'NewModel' with a single diagram
            // attached to it.

            // Dump a report of the current model validation errors. The loaded file is missing an
            // internal constraint on a fact type, so we expect errors
            myTestServices.LogValidationErrors("Before constraint repair");

            // Find the fact that that needs fixing and repair it
            //ORMModel model = (ORMModel)store.ElementDirectory.GetElement(ORMModel.DomainClassId);
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FactType fact  = (FactType)store.ElementDirectory.GetElement(new Guid("CB33E377-9ADC-46BA-8E1B-24AE46BC0854"));
            Role     role  = fact.RoleCollection[1].Role;

            // At this point, we either need to open a transaction on the store with
            // using (Transaction t = store.TransactionManager.BeginTransaction("Transaction name"))
            // or we grab the property descriptor, which emulates setting the property through the
            // property grid and pushes a transaction for us.

            DomainTypeDescriptor.CreatePropertyDescriptor(role, Role.MultiplicityDomainPropertyId).SetValue(role, RoleMultiplicity.ExactlyOne);

            // Turn the following code back on to demonstrate a comparison failure

            // ~~ outdated code, do not turn on ~~//
            //fact = (FactType)model.FactTypesDictionary.GetElement("FactType2").SingleElement;
            //fact.CreatePropertyDescriptor(store.MetaDataDirectory.FindMetaAttribute(NamedElement.NameMetaAttributeGuid), fact).SetValue(fact, "changeFactType2");
            // ~~ /outdated code, do not turn on ~~//


            // After the method exits, the Compare and LogValidationErrors methods will be run automatically against
            // the test service. The expected results for the Compare are in Tests.Test1.Compare.orm. You can also
            // compare at intermediate stages by explicitly running the IORMToolTestServices.Compare function, generally
            // with a reference name to distinguish the intermediate stages from the automatic comparison.
        }
Exemplo n.º 7
0
        public void ExactlyOneTest1a(Store store)
        {
            myTestServices.LogValidationErrors("No errors expected");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("TestFrequency").SingleElement;

            DomainTypeDescriptor.CreatePropertyDescriptor(constraint, FrequencyConstraint.MaxFrequencyDomainPropertyId).SetValue(constraint, 1);
            myTestServices.LogValidationErrors("Error introduced");

            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                constraint.MinFrequency = 3;
                constraint.MaxFrequency = 4;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error cleared with code");
            store.UndoManager.Undo();
            ((IORMToolServices)store).ModelErrorActivationService.ActivateError(constraint, constraint.FrequencyConstraintExactlyOneError);
            myTestServices.LogValidationErrors("Fixing error with error activation service");
        }
Exemplo n.º 8
0
        public void ConstContradictTests_1a(Store store)
        {
            myTestServices.LogValidationErrors("ExclusionContradictsEqualityError exists");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            ExclusionConstraint constraint = (ExclusionConstraint)model.ConstraintsDictionary.GetElement("ExConstraint").FirstElement;

            myTestServices.LogValidationErrors("Removing Exclusion Constraint");

            using (Transaction t = store.TransactionManager.BeginTransaction("Remove Ex Constraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Removed");
        }
        public void ResolvePreferredTest1(Store store)
        {
            IElementDirectory   directory       = store.ElementDirectory;
            SubtypeFact         FiveToTwo       = (SubtypeFact)directory.GetElement(new Guid("9B85CC3F-FAA1-485B-A6CA-DE65165C6AE5"));
            SubtypeFact         FiveToThree     = (SubtypeFact)directory.GetElement(new Guid("C48F356A-DC20-4CD8-AD6A-EE4518622FFB"));
            SubtypeFact         SixToFive       = (SubtypeFact)directory.GetElement(new Guid("321CD412-8DAA-4D35-8D4E-D8D5915F07E0"));
            SubtypeFact         SixToSeven      = (SubtypeFact)directory.GetElement(new Guid("D6A4C2F2-3F99-4E2F-AB2F-407E03AB6F42"));
            SubtypeFact         FiveToFour      = (SubtypeFact)directory.GetElement(new Guid("DE1FC770-19A5-4CA9-AEF7-CE1204D80270"));
            SubtypeFact         SevenToFour     = (SubtypeFact)directory.GetElement(new Guid("71D29425-481E-445B-8F8A-63E9F29F761A"));
            ORMModel            model           = FiveToTwo.Model;
            RoleValueConstraint valueConstraint = (RoleValueConstraint)model.ConstraintsDictionary.GetElement("RoleValueConstraint1").SingleElement;

            myTestServices.LogValidationErrors("Expected three initial errors");

            myTestServices.LogMessage("Scenario 1: Make 5->2 preferred path, sibling and downstream subtypes should all be preferred");
            DomainTypeDescriptor.CreatePropertyDescriptor(FiveToTwo, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(FiveToTwo, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("5->4, 6->5, 6->7 are on the preferred path: " + (FiveToFour.ProvidesPreferredIdentifier && SixToFive.ProvidesPreferredIdentifier && SixToSeven.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a string type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 2: Make 5->3 preferred path, downstream subtypes are no ambiguous");
            DomainTypeDescriptor.CreatePropertyDescriptor(FiveToThree, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(FiveToThree, true);
            myTestServices.LogValidationErrors("Two errors expected");
            myTestServices.LogMessage("5->2, 5->4, 6->5, 6->7 are not preferred: " + (!(FiveToTwo.ProvidesPreferredIdentifier || FiveToFour.ProvidesPreferredIdentifier || SixToFive.ProvidesPreferredIdentifier || SixToSeven.ProvidesPreferredIdentifier)).ToString());

            myTestServices.LogMessage("Scenario 3: Make 6->5 preferred path");
            DomainTypeDescriptor.CreatePropertyDescriptor(SixToFive, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(SixToFive, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("6->7 is not on the preferred path: " + (!SixToSeven.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a number type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 4: Make 6->7 preferred path");
            DomainTypeDescriptor.CreatePropertyDescriptor(SixToSeven, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(SixToSeven, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("6->5 is not on the preferred path: " + (!SixToFive.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a string type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 5: Delete 7->4 to break subtype structure");
            using (Transaction t = store.TransactionManager.BeginTransaction("Break graph"))
            {
                SevenToFour.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Expecting invalid graph, detached valuetype, and no reference scheme errors");

            myTestServices.LogMessage("Scenario 6: Delete 6->5 to make graph valid");
            using (Transaction t = store.TransactionManager.BeginTransaction("Graph OK"))
            {
                SixToFive.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Expecting detached valuetype and no reference scheme errors");

            myTestServices.LogMessage("Scenario 7: Set identifier on 7 to clear errors");
            using (Transaction t = store.TransactionManager.BeginTransaction("Clear errors"))
            {
                SixToSeven.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
            myTestServices.LogValidationErrors("No errors expected");

            myTestServices.LogValidationErrors("Scenario 8: (Undo scenarios 5-7) Make 5->4 preferred path and give 4 an explicit id in one transaction");
            store.UndoManager.Undo();
            store.UndoManager.Undo();
            store.UndoManager.Undo();
            using (Transaction t = store.TransactionManager.BeginTransaction("Change id and make preferred in one transaction"))
            {
                // Note that doing this in the opposite order in two transactions has the same result
                FiveToFour.ProvidesPreferredIdentifier   = true;
                FiveToFour.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
            myTestServices.LogValidationErrors("No errors expected");

            myTestServices.LogValidationErrors("Scenario 9: (Undo scenario 8) Make 5->4 preferred path then give 4 an explicit id to make 5 and 6 ambiguous");
            store.UndoManager.Undo();
            using (Transaction t = store.TransactionManager.BeginTransaction("Change preferred path"))
            {
                FiveToFour.ProvidesPreferredIdentifier = true;
                t.Commit();
            }
            using (Transaction t = store.TransactionManager.BeginTransaction("Introduce id that interferes with split identifier path"))
            {
                FiveToFour.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Run all tests for the given type that match the
        /// category filters specified for this suite
        /// </summary>
        /// <param name="testType">A type with a Test attribute</param>
        /// <param name="services">Services used to run the test. IORMToolTestServices can
        /// be retrieved from services.ServiceProvider.</param>
        /// <param name="suiteReport">The suite report callback</param>
        private void RunTests(Type testType, IORMToolServices services, IORMToolTestSuiteReport suiteReport)
        {
            IORMToolTestServices testServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
            object testTypeInstance           = null;

            object[]     methodParams = null;
            MethodInfo[] methods      = testType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            int          methodCount  = methods.Length;

            for (int i = 0; i < methodCount; ++i)
            {
                MethodInfo method         = methods[i];
                object[]   testAttributes = method.GetCustomAttributes(typeof(ORMTestAttribute), false);
                Debug.Assert(testAttributes.Length < 2, "Single use attribute with inherit=false, should only pick up zero or one attributes");
                // Make sure that the method is flagged as a Test method that can be run per the current category settings
                if (testAttributes.Length == 0 || !CheckCategoryFilters((ORMTestAttribute)testAttributes[0]))
                {
                    continue;
                }

                // Make sure we've instantiated the test class
                if (testTypeInstance == null)
                {
                    ConstructorInfo constructor;
                    if (null != (constructor = testType.GetConstructor(new Type[] { typeof(IORMToolServices) })))
                    {
                        testTypeInstance = constructor.Invoke(new object[] { services });
                        methodParams     = new object[1];
                    }
                    bool loadFailure = null == testTypeInstance;
                    suiteReport.BeginTestClass(testType.Namespace, testType.Name, loadFailure);
                    if (loadFailure)
                    {
                        return;
                    }
                }

                ParameterInfo[] methodParamInfos = method.GetParameters();
                if (!(methodParamInfos.Length == 1 && typeof(Store).IsAssignableFrom(methodParamInfos[0].ParameterType)))
                {
                    // The test method does not match the signature we need, it should
                    // not have been marked with the Test attribute
                    suiteReport.ReportTestResults(method.Name, ORMTestResult.FailBind, null);
                }
                else
                {
                    Store store = null;
                    try
                    {
                        // Prepare the test services for a new test
                        testServices.OpenReport();

                        // Populate a store. Automatically loads the starting
                        // file from the test assembly if one is provided
                        store = testServices.Load(method, null, null);

                        // Run the method
                        methodParams[0] = store;
                        method.Invoke(testTypeInstance, methodParams);

                        // Compare the current contents of the store with the
                        // expected state
                        testServices.Compare(store, method, null);
                        testServices.LogValidationErrors(null);
                    }
                    finally
                    {
                        if (store != null)
                        {
                            ((IDisposable)store).Dispose();
                        }

                        // Close the report and see if the report matches the expected results
                        using (XmlReader reportReader = testServices.CloseReport(method))
                        {
                            string methodName     = method.Name;
                            string resourceName   = string.Concat(testType.FullName, ".", methodName, ".Report.xml");
                            Stream baselineStream = null;
                            try
                            {
                                Assembly testAssembly = testType.Assembly;
                                // Get the baseline that we're comparing to
                                if (null != testAssembly.GetManifestResourceInfo(resourceName))
                                {
                                    baselineStream = testAssembly.GetManifestResourceStream(resourceName);
                                }
                                if (baselineStream != null)
                                {
                                    bool hasDiff = false;

                                    // See if the data is different.
                                    XmlDiff           diff           = DiffEngine;
                                    XmlReaderSettings readerSettings = DetachableReaderSettings;
                                    XmlWriterSettings writerSettings = DetachableWriterSettings;
                                    using (MemoryStream diffStream = new MemoryStream())
                                    {
                                        using (XmlReader baselineReader = XmlReader.Create(baselineStream, readerSettings))
                                        {
                                            using (XmlWriter diffWriter = XmlWriter.Create(diffStream, writerSettings))
                                            {
                                                hasDiff = !diff.Compare(baselineReader, reportReader, diffWriter);
                                            }
                                        }
                                        if (hasDiff)
                                        {
                                            // Record the diffgram in the suite report
                                            diffStream.Seek(0, SeekOrigin.Begin);
                                            using (XmlReader diffReader = XmlTextReader.Create(diffStream, readerSettings))
                                            {
                                                suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportDiffgram, diffReader);
                                            }
                                        }
                                        else
                                        {
                                            // Record a passing result
                                            suiteReport.ReportTestResults(methodName, ORMTestResult.Pass, null);
                                        }
                                    }
                                }
                                else
                                {
                                    // Record the full report, we have no baseline to compare against
                                    suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportBaseline, reportReader);
                                }
                            }
                            finally
                            {
                                if (baselineStream != null)
                                {
                                    ((IDisposable)baselineStream).Dispose();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void EqualityMandatoryImplied_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role     role  = (Role)store.ElementDirectory.GetElement(new Guid("1C424E34-8369-41EC-850F-FD24E7B30C7A"));

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error is removed with Undo");
        }