Beispiel #1
0
        public void VerifyThatPropertiesArePopulated()
        {
            var referencer = new ReferencerRule
            {
                Name          = "name",
                ShortName     = "shortname",
                MinReferenced = 1,
                MaxReferenced = 2
            };

            var vm = new ReferencerRuleDialogViewModel(referencer, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogService.Object);

            Assert.AreEqual(referencer.Name, vm.Name);
            Assert.AreEqual(referencer.ShortName, vm.ShortName);
            Assert.AreEqual(referencer.MinReferenced, vm.MinReferenced);
            Assert.AreEqual(referencer.MaxReferenced, vm.MaxReferenced);

            Assert.AreEqual(1, vm.PossibleContainer.Count);
            vm.Container = vm.PossibleContainer.Single();
            Assert.AreEqual(1, vm.PossibleReferencedCategory.Count);
            Assert.AreEqual(1, vm.PossibleReferencingCategory.Count);

            Assert.IsFalse(vm.OkCommand.CanExecute(null));
            vm.SelectedReferencingCategory = vm.PossibleReferencingCategory.First();
            vm.ReferencedCategory          = new ReactiveList <Category>(vm.PossibleReferencedCategory);

            Assert.IsTrue(vm.OkCommand.CanExecute(null));
        }
Beispiel #2
0
        public void VerifyUpdateOkCanExecute()
        {
            var referencer = new ReferencerRule
            {
                Name          = "name",
                ShortName     = "shortname",
                MinReferenced = 1,
                MaxReferenced = 2
            };

            var vm = new ReferencerRuleDialogViewModel(referencer, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogService.Object);

            Assert.IsFalse(vm.OkCommand.CanExecute(null));
            vm.SelectedReferencingCategory = vm.PossibleReferencingCategory.First();
            Assert.IsFalse(vm.OkCommand.CanExecute(null));
            vm.ReferencedCategory = new ReactiveList <Category>(vm.PossibleReferencedCategory);
            Assert.IsTrue(vm.OkCommand.CanExecute(null));

            vm.MinReferenced = 3;
            Assert.IsFalse(vm.OkCommand.CanExecute(null));
            vm.MinReferenced = 2;
            Assert.IsFalse(vm.OkCommand.CanExecute(null));
            var cat2 = new Category(Guid.NewGuid(), null, null)
            {
                Name = "category2", ShortName = "cat2"
            };

            vm.ReferencedCategory.Add(cat2);
            Assert.IsTrue(vm.OkCommand.CanExecute(null));
        }
        public void SetUp()
        {
            this.referencerRuleRuleChecker = new ReferencerRuleRuleChecker();

            this.siteReferenceDataLibrary = new SiteReferenceDataLibrary();
            this.referencerRule           = new ReferencerRule {
                Iid = Guid.Parse("85c00539-410b-4208-8ee5-b9ee41f358db"), ShortName = "RULE"
            };
            this.siteReferenceDataLibrary.Rule.Add(this.referencerRule);
        }
Beispiel #4
0
        public void VerifyThatInspectCommandsOpenDialogs()
        {
            var referencer = new ReferencerRule
            {
                Name      = "name",
                ShortName = "shortname"
            };

            var vm = new ReferencerRuleDialogViewModel(referencer, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogService.Object);

            Assert.IsTrue(vm.InspectSelectedReferencingCategoryCommand.CanExecute(null));
            vm.InspectSelectedReferencingCategoryCommand.Execute(null);
            this.thingDialogService.Verify(x => x.Navigate(It.IsAny <Category>(), It.IsAny <ThingTransaction>(), this.session.Object, false, ThingDialogKind.Inspect, this.thingDialogService.Object, It.IsAny <Thing>(), null));

            vm.SelectedReferencingCategory = null;
            Assert.IsFalse(vm.InspectSelectedReferencingCategoryCommand.CanExecute(null));
        }
        /// <summary>
        /// Serialize the <see cref="ReferencerRule"/>
        /// </summary>
        /// <param name="referencerRule">The <see cref="ReferencerRule"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(ReferencerRule referencerRule)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](referencerRule.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referencerRule.ClassKind)));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](referencerRule.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referencerRule.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referencerRule.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referencerRule.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](referencerRule.Iid));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referencerRule.IsDeprecated));
            jsonObject.Add("maxReferenced", this.PropertySerializerMap["maxReferenced"](referencerRule.MaxReferenced));
            jsonObject.Add("minReferenced", this.PropertySerializerMap["minReferenced"](referencerRule.MinReferenced));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referencerRule.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](referencerRule.Name));
            jsonObject.Add("referencedCategory", this.PropertySerializerMap["referencedCategory"](referencerRule.ReferencedCategory.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("referencingCategory", this.PropertySerializerMap["referencingCategory"](referencerRule.ReferencingCategory));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referencerRule.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referencerRule.ShortName));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referencerRule.ThingPreference));
            return(jsonObject);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferencerRuleDialogViewModel"/> class.
 /// </summary>
 /// <param name="referencerRule">
 /// The <see cref="CDP4Common.SiteDirectoryData.ReferencerRule"/> 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="CDP4Common.CommonData.Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="ReferencerRuleDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="ReferencerRuleDialogViewModel"/> 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 Container <see cref="CDP4Common.CommonData.Thing"/> of the created <see cref="CDP4Common.SiteDirectoryData.ReferencerRule"/>
 /// </param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 public ReferencerRuleDialogViewModel(ReferencerRule referencerRule, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(referencerRule, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }
        public void VerifyThatTheVerifyMethodThrowsNotSupportedException()
        {
            var rule = new ReferencerRule(Guid.NewGuid(), this.cache, this.uri);

            Assert.Throws <NotSupportedException>(() => rule.Verify(this.iteration));
        }
        /// <summary>
        /// Persist the <see cref="ReferencerRule"/> containment tree to the ORM layer. Update if it already exists.
        /// This is typically used during the import of existing data to the Database.
        /// </summary>
        /// <param name="transaction">
        /// The current <see cref="NpgsqlTransaction"/> to the database.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="referencerRule">
        /// The <see cref="ReferencerRule"/> instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool UpsertContainment(NpgsqlTransaction transaction, string partition, ReferencerRule referencerRule)
        {
            var results = new List <bool>();

            foreach (var alias in this.ResolveFromRequestCache(referencerRule.Alias))
            {
                results.Add(this.AliasService.UpsertConcept(transaction, partition, alias, referencerRule));
            }

            foreach (var definition in this.ResolveFromRequestCache(referencerRule.Definition))
            {
                results.Add(this.DefinitionService.UpsertConcept(transaction, partition, definition, referencerRule));
            }

            foreach (var hyperLink in this.ResolveFromRequestCache(referencerRule.HyperLink))
            {
                results.Add(this.HyperLinkService.UpsertConcept(transaction, partition, hyperLink, referencerRule));
            }

            return(results.All(x => x));
        }