public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); this.navigation = new Mock <IThingDialogNavigationService>(); 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 testScale = new LogarithmicScale(); this.rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null) { Name = "testRDL", ShortName = "test" }; this.rdl.Scale.Add(testScale); var qkf = new QuantityKindFactor(); this.derivedQuantityKind = new DerivedQuantityKind { Name = "derivedQuantityKind", ShortName = "dqk" }; this.derivedQuantityKind.QuantityKindFactor.Add(qkf); this.rdl.ParameterType.Add(new SimpleQuantityKind { Name = "testSQK", ShortName = "tSQK" }); this.siteDir.SiteReferenceDataLibrary.Add(this.rdl); this.cache.TryAdd(new CacheKey(this.rdl.Iid, null), new Lazy <Thing>(() => 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 DerivedQuantityKindDialogViewModel(this.derivedQuantityKind, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object, null); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); 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.session = new Mock <ISession>(); 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.quantityKindFactor = new QuantityKindFactor(); var testDerivedQuantityKind = new DerivedQuantityKind(Guid.NewGuid(), this.cache, null) { Name = "Test Derived QK", ShortName = "tdqk" }; var simpleQuantityKind = new SimpleQuantityKind(); rdl.ParameterType.Add(simpleQuantityKind); rdl.ParameterType.Add(testDerivedQuantityKind); this.siteDir.SiteReferenceDataLibrary.Add(rdl); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); var chainOfContainers = new[] { rdl }; this.cache.TryAdd(new CacheKey(testDerivedQuantityKind.Iid, null), new Lazy <Thing>(() => testDerivedQuantityKind)); var clone = testDerivedQuantityKind.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); 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 QuantityKindFactorDialogViewModel(this.quantityKindFactor, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, chainOfContainers); }
/// <summary> /// Serialize the <see cref="QuantityKindFactor"/> /// </summary> /// <param name="quantityKindFactor">The <see cref="QuantityKindFactor"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(QuantityKindFactor quantityKindFactor) { var jsonObject = new JObject(); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), quantityKindFactor.ClassKind))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](quantityKindFactor.Exponent)); jsonObject.Add("iid", this.PropertySerializerMap["iid"](quantityKindFactor.Iid)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](quantityKindFactor.ModifiedOn)); jsonObject.Add("quantityKind", this.PropertySerializerMap["quantityKind"](quantityKindFactor.QuantityKind)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](quantityKindFactor.RevisionNumber)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](quantityKindFactor.ThingPreference)); return(jsonObject); }
public void Setup() { // QuantityKind tree: rootQk -> specializedQk -> derivedQk -> simpleQk this.simpleQk = new SimpleQuantityKind(Guid.NewGuid(), 0); this.derivedQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0) { QuantityKind = this.simpleQk.Iid }; this.derivedQk = new DerivedQuantityKind(Guid.NewGuid(), 0) { QuantityKindFactor = { new OrderedItem { K = 1, V = this.derivedQkFactor.Iid.ToString() } } }; this.specializedQk = new SpecializedQuantityKind(Guid.NewGuid(), 0) { General = this.derivedQk.Iid }; this.rootQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0) { QuantityKind = this.specializedQk.Iid }; this.rootQk = new DerivedQuantityKind(Guid.NewGuid(), 0) { QuantityKindFactor = { new OrderedItem { K = 1, V = this.rootQkFactor.Iid.ToString() } } }; // cyclic factor this.derivedQkCyclicFactor = new QuantityKindFactor(Guid.NewGuid(), 0) { QuantityKind = this.rootQk.Iid }; // outside RDL factor this.outsideRdlQk = new SimpleQuantityKind(Guid.NewGuid(), 0); this.derivedQkOutsideRdlFactor = new QuantityKindFactor(Guid.NewGuid(), 0) { QuantityKind = this.outsideRdlQk.Iid }; // RDL chain: mrdl -> srdl this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), 0) { ParameterType = { this.simpleQk.Iid } }; this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), 0) { ParameterType = { this.derivedQk.Iid, this.specializedQk.Iid, this.rootQk.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.quantityKindFactorService = new Mock <IQuantityKindFactorService>(); this.quantityKindFactorService .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.derivedQkFactor, this.rootQkFactor, this.derivedQkCyclicFactor, this.derivedQkOutsideRdlFactor }.Where(qkf => iids.Contains(qkf.Iid))); }); this.quantityKindService = new Mock <IQuantityKindService>(); this.quantityKindService .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.simpleQk, this.derivedQk, this.specializedQk, this.rootQk, this.outsideRdlQk }.Where(qk => iids.Contains(qk.Iid))); }); this.sideEffect = new DerivedQuantityKindSideEffect { SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object, QuantityKindFactorService = this.quantityKindFactorService.Object, QuantityKindService = this.quantityKindService.Object }; }
/// <summary> /// Add an Quantity Kind Factor row view model to the list of <see cref="QuantityKindFactor"/> /// </summary> /// <param name="quantityKindFactor"> /// The <see cref="QuantityKindFactor"/> that is to be added /// </param> private QuantityKindFactorRowViewModel AddQuantityKindFactorRowViewModel(QuantityKindFactor quantityKindFactor) { return(new QuantityKindFactorRowViewModel(quantityKindFactor, this.Session, this)); }
/// <summary> /// Initializes a new instance of the <see cref="QuantityKindFactorDialogViewModel"/> class. /// </summary> /// <param name="quantityKindFactor"> /// The <see cref="QuantityKindFactor"/> 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="QuantityKindFactorDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="QuantityKindFactorDialogViewModel"/> 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 QuantityKindFactorDialogViewModel(QuantityKindFactor quantityKindFactor, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(quantityKindFactor, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { }