コード例 #1
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();
            }
        }
コード例 #2
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();
            }
       }