public void Setup()
        {
            this.securityContext = new Mock <ISecurityContext>();
            this.optionService   = new Mock <IOptionService>();
            this.actualFiniteStateListService = new Mock <IActualFiniteStateListService>();
            this.parameterService             = new Mock <ICompoundParameterTypeService>();
            this.valueSetService  = new Mock <IParameterValueSetService>();
            this.iterationService = new Mock <IIterationService>();
            this.parameterOverrideValueSetService     = new Mock <IParameterOverrideValueSetService>();
            this.parameterSubscriptionValueSetService = new Mock <IParameterSubscriptionValueSetService>();
            this.parameterSubscriptionService         = new Mock <IParameterSubscriptionService>();
            this.parameterOverrideService             = new Mock <IParameterOverrideService>();
            this.parameterTypeComponentService        = new Mock <IParameterTypeComponentService>();
            this.parameterTypeService     = new Mock <IParameterTypeService>();
            this.elementUsageService      = new Mock <IElementUsageService>();
            this.defaultValueArrayFactory = new Mock <IDefaultValueArrayFactory>();

            this.npgsqlTransaction = null;

            this.iteration = new Iteration(Guid.NewGuid(), 1);
            this.option1   = new Option(Guid.NewGuid(), 1);
            this.option2   = new Option(Guid.NewGuid(), 1);

            this.iteration.Option.Add(new OrderedItem {
                K = 1, V = this.option1.Iid
            });
            this.iteration.Option.Add(new OrderedItem {
                K = 2, V = this.option2.Iid
            });

            this.actualList   = new ActualFiniteStateList(Guid.NewGuid(), 1);
            this.actualState1 = new ActualFiniteState(Guid.NewGuid(), 1);
            this.actualState2 = new ActualFiniteState(Guid.NewGuid(), 1);

            this.actualList.ActualState.Add(this.actualState1.Iid);
            this.actualList.ActualState.Add(this.actualState2.Iid);

            this.parameter = new Parameter(Guid.NewGuid(), 1);

            this.cptParameterType = new CompoundParameterType(Guid.NewGuid(), 1);
            this.boolPt           = new BooleanParameterType(Guid.NewGuid(), 1);
            this.cpt1             = new ParameterTypeComponent(Guid.NewGuid(), 1)
            {
                ParameterType = this.boolPt.Iid
            };
            this.cpt2 = new ParameterTypeComponent(Guid.NewGuid(), 1)
            {
                ParameterType = this.boolPt.Iid
            };

            this.cptParameterType.Component.Add(new OrderedItem {
                K = 1, V = this.cpt1.Iid.ToString()
            });
            this.cptParameterType.Component.Add(new OrderedItem {
                K = 2, V = this.cpt2.Iid.ToString()
            });

            this.sideEffect = new ParameterSideEffect
            {
                IterationService                     = this.iterationService.Object,
                ActualFiniteStateListService         = this.actualFiniteStateListService.Object,
                ParameterValueSetService             = this.valueSetService.Object,
                ParameterOverrideValueSetService     = this.parameterOverrideValueSetService.Object,
                ParameterSubscriptionValueSetService = this.parameterSubscriptionValueSetService.Object,
                ParameterOverrideService             = this.parameterOverrideService.Object,
                ParameterSubscriptionService         = this.parameterSubscriptionService.Object,
                ParameterTypeService                 = this.parameterTypeService.Object,
                ElementUsageService                  = this.elementUsageService.Object,
                ParameterTypeComponentService        = this.parameterTypeComponentService.Object,
                OptionService                        = this.optionService.Object,
                DefaultValueArrayFactory             = this.defaultValueArrayFactory.Object,
                ParameterValueSetFactory             = new ParameterValueSetFactory(),
                ParameterOverrideValueSetFactory     = new ParameterOverrideValueSetFactory(),
                ParameterSubscriptionValueSetFactory = new ParameterSubscriptionValueSetFactory()
            };

            // prepare mock data
            this.elementDefinition = new ElementDefinition(Guid.NewGuid(), 1);
            this.elementDefinition.Parameter.Add(this.parameter.Iid);
            this.parameterOverride = new ParameterOverride(Guid.NewGuid(), 1)
            {
                Parameter = this.parameter.Iid
            };
            this.elementUsage = new ElementUsage(Guid.NewGuid(), 1)
            {
                ElementDefinition = this.elementDefinition.Iid, ParameterOverride = { this.parameterOverride.Iid }
            };

            this.parameterService.Setup(x => x.Get(It.IsAny <NpgsqlTransaction>(), "SiteDirectory", It.Is <IEnumerable <Guid> >(y => y.Contains(this.cptParameterType.Iid)), this.securityContext.Object))
            .Returns(new List <Thing> {
                this.cptParameterType
            });

            this.iterationService.Setup(x => x.GetShallow(null, "partition", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.iteration
            });

            this.actualFiniteStateListService.Setup(x => x.GetShallow(It.IsAny <NpgsqlTransaction>(), "partition", It.Is <IEnumerable <Guid> >(y => y.Contains(this.actualList.Iid)), this.securityContext.Object))
            .Returns(new List <Thing> {
                this.actualList
            });

            this.parameterTypeService.Setup(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.boolPt, this.cptParameterType
            });

            this.parameterTypeService.Setup(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", new List <Guid> {
                this.existingNotQuantityKindParameterTypeGuid
            }, this.securityContext.Object))
            .Returns(new List <Thing> {
                new BooleanParameterType(this.existingNotQuantityKindParameterTypeGuid, 1)
            });

            this.parameterTypeService.Setup(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", new List <Guid> {
                this.existingQuantityKindParameterTypeGuid
            }, this.securityContext.Object))
            .Returns(new List <Thing> {
                new SimpleQuantityKind(this.existingQuantityKindParameterTypeGuid, 1)
            });

            this.parameterTypeService.Setup(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", new List <Guid> {
                this.notExistingParameterTypeGuid
            }, this.securityContext.Object))
            .Returns(new List <Thing>());

            this.parameterTypeComponentService.Setup(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.cpt1, this.cpt2
            });

            this.parameterOverrideService.Setup(x => x.GetShallow(this.npgsqlTransaction, "partition", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.parameterOverride
            });

            this.elementUsageService.Setup(x => x.GetShallow(this.npgsqlTransaction, "partition", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.elementUsage
            });

            this.scalarDefaultValueArray = new ValueArray <string>(new List <string>()
            {
                "-"
            });
            this.compoundDefaultValueArray = new ValueArray <string>(new List <string>()
            {
                "-", "-"
            });

            this.defaultValueArrayFactory.Setup(x => x.CreateDefaultValueArray(this.cptParameterType.Iid))
            .Returns(this.compoundDefaultValueArray);

            this.defaultValueArrayFactory.Setup(x => x.CreateDefaultValueArray(this.boolPt.Iid))
            .Returns(this.scalarDefaultValueArray);
        }
        public void Setup()
        {
            this.securityContext = new Mock <ISecurityContext>();
            this.optionService   = new Mock <IOptionService>();
            this.actualFiniteStateListService = new Mock <IActualFiniteStateListService>();
            this.valueSetService  = new Mock <IParameterValueSetService>();
            this.iterationService = new Mock <IIterationService>();
            this.parameterOverrideValueSetService     = new Mock <IParameterOverrideValueSetService>();
            this.parameterSubscriptionValueSetService = new Mock <IParameterSubscriptionValueSetService>();
            this.parameterSubscriptionService         = new Mock <IParameterSubscriptionService>();
            this.parameterOverrideService             = new Mock <IParameterOverrideService>();
            this.elementUsageService         = new Mock <IElementUsageService>();
            this.defaultValueArrayFactory    = new Mock <IDefaultValueArrayFactory>();
            this.OldParameterContextProvider = new Mock <IOldParameterContextProvider>();
            this.cachedReferenceDataService  = new Mock <ICachedReferenceDataService>();

            this.organizationalParticipationResolverService = new Mock <IOrganizationalParticipationResolverService>();
            this.organizationalParticipationResolverService.Setup(x => x.ValidateCreateOrganizationalParticipation(It.IsAny <Thing>(), It.IsAny <Thing>(), It.IsAny <ISecurityContext>(), this.npgsqlTransaction, It.IsAny <string>()));

            this.npgsqlTransaction = null;

            this.iteration = new Iteration(Guid.NewGuid(), 1);
            this.option1   = new Option(Guid.NewGuid(), 1);
            this.option2   = new Option(Guid.NewGuid(), 1);

            this.iteration.Option.Add(new OrderedItem {
                K = 1, V = this.option1.Iid
            });
            this.iteration.Option.Add(new OrderedItem {
                K = 2, V = this.option2.Iid
            });

            this.actualList   = new ActualFiniteStateList(Guid.NewGuid(), 1);
            this.actualState1 = new ActualFiniteState(Guid.NewGuid(), 1);
            this.actualState2 = new ActualFiniteState(Guid.NewGuid(), 1);

            this.actualList.ActualState.Add(this.actualState1.Iid);
            this.actualList.ActualState.Add(this.actualState2.Iid);

            this.parameter = new Parameter(Guid.NewGuid(), 1);

            this.cptParameterType = new CompoundParameterType(Guid.NewGuid(), 1);
            this.boolPt           = new BooleanParameterType(Guid.NewGuid(), 1);
            this.cpt1             = new ParameterTypeComponent(Guid.NewGuid(), 1)
            {
                ParameterType = this.boolPt.Iid
            };
            this.cpt2 = new ParameterTypeComponent(Guid.NewGuid(), 1)
            {
                ParameterType = this.boolPt.Iid
            };

            this.cptParameterType.Component.Add(new OrderedItem {
                K = 1, V = this.cpt1.Iid.ToString()
            });
            this.cptParameterType.Component.Add(new OrderedItem {
                K = 2, V = this.cpt2.Iid.ToString()
            });

            this.sideEffect = new ParameterSideEffect
            {
                IterationService                     = this.iterationService.Object,
                ActualFiniteStateListService         = this.actualFiniteStateListService.Object,
                ParameterValueSetService             = this.valueSetService.Object,
                ParameterOverrideValueSetService     = this.parameterOverrideValueSetService.Object,
                ParameterSubscriptionValueSetService = this.parameterSubscriptionValueSetService.Object,
                ParameterOverrideService             = this.parameterOverrideService.Object,
                ParameterSubscriptionService         = this.parameterSubscriptionService.Object,
                ElementUsageService                  = this.elementUsageService.Object,
                OptionService                              = this.optionService.Object,
                DefaultValueArrayFactory                   = this.defaultValueArrayFactory.Object,
                ParameterValueSetFactory                   = new ParameterValueSetFactory(),
                ParameterOverrideValueSetFactory           = new ParameterOverrideValueSetFactory(),
                ParameterSubscriptionValueSetFactory       = new ParameterSubscriptionValueSetFactory(),
                OldParameterContextProvider                = this.OldParameterContextProvider.Object,
                OrganizationalParticipationResolverService = this.organizationalParticipationResolverService.Object,
                CachedReferenceDataService                 = this.cachedReferenceDataService.Object
            };

            // prepare mock data
            this.elementDefinition = new ElementDefinition(Guid.NewGuid(), 1);
            this.elementDefinition.Parameter.Add(this.parameter.Iid);

            this.parameterOverride = new ParameterOverride(Guid.NewGuid(), 1)
            {
                Parameter = this.parameter.Iid
            };

            this.elementUsage = new ElementUsage(Guid.NewGuid(), 1)
            {
                ElementDefinition = this.elementDefinition.Iid, ParameterOverride = { this.parameterOverride.Iid }
            };

            this.iterationService.Setup(x => x.GetActiveIteration(null, "partition", this.securityContext.Object))
            .Returns(this.iteration);

            this.actualFiniteStateListService.Setup(x => x.GetShallow(It.IsAny <NpgsqlTransaction>(), "partition", It.Is <IEnumerable <Guid> >(y => y.Contains(this.actualList.Iid)), this.securityContext.Object))
            .Returns(new List <Thing> {
                this.actualList
            });

            var parameterTypeDictionary = new Dictionary <Guid, ParameterType>();

            parameterTypeDictionary.Add(this.cptParameterType.Iid, this.cptParameterType);
            parameterTypeDictionary.Add(this.boolPt.Iid, this.boolPt);

            this.cachedReferenceDataService.Setup(x => x.QueryParameterTypes(this.npgsqlTransaction, this.securityContext.Object))
            .Returns(parameterTypeDictionary);

            var parameterTypeComponentDictionary = new Dictionary <Guid, ParameterTypeComponent>();

            parameterTypeComponentDictionary.Add(this.cpt1.Iid, this.cpt1);
            parameterTypeComponentDictionary.Add(this.cpt2.Iid, this.cpt2);

            this.cachedReferenceDataService.Setup(x => x.QueryParameterTypeComponents(this.npgsqlTransaction, this.securityContext.Object))
            .Returns(parameterTypeComponentDictionary);

            this.parameterOverrideService.Setup(x => x.GetShallow(this.npgsqlTransaction, "partition", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.parameterOverride
            });

            this.elementUsageService.Setup(x => x.GetShallow(this.npgsqlTransaction, "partition", null, this.securityContext.Object))
            .Returns(new List <Thing> {
                this.elementUsage
            });

            this.scalarDefaultValueArray = new ValueArray <string>(new List <string> {
                "-"
            });
            this.compoundDefaultValueArray = new ValueArray <string>(new List <string> {
                "-", "-"
            });

            this.defaultValueArrayFactory.Setup(x => x.CreateDefaultValueArray(this.cptParameterType.Iid))
            .Returns(this.compoundDefaultValueArray);

            this.defaultValueArrayFactory.Setup(x => x.CreateDefaultValueArray(this.boolPt.Iid))
            .Returns(this.scalarDefaultValueArray);

            this.OldParameterContextProvider.Setup(x => x.GetsourceValueSet(It.IsAny <Guid?>(), It.IsAny <Guid?>())).Returns((ParameterValueSet)null);
        }