public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.navigation = new Mock <IThingDialogNavigationService>(); this.permissionService = new Mock <IPermissionService>(); this.session = new Mock <ISession>(); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri); this.siteRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri); this.derivedUnit = new DerivedUnit(Guid.NewGuid(), null, this.uri); this.factor = new UnitFactor(Guid.NewGuid(), null, this.uri); this.derivedUnit.UnitFactor.Add(this.factor); this.unit = new SimpleUnit(Guid.NewGuid(), null, this.uri); this.siteRdl.Unit.Add(this.unit); this.factor.Unit = this.unit; this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary)); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); this.transaction = new ThingTransaction(transactionContext, null); 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()); }
public static UnitFactorView Create(UnitFactor obj) { var v = new UnitFactorView(); Copy.Members(obj.Data, v); return(v); }
[TestMethod] public void FactorIsTakenFromDataTest() { var d = GetRandom.Object <UnitFactorData>(); obj = new UnitFactor(d); Assert.AreEqual(obj.Factor, d.Factor); }
[TestMethod] public void CanSetSystemOfUnitsInConstructorTest() { var s = new SystemOfUnits(GetRandom.Object <SystemOfUnitsData>()); var d = GetRandom.Object <UnitFactorData>(); obj = new UnitFactor(d, s); arePropertiesEqual(s.Data, obj.SystemOfUnits.Data); }
public void SetUp() { this.unitFactorRuleChecker = new UnitFactorRuleChecker(); this.siteReferenceDataLibrary = new SiteReferenceDataLibrary(); this.derivedUnit = new DerivedUnit(); this.unitFactor = new UnitFactor(); this.siteReferenceDataLibrary.Unit.Add(this.derivedUnit); this.derivedUnit.UnitFactor.Add(this.unitFactor); }
/// <summary> /// Serialize the <see cref="UnitFactor"/> /// </summary> /// <param name="unitFactor">The <see cref="UnitFactor"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(UnitFactor unitFactor) { var jsonObject = new JObject(); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitFactor.ClassKind))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](unitFactor.Exponent)); jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitFactor.Iid)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitFactor.ModifiedOn)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitFactor.RevisionNumber)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitFactor.ThingPreference)); jsonObject.Add("unit", this.PropertySerializerMap["unit"](unitFactor.Unit)); return(jsonObject); }
public void VerifyIsContainedByIidWorks() { var model = new EngineeringModel(Guid.NewGuid(), null, null); var sitedir = new SiteDirectory(Guid.NewGuid(), null, null); var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null); var unit = new DerivedUnit(Guid.NewGuid(), null, null); var factor = new UnitFactor(Guid.NewGuid(), null, null); sitedir.SiteReferenceDataLibrary.Add(rdl); rdl.Unit.Add(unit); unit.UnitFactor.Add(factor); Assert.IsTrue(factor.IsContainedBy(sitedir.Iid)); Assert.IsTrue(factor.IsContainedBy(rdl.Iid)); Assert.IsTrue(factor.IsContainedBy(unit.Iid)); Assert.IsFalse(factor.IsContainedBy(model.Iid)); Assert.IsFalse(sitedir.IsContainedBy(sitedir.Iid)); Assert.Throws <ArgumentNullException>(() => factor.IsContainedBy(iid: Guid.Empty)); }
/// <summary> /// Initializes a new instance of the <see cref="UnitFactorDialogViewModel"/> class. /// </summary> /// <param name="unitFactor"> /// The <see cref="UnitFactor"/> 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="UnitFactorDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="UnitFactorDialogViewModel"/> 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 UnitFactorDialogViewModel(UnitFactor unitFactor, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(unitFactor, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain duA -> ufA -> duB -> ufB -> suD this.simpleUnitD = new SimpleUnit { Iid = Guid.NewGuid() }; this.unitFactorD = new UnitFactor { Iid = Guid.NewGuid(), Unit = this.simpleUnitD.Iid }; this.unitFactorB = new UnitFactor { Iid = Guid.NewGuid(), Unit = this.simpleUnitD.Iid }; var unitFactorForB = new OrderedItem { K = 1, V = this.unitFactorB.Iid }; var unitFactorsForB = new List <OrderedItem> { unitFactorForB }; this.derivedUnitB = new DerivedUnit { Iid = Guid.NewGuid(), UnitFactor = unitFactorsForB }; this.unitFactorA = new UnitFactor { Iid = Guid.NewGuid(), Unit = this.derivedUnitB.Iid }; var unitFactorForA = new OrderedItem { K = 1, V = this.unitFactorA.Iid }; var unitFactorsForA = new List <OrderedItem> { unitFactorForA }; this.derivedUnitA = new DerivedUnit { Iid = Guid.NewGuid(), UnitFactor = unitFactorsForA }; this.unitFactorC = new UnitFactor { Iid = Guid.NewGuid(), Unit = this.derivedUnitA.Iid }; // There is a chain librayA -> LibraryB this.referenceDataLibraryB = new SiteReferenceDataLibrary { Iid = Guid.NewGuid(), Unit = { this.simpleUnitD.Iid } }; this.referenceDataLibraryA = new ModelReferenceDataLibrary { Iid = Guid.NewGuid(), Unit = { this.derivedUnitA.Iid, this.derivedUnitB.Iid }, RequiredRdl = this.referenceDataLibraryB.Iid }; 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.referenceDataLibraryB }); this.derivedUnitService = new Mock <IDerivedUnitService>(); this.derivedUnitService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.simpleUnitD.Iid, this.derivedUnitA.Iid, this.derivedUnitB.Iid }, It.IsAny <ISecurityContext>())) .Returns(new List <DerivedUnit> { this.derivedUnitA, this.derivedUnitB }); this.unitFactorService = new Mock <IUnitFactorService>(); this.unitFactorService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.unitFactorA.Iid }, It.IsAny <ISecurityContext>())).Returns(new List <UnitFactor> { this.unitFactorA }); this.unitFactorService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.unitFactorB.Iid }, It.IsAny <ISecurityContext>())).Returns(new List <UnitFactor> { this.unitFactorB }); this.unitFactorService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.unitFactorC.Iid }, It.IsAny <ISecurityContext>())).Returns(new List <UnitFactor> { this.unitFactorC }); this.unitFactorService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.unitFactorD.Iid }, It.IsAny <ISecurityContext>())).Returns(new List <UnitFactor> { this.unitFactorD }); }
/// <summary> /// Add an Unit Factor row view model to the list of <see cref="UnitFactor"/> /// </summary> /// <param name="unitFactor"> /// The <see cref="UnitFactor"/> that is to be added /// </param> private UnitFactorRowViewModel AddUnitFactorRowViewModel(UnitFactor unitFactor) { return(new UnitFactorRowViewModel(unitFactor, this.Session, this)); }