public async Task VerifyThatUserRuleVerificationCanBeExecutedAndMessageBusMessagesAreReceived()
        {
            var messageReceivedCounter = 0;

            var service = new RuleVerificationService(new List <Lazy <IBuiltInRule, IBuiltInRuleMetaData> >());

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri);

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri);
            var userRuleVerification   = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                IsActive = true,
                Rule     = binaryRelationshipRule
            };

            this.session.Setup(s => s.Write(It.IsAny <OperationContainer>()))
            .Callback(() =>
            {
                CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);
            });

            ruleVerificationList.RuleVerification.Add(userRuleVerification);

            var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification)
                           .Subscribe(
                x => { messageReceivedCounter++; });

            await service.Execute(this.session.Object, ruleVerificationList);

            Assert.AreEqual(3, messageReceivedCounter);
        }
예제 #2
0
        public void VerifyThatUserRuleVerificationCanBeExecutedAndMessageBusMessagesAreReceived()
        {
            var messageReceivedCounter = 0;

            var service = new RuleVerificationService(new List <Lazy <IBuiltInRule, IBuiltInRuleMetaData> >());

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri);

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri);
            var userRuleVerification   = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                IsActive = true,
                Rule     = binaryRelationshipRule
            };

            ruleVerificationList.RuleVerification.Add(userRuleVerification);

            var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification)
                           .Subscribe(
                x => { messageReceivedCounter++; });

            service.Execute(this.session.Object, ruleVerificationList);

            Assert.AreEqual(2, messageReceivedCounter);
        }
        public void TestGetOwnerThrowEx()
        {
            var userRuleVerification = new UserRuleVerification();

            Assert.Throws <ContainmentException>(() =>
            {
                Console.WriteLine(userRuleVerification.Owner);
            });
        }
        public void TestGetOwner()
        {
            var thing = new UserRuleVerification();
            var list  = new RuleVerificationList();

            list.Owner = new DomainOfExpertise();
            list.RuleVerification.Add(thing);

            Assert.IsTrue(ReferenceEquals(list.Owner, thing.Owner));
        }
        public void TestGetDerivedName()
        {
            var userRuleVerif = new UserRuleVerification();

            userRuleVerif.Rule = new DecompositionRule()
            {
                Name = "rule"
            };

            Assert.AreEqual("rule", userRuleVerif.Name);
        }
        /// <summary>
        /// Serialize the <see cref="UserRuleVerification"/>
        /// </summary>
        /// <param name="userRuleVerification">The <see cref="UserRuleVerification"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(UserRuleVerification userRuleVerification)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userRuleVerification.ClassKind)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](userRuleVerification.ExecutedOn));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](userRuleVerification.Iid));
            jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](userRuleVerification.IsActive));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userRuleVerification.ModifiedOn));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userRuleVerification.RevisionNumber));
            jsonObject.Add("rule", this.PropertySerializerMap["rule"](userRuleVerification.Rule));
            jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), userRuleVerification.Status)));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userRuleVerification.ThingPreference));
            return(jsonObject);
        }
        public void SetUp()
        {
            this.userRuleVerificationRuleChecker = new UserRuleVerificationRuleChecker();

            this.modelReferenceDataLibrary = new ModelReferenceDataLibrary();
            this.engineeringModelSetup     = new EngineeringModelSetup();
            this.engineeringModel          = new EngineeringModel();
            this.iteration            = new Iteration();
            this.ruleVerificationList = new RuleVerificationList();
            this.userRuleVerification = new UserRuleVerification();

            this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary);
            this.engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;
            this.engineeringModel.Iteration.Add(this.iteration);
            this.iteration.RuleVerificationList.Add(this.ruleVerificationList);
            this.ruleVerificationList.RuleVerification.Add(this.userRuleVerification);
        }
예제 #8
0
        /// <summary>
        /// Create a new <see cref="UserRuleVerification"/>
        /// </summary>
        /// <param name="ruleVerificationList">
        /// The container <see cref="RuleVerificationList"/> of the <see cref="UserRuleVerification"/> that is to be created.
        /// </param>
        /// <param name="rule">
        /// The <see cref="Rule"/> that the new <see cref="UserRuleVerification"/> references.
        /// </param>
        /// <param name="session">
        /// The <see cref="ISession"/> in which the new <see cref="UserRuleVerification"/> is to be added
        /// </param>
        public async Task CreateUserRuleVerification(RuleVerificationList ruleVerificationList, Rule rule, ISession session)
        {
            if (ruleVerificationList == null)
            {
                throw new ArgumentNullException(nameof(ruleVerificationList), "The ruleVerificationList must not be null");
            }

            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule), "The rule must not be null");
            }

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session), "The session may not be null");
            }

            var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), null, null)
            {
                Rule     = rule,
                IsActive = false,
                Status   = RuleVerificationStatusKind.NONE
            };

            var clone = ruleVerificationList.Clone(false);

            clone.RuleVerification.Add(userRuleVerification);

            var transactionContext = TransactionContextResolver.ResolveContext(ruleVerificationList);
            var transaction        = new ThingTransaction(transactionContext, clone);

            transaction.Create(userRuleVerification);

            try
            {
                var operationContainer = transaction.FinalizeTransaction();
                await session.Write(operationContainer);
            }
            catch (Exception ex)
            {
                logger.Error("The UserRuleVerification could not be created", ex);
                throw ex;
            }
        }
        /// <summary>
        /// Persist the DTO composition to the ORM layer.
        /// </summary>
        /// <param name="transaction">
        /// The transaction object.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="userRuleVerification">
        /// The userRuleVerification instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool CreateContainment(NpgsqlTransaction transaction, string partition, UserRuleVerification userRuleVerification)
        {
            var results = new List <bool>();

            foreach (var violation in this.ResolveFromRequestCache(userRuleVerification.Violation))
            {
                results.Add(this.RuleViolationService.CreateConcept(transaction, partition, violation, userRuleVerification));
            }

            return(results.All(x => x));
        }
        /// <summary>
        /// Execute the <see cref="Rule"/> verification.
        /// </summary>
        /// <param name="session">
        /// The <see cref="ISession"/> instance used to update the contained <see cref="RuleVerification"/> instances on the data-source.
        /// </param>
        /// <param name="userRuleVerification">
        /// The <see cref="UserRuleVerification"/> that references <see cref="Rule"/> that needs to be verified.
        /// </param>
        /// <param name="container">
        /// The container <see cref="RuleVerificationList"/> of the <paramref name="userRuleVerification"/>
        /// </param>
        /// <returns>An awaitable <see cref="Task"/></returns>
        private async Task Execute(ISession session, UserRuleVerification userRuleVerification, RuleVerificationList container)
        {
            var iteration = (Iteration)container.Container;

            if (iteration == null)
            {
                throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid));
            }

            foreach (var violation in userRuleVerification.Violation)
            {
                CDPMessageBus.Current.SendObjectChangeEvent(violation, EventKind.Removed);
            }

            userRuleVerification.Violation.Clear();
            userRuleVerification.Status = RuleVerificationStatusKind.PASSED;

            CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);

            IEnumerable <RuleViolation> violations = null;

            switch (userRuleVerification.Rule.ClassKind)
            {
            case ClassKind.BinaryRelationshipRule:
                var binaryRelationshipRule = (BinaryRelationshipRule)userRuleVerification.Rule;
                violations = binaryRelationshipRule.Verify(iteration);
                break;

            case ClassKind.DecompositionRule:
                var decompositionRule = (DecompositionRule)userRuleVerification.Rule;
                violations = decompositionRule.Verify(iteration);
                break;

            case ClassKind.MultiRelationshipRule:
                var multiRelationshipRule = (MultiRelationshipRule)userRuleVerification.Rule;
                violations = multiRelationshipRule.Verify(iteration);
                break;

            case ClassKind.ParameterizedCategoryRule:
                var parameterizedCategoryRule = (ParameterizedCategoryRule)userRuleVerification.Rule;
                violations = parameterizedCategoryRule.Verify(iteration);
                break;

            case ClassKind.ReferencerRule:
                var referencerRule = (ReferencerRule)userRuleVerification.Rule;
                violations = referencerRule.Verify(iteration);
                break;
            }

            if (violations is not null)
            {
                userRuleVerification.Status = RuleVerificationStatusKind.FAILED;

                IDisposable subscription = null;

                //Listen for changes to the verification rule that will happen after UpdateExecutedOn in order to get the updated version.
                //The violations must be added lastly as they are not persistent
                subscription = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification)
                               .Where(objectChange => objectChange.EventKind == EventKind.Updated)
                               .ObserveOn(RxApp.MainThreadScheduler)
                               .Subscribe(updated =>
                {
                    //Only interested in a single update
                    subscription.Dispose();

                    var verification = updated.ChangedThing as UserRuleVerification;
                    verification.Violation.AddRange(violations);

                    CDPMessageBus.Current.SendObjectChangeEvent(verification, EventKind.Updated);

                    foreach (var ruleViolation in violations)
                    {
                        CDPMessageBus.Current.SendObjectChangeEvent(ruleViolation, EventKind.Added);
                    }
                });
            }

            await this.UpdateExecutedOn(session, userRuleVerification);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserRuleVerificationDialogViewModel"/> class
 /// </summary>
 /// <param name="userRuleVerification">
 /// The <see cref="UserRuleVerification"/> that is the subject of the current view-model. This is the object
 /// that will be either created, or edited.
 /// </param>
 /// <param name="transaction">
 /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
 /// </param>
 /// <param name="session">
 /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="DialogViewModelBase{T}"/> is the root of all <see cref="DialogViewModelBase{T}"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="DialogViewModelBase{T}"/> performs
 /// </param>
 /// <param name="thingDialogNavigationService">
 /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>.
 /// </param>
 /// <param name="container">
 /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog
 /// </param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 public UserRuleVerificationDialogViewModel(UserRuleVerification userRuleVerification, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container, IEnumerable <Thing> chainOfContainers)
     : base(userRuleVerification, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserRuleVerificationRowViewModel"/> class.
 /// </summary>
 /// <param name="userRuleVerification">
 /// The <see cref="UserRuleVerification"/> that is represented by the current row-view-model.
 /// </param>
 /// <param name="session">
 /// The current active <see cref="ISession"/>
 /// </param>
 /// <param name="containerViewModel">
 /// The view-model that is the container of the current row-view-model.
 /// </param>
 public UserRuleVerificationRowViewModel(UserRuleVerification userRuleVerification, ISession session, IViewModelBase <Thing> containerViewModel)
     : base(userRuleVerification, session, containerViewModel)
 {
 }
예제 #13
0
        public void VerifyThatViolationAreAddedRemoved()
        {
            var decompositionRule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "decomposition"
            };

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            // add a rule verification
            var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Name     = "BuiltIn",
                Status   = RuleVerificationStatusKind.INCONCLUSIVE,
                IsActive = true,
            };

            var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                IsActive = true,
                Rule     = decompositionRule
            };

            ruleVerificationList.RuleVerification.Add(userRuleVerification);
            ruleVerificationList.RuleVerification.Add(builtInRuleVerification);

            var listRowViewModel = new RuleVerificationListRowViewModel(ruleVerificationList, this.session.Object, null);

            var violation = new RuleViolation(Guid.NewGuid(), this.cache, this.uri)
            {
                Description = "violation",
            };

            var builtinRow =
                listRowViewModel.ContainedRows.Single(x => x.Thing.ClassKind == ClassKind.BuiltInRuleVerification);
            var userRow = listRowViewModel.ContainedRows.Single(x => x.Thing.ClassKind == ClassKind.UserRuleVerification);

            Assert.IsEmpty(builtinRow.ContainedRows);
            Assert.IsEmpty(userRow.ContainedRows);

            builtInRuleVerification.Violation.Add(violation);
            this.revision.SetValue(builtInRuleVerification, 10);
            CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated);
            Assert.IsNotEmpty(builtinRow.ContainedRows);

            builtInRuleVerification.Violation.Clear();
            this.revision.SetValue(builtInRuleVerification, 20);
            CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated);
            Assert.IsEmpty(builtinRow.ContainedRows);

            userRuleVerification.Violation.Add(violation);
            this.revision.SetValue(userRuleVerification, 10);
            CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);
            Assert.IsNotEmpty(userRow.ContainedRows);

            userRuleVerification.Violation.Clear();
            this.revision.SetValue(userRuleVerification, 20);
            CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);
            Assert.IsEmpty(userRow.ContainedRows);
        }
예제 #14
0
        public void VerifyThatPropertiesAreSetAndContainRowsArePopulated()
        {
            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var listRowViewModel = new RuleVerificationListRowViewModel(ruleVerificationList, this.session.Object, null);

            Assert.IsEmpty(listRowViewModel.ContainedRows);

            // add a rule verification
            var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Name     = "BuiltIn",
                Status   = RuleVerificationStatusKind.INCONCLUSIVE,
                IsActive = true
            };

            ruleVerificationList.RuleVerification.Add(builtInRuleVerification);
            this.revision.SetValue(ruleVerificationList, 2);
            CDPMessageBus.Current.SendObjectChangeEvent(ruleVerificationList, EventKind.Updated);

            var builtInRuleVerificationRow = listRowViewModel.ContainedRows.Single(x => x.Thing == builtInRuleVerification);

            Assert.AreEqual(builtInRuleVerification, builtInRuleVerificationRow.Thing);
            Assert.AreEqual("BuiltIn", ((RuleVerification)builtInRuleVerificationRow.Thing).Name);

            // add a rule verification
            var parameterizedCategoryRule = new ParameterizedCategoryRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "Parameterized Category Rule"
            };

            var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Status   = RuleVerificationStatusKind.INCONCLUSIVE,
                IsActive = true,
                Rule     = parameterizedCategoryRule
            };

            ruleVerificationList.RuleVerification.Add(userRuleVerification);
            this.revision.SetValue(ruleVerificationList, 3);
            CDPMessageBus.Current.SendObjectChangeEvent(ruleVerificationList, EventKind.Updated);

            var userRuleVerificationRow = listRowViewModel.ContainedRows.Single(x => x.Thing == userRuleVerification);

            Assert.AreEqual(userRuleVerification, userRuleVerificationRow.Thing);
            Assert.AreEqual("Parameterized Category Rule", ((RuleVerification)userRuleVerificationRow.Thing).Name);

            // Remove a rule verification
            ruleVerificationList.RuleVerification.Remove(builtInRuleVerification);
            this.revision.SetValue(ruleVerificationList, 4);
            CDPMessageBus.Current.SendObjectChangeEvent(ruleVerificationList, EventKind.Updated);
            Assert.AreEqual(1, listRowViewModel.ContainedRows.Count);

            // Remove a rule verification
            ruleVerificationList.RuleVerification.Remove(userRuleVerification);
            this.revision.SetValue(ruleVerificationList, 5);
            CDPMessageBus.Current.SendObjectChangeEvent(ruleVerificationList, EventKind.Updated);
            Assert.AreEqual(0, listRowViewModel.ContainedRows.Count);
        }
예제 #15
0
        /// <summary>
        /// Execute the <see cref="Rule"/> verification.
        /// </summary>
        /// <param name="session">
        /// The <see cref="ISession"/> instance used to update the contained <see cref="RuleVerification"/> instances on the data-source.
        /// </param>
        /// <param name="userRuleVerification">
        /// The <see cref="UserRuleVerification"/> that references <see cref="Rule"/> that needs to be verified.
        /// </param>
        /// <param name="container">
        /// The container <see cref="RuleVerificationList"/> of the <paramref name="userRuleVerification"/>
        /// </param>
        private void Execute(ISession session, UserRuleVerification userRuleVerification, RuleVerificationList container)
        {
            var iteration = (Iteration)container.Container;

            if (iteration == null)
            {
                throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid));
            }

            foreach (var violation in userRuleVerification.Violation)
            {
                CDPMessageBus.Current.SendObjectChangeEvent(violation, EventKind.Removed);
            }

            userRuleVerification.Violation.Clear();
            CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);

            IEnumerable <RuleViolation> violations = null;

            switch (userRuleVerification.Rule.ClassKind)
            {
            case ClassKind.BinaryRelationshipRule:
                var binaryRelationshipRule = (BinaryRelationshipRule)userRuleVerification.Rule;
                violations = binaryRelationshipRule.Verify(iteration);
                break;

            case ClassKind.DecompositionRule:
                var decompositionRule = (DecompositionRule)userRuleVerification.Rule;
                violations = decompositionRule.Verify(iteration);
                break;

            case ClassKind.MultiRelationshipRule:
                var multiRelationshipRule = (MultiRelationshipRule)userRuleVerification.Rule;
                violations = multiRelationshipRule.Verify(iteration);
                break;

            case ClassKind.ParameterizedCategoryRule:
                var parameterizedCategoryRule = (ParameterizedCategoryRule)userRuleVerification.Rule;
                violations = parameterizedCategoryRule.Verify(iteration);
                break;

            case ClassKind.ReferencerRule:
                var referencerRule = (ReferencerRule)userRuleVerification.Rule;
                violations = referencerRule.Verify(iteration);
                break;
            }

            this.UpdateExecutedOn(session, userRuleVerification);

            if (violations != null)
            {
                userRuleVerification.Violation.AddRange(violations);

                CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);

                foreach (var ruleViolation in violations)
                {
                    CDPMessageBus.Current.SendObjectChangeEvent(ruleViolation, EventKind.Added);
                }
            }
        }
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.siteDirectory           = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.systemDomainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "System", ShortName = "SYS"
            };
            this.siteDirectory.Domain.Add(this.systemDomainOfExpertise);

            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();

            var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testRDL", ShortName = "test"
            };

            this.binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "binary", ShortName = "binary"
            };
            srdl.Rule.Add(this.binaryRelationshipRule);

            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = srdl
            };

            mrdl.RequiredRdl = srdl;
            engineeringModelSetup.RequiredRdl.Add(mrdl);
            this.decompositionRule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "decomposition", ShortName = "decomposition"
            };
            mrdl.Rule.Add(this.decompositionRule);

            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.engineeringModel.EngineeringModelSetup = engineeringModelSetup;
            this.iteration                = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            this.iterationSetup           = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.iteration.IterationSetup = this.iterationSetup;

            this.engineeringModel.Iteration.Add(iteration);

            this.ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.systemDomainOfExpertise
            };

            iteration.RuleVerificationList.Add(this.ruleVerificationList);
            this.userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Rule = this.binaryRelationshipRule
            };


            this.ruleVerificationList.RuleVerification.Add(this.userRuleVerification);

            this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));

            var chainOfRdls = new List <ReferenceDataLibrary>();

            chainOfRdls.Add(mrdl);
            chainOfRdls.Add(srdl);

            this.session.Setup(x => x.GetEngineeringModelRdlChain(It.IsAny <EngineeringModel>())).Returns(chainOfRdls);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, null);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }