示例#1
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();
            this.navigation           = new Mock <IThingDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object);
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.session       = new Mock <ISession>();
            this.testEM        = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.testIteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            testEM.Iteration.Add(testIteration);
            this.testED         = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            this.parameterGroup = new ParameterGroup()
            {
                Name = "1"
            };
            testIteration.Element.Add(this.testED);

            this.cache.TryAdd(new CacheKey(this.testED.Iid, testIteration.Iid), new Lazy <Thing>(() => this.testED));
            var clone = this.testED.Clone(false);

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

            this.transaction = new ThingTransaction(transactionContext, clone);

            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());

            this.viewmodel = new ParameterGroupDialogViewModel(this.parameterGroup, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);
        }
        public void VerifyThatParameterlessContructorExists()
        {
            var dialogViewModel = new ParameterGroupDialogViewModel();

            Assert.IsFalse(dialogViewModel.IsReadOnly);
        }
        public void VerifyThatParameterGroupsAreAcyclic()
        {
            var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "ElemDef", ShortName = "ED"
            };

            this.testIteration.Element.Add(elementDefinition);
            var pg1 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "1"
            };

            elementDefinition.ParameterGroup.Add(pg1);
            var pg2 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "2", ContainingGroup = pg1
            };

            elementDefinition.ParameterGroup.Add(pg2);
            var pg3 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "3", ContainingGroup = pg2
            };

            elementDefinition.ParameterGroup.Add(pg3);
            var pg4 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "4", ContainingGroup = pg3
            };

            elementDefinition.ParameterGroup.Add(pg4);
            var pg5 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "5"
            };

            elementDefinition.ParameterGroup.Add(pg5);
            var pg6 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "6", ContainingGroup = pg5
            };

            elementDefinition.ParameterGroup.Add(pg6);
            this.cache.TryAdd(new CacheKey(elementDefinition.Iid, this.testIteration.Iid), new Lazy <Thing>(() => elementDefinition));

            var clone = elementDefinition.Clone(false);

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

            this.transaction = new ThingTransaction(transactionContext, clone);

            var vm1 = new ParameterGroupDialogViewModel(pg1, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(2, vm1.PossibleGroups.Count);

            var vm2 = new ParameterGroupDialogViewModel(pg2, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(3, vm2.PossibleGroups.Count);

            var vm3 = new ParameterGroupDialogViewModel(pg3, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(4, vm3.PossibleGroups.Count);
        }