public void VerifyThatValidatePocoPropertiesAddsScaleValueDefinitionError() { Assert.DoesNotThrowAsync(async() => await this.session.Object.Open()); var ratioScale = new RatioScale(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri); var scaleValueDefinition = new ScaleValueDefinition(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri); ratioScale.ValueDefinition.Add(scaleValueDefinition); this.siteReferenceDataLibrary.Scale.Add(ratioScale); scaleValueDefinition.ValidatePoco(); this.session.Object.Assembler.Cache.TryAdd(new CacheKey(scaleValueDefinition.Iid, null), new Lazy <Thing>(() => scaleValueDefinition)); this.viewModel.BindPocoErrors(); Assert.That(this.viewModel.Errors.Any(e => e.Error.Contains("The property Name is null or empty"))); Assert.That(this.viewModel.Errors.Any(e => e.Error.Contains("The property ShortName is null or empty"))); Assert.DoesNotThrow(() => this.viewModel.FixCommand.Execute(null)); Assert.AreEqual(0, this.viewModel.Errors.Count(e => e.Error.Contains("The property Name is null or empty"))); Assert.AreEqual(0, this.viewModel.Errors.Count(e => e.Error.Contains("The property ShortName is null or empty"))); Assert.DoesNotThrowAsync(async() => await this.session.Object.Close()); }
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.permissionService = new Mock<IPermissionService>(); this.permissionService.Setup(x => x.CanRead(It.IsAny<Thing>())).Returns(true); this.permissionService.Setup(x => x.CanWrite(It.IsAny<Thing>())).Returns(true); this.session = new Mock<ISession>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); var person = new Person(Guid.NewGuid(), null, null) { Container = this.siteDir }; this.session.Setup(x => x.ActivePerson).Returns(person); var simpleUnit = new SimpleUnit(Guid.NewGuid(), null, null); this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null); this.siteDir.Person.Add(person); var testScale = new LogarithmicScale(); this.rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { Name = "testRDL", ShortName = "test" }; this.rdl.Unit.Add(simpleUnit); this.rdl.Scale.Add(testScale); var svd1 = new ScaleValueDefinition(Guid.NewGuid(), null, null) { Name = "ReferenceSVD", ShortName = "RSVD" }; var svd2 = new ScaleValueDefinition(Guid.NewGuid(), null, null) { Name = "DependentSVD", ShortName = "DSVD" }; this.ratioScale = new RatioScale(Guid.NewGuid(), null, null) { Name = "ratioScale", ShortName = "dqk" }; this.ratioScale.ValueDefinition.Add(svd1); this.ratioScale.ValueDefinition.Add(svd2); this.rdl.ParameterType.Add(new SimpleQuantityKind { Name = "testSQK", ShortName = "tSQK" }); this.siteDir.SiteReferenceDataLibrary.Add(this.rdl); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); this.transaction = new ThingTransaction(transactionContext, null); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet<ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary)); 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 RatioScaleDialogViewModel(this.ratioScale, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object); }
/// <summary> /// Serialize the <see cref="ScaleValueDefinition"/> /// </summary> /// <param name="scaleValueDefinition">The <see cref="ScaleValueDefinition"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(ScaleValueDefinition scaleValueDefinition) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](scaleValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleValueDefinition.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](scaleValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](scaleValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleValueDefinition.Iid)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleValueDefinition.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](scaleValueDefinition.Name)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleValueDefinition.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](scaleValueDefinition.ShortName)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleValueDefinition.ThingPreference)); jsonObject.Add("value", this.PropertySerializerMap["value"](scaleValueDefinition.Value)); return(jsonObject); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.navigation = new Mock <IThingDialogNavigationService>(); this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); this.permissionService = new Mock <IPermissionService>(); this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.session = new Mock <ISession>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); var person = new Person(Guid.NewGuid(), this.cache, null) { Container = this.siteDir }; this.session.Setup(x => x.ActivePerson).Returns(person); this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, null); this.siteDir.Person.Add(person); var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null) { Name = "testRDL", ShortName = "test" }; this.mappingToReferenceScale = new MappingToReferenceScale(Guid.NewGuid(), null, null); this.siteDir.SiteReferenceDataLibrary.Add(rdl); this.testRatioScale = new RatioScale(Guid.NewGuid(), this.cache, null) { Name = "ratioScale", ShortName = "dqk" }; var testRatioScale1 = new RatioScale(Guid.NewGuid(), this.cache, null) { Name = "ratioScale1", ShortName = "dqk1" }; var svd1 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null) { Name = "ReferenceSVD", ShortName = "RSVD" }; var svd2 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null) { Name = "DependentSVD", ShortName = "DSVD" }; this.testRatioScale.ValueDefinition.Add(svd1); testRatioScale1.ValueDefinition.Add(svd2); rdl.Scale.Add(this.testRatioScale); rdl.Scale.Add(testRatioScale1); this.cache.TryAdd(new CacheKey(this.testRatioScale.Iid, null), new Lazy <Thing>(() => this.testRatioScale)); this.clone = this.testRatioScale.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); this.transaction = new ThingTransaction(transactionContext, this.clone); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); 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 MappingToReferenceScaleDialogViewModel(this.mappingToReferenceScale, this.transaction, this.session.Object, false, ThingDialogKind.Create, this.navigation.Object, this.clone); }
/// <summary> /// Add an Value Definition row view model to the list of <see cref="ValueDefinition"/> /// </summary> /// <param name="valueDefinition"> /// The <see cref="ValueDefinition"/> that is to be added /// </param> private ScaleValueDefinitionRowViewModel AddValueDefinitionRowViewModel(ScaleValueDefinition valueDefinition) { return(new ScaleValueDefinitionRowViewModel(valueDefinition, this.Session, this)); }
/// <summary> /// Initializes a new instance of the <see cref="ScaleValueDefinitionDialogViewModel"/> class. /// </summary> /// <param name="scaleValueDefinition"> /// The <see cref="ScaleValueDefinition"/> 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="ScaleValueDefinitionDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="ScaleValueDefinitionDialogViewModel"/> 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 ScaleValueDefinitionDialogViewModel(ScaleValueDefinition scaleValueDefinition, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(scaleValueDefinition, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { }
public void Setup() { this.scaleValueDefinition = new ScaleValueDefinition(Guid.NewGuid(), 0); this.containerMeasurementScale = new OrdinalScale(Guid.NewGuid(), 0) { ValueDefinition = { this.scaleValueDefinition.Iid } }; this.rootMappingToReferenceScale = new MappingToReferenceScale(Guid.NewGuid(), 0) { ReferenceScaleValue = this.scaleValueDefinition.Iid, DependentScaleValue = this.scaleValueDefinition.Iid }; this.rootMeasurementScale = new OrdinalScale(Guid.NewGuid(), 0) { MappingToReferenceScale = { this.rootMappingToReferenceScale.Iid } }; // RDL chain: mrdl -> srdl this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), 0); this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), 0) { Scale = { this.rootMeasurementScale.Iid, this.containerMeasurementScale.Iid, }, RequiredRdl = this.srdl.Iid }; // setup services this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); this.siteReferenceDataLibraryService = new Mock <ISiteReferenceDataLibraryService>(); this.siteReferenceDataLibraryService .Setup(x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), null, It.IsAny <ISecurityContext>())) .Returns(new List <ReferenceDataLibrary> { this.srdl }); this.mappingToReferenceScaleService = new Mock <IMappingToReferenceScaleService>(); this.mappingToReferenceScaleService .Setup(x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), It.IsAny <IEnumerable <Guid> >(), It.IsAny <ISecurityContext>())) .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>( (transaction, partition, iids, context) => { iids = iids.ToList(); return(new List <Thing> { this.rootMappingToReferenceScale }.Where(qk => iids.Contains(qk.Iid))); }); this.scaleValueDefinitionService = new Mock <IScaleValueDefinitionService>(); this.scaleValueDefinitionService .Setup(x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), It.IsAny <IEnumerable <Guid> >(), It.IsAny <ISecurityContext>())) .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>( (transaction, partition, iids, context) => { iids = iids.ToList(); return(new List <Thing> { this.scaleValueDefinition }.Where(qk => iids.Contains(qk.Iid))); }); this.measurementScaleService = new Mock <IMeasurementScaleService>(); this.measurementScaleService .Setup(x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), null, It.IsAny <ISecurityContext>())) .Returns(new List <MeasurementScale> { this.rootMeasurementScale, this.containerMeasurementScale }); this.sideEffect = new MeasurementScaleSideEffect { SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object, MappingToReferenceScaleService = this.mappingToReferenceScaleService.Object, ScaleValueDefinitionService = this.scaleValueDefinitionService.Object, MeasurementScaleService = this.measurementScaleService.Object }; }
/// <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="scaleValueDefinition"> /// The scaleValueDefinition instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, ScaleValueDefinition scaleValueDefinition) { var results = new List <bool>(); foreach (var alias in this.ResolveFromRequestCache(scaleValueDefinition.Alias)) { results.Add(this.AliasService.CreateConcept(transaction, partition, alias, scaleValueDefinition)); } foreach (var definition in this.ResolveFromRequestCache(scaleValueDefinition.Definition)) { results.Add(this.DefinitionService.CreateConcept(transaction, partition, definition, scaleValueDefinition)); } foreach (var hyperLink in this.ResolveFromRequestCache(scaleValueDefinition.HyperLink)) { results.Add(this.HyperLinkService.CreateConcept(transaction, partition, hyperLink, scaleValueDefinition)); } return(results.All(x => x)); }