/// <summary> /// recursively queries the chain of rdls for a provided <see cref="ReferenceDataLibrary"/> and adds the found <see cref="SiteReferenceDataLibrary"/> to the /// resulting <paramref name="siteReferenceDataLibraryUniqueIdentifiers"/> /// </summary> /// <param name="referenceDataLibrary"> /// The <see cref="ReferenceDataLibrary"/> for which the chain-of-rdl is to be computed /// </param> /// <param name="siteReferenceDataLibraryUniqueIdentifiers"> /// A <see cref="HashSet{Guid}"/> to which the /// </param> private void QueryRequiredReferenceDataLibraryChainAndUpdateResult(ReferenceDataLibrary referenceDataLibrary, HashSet <Guid> siteReferenceDataLibraryUniqueIdentifiers) { // the referenceDataLibrary does not have a requiredRdl, no need to continue if (!referenceDataLibrary.RequiredRdl.HasValue) { return; } // the required RDL of the referenceDataLibrary has already been found in a previous iteration, no need to redo it if (siteReferenceDataLibraryUniqueIdentifiers.Contains(referenceDataLibrary.RequiredRdl.Value)) { return; } // iterate through the cached SiteReferenceDataLibrary objects untill we find a matching required RDL. // Add this matched object to the resultset and look for it's required rdl's with a recursive call var siteReferenceDataLibrary = this.cachedSiteReferenceDataLibraries.FirstOrDefault(x => x.Iid == referenceDataLibrary.RequiredRdl); if (siteReferenceDataLibrary != null) { siteReferenceDataLibraryUniqueIdentifiers.Add(siteReferenceDataLibrary.Iid); this.QueryRequiredReferenceDataLibraryChainAndUpdateResult(siteReferenceDataLibrary, siteReferenceDataLibraryUniqueIdentifiers); } }
/// <summary> /// Initializes the dialog /// </summary> protected override void Initialize() { base.Initialize(); this.selectedRdl = this.ChainOfContainer.OfType <ReferenceDataLibrary>().SingleOrDefault(); if (this.selectedRdl == null) { throw new InvalidOperationException("There is no Reference Data Library in the chain of selected container."); } this.WhenAnyValue(vm => vm.SelectedUnit).Where(x => x != null).Subscribe(_ => this.UpdateOkCanExecute()); }
/// <summary> /// Read a <see cref="ReferenceDataLibrary"/> from the underlying <see cref="IDal"/> /// </summary> /// <param name="rdl">The <see cref="ReferenceDataLibrary"/> to read</param> /// <returns> /// an await-able <see cref="Task"/> /// </returns> /// <remarks> /// The Cache is updated with the returned objects and the <see cref="CDPMessageBus"/> is used to send messages to notify listeners of updates to the Cache /// </remarks> public async Task Read(ReferenceDataLibrary rdl) { if (this.ActivePerson == null) { throw new InvalidOperationException("The ReferenceDataLibrary cannot be read when the ActivePerson is null; The Open method must be called prior to any of the Read methods"); } await this.Read((Thing)rdl); this.AddRdlToOpenList(rdl); }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var constant in this.constants) { if (constant.Thing.Container != rdl) { continue; } if (constant.ContainerRdl != rdl.ShortName) { constant.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var measurementUnit in this.measurementUnits) { if (measurementUnit.Thing.Container != rdl) { continue; } if (measurementUnit.ContainerRdl != rdl.ShortName) { measurementUnit.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var filetype in this.FileTypes) { if (filetype.Thing.Container != rdl) { continue; } if (filetype.ContainerRdl != rdl.ShortName) { filetype.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var referenceSource in this.ReferenceSources) { if (referenceSource.Thing.Container != rdl) { continue; } if (referenceSource.ContainerRdl != rdl.ShortName) { referenceSource.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var unitPrefixe in this.UnitPrefixes) { if (unitPrefixe.Thing.Container != rdl) { continue; } if (unitPrefixe.ContainerRdl != rdl.ShortName) { unitPrefixe.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var parameter in this.parameterTypes) { if (parameter.Thing.Container != rdl) { continue; } if (parameter.ContainerRdl != rdl.ShortName) { parameter.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var glossary in this.Glossaries) { if (glossary.Thing.Container != rdl) { continue; } if (glossary.ContainerRdlShortName != rdl.ShortName) { glossary.ContainerRdlShortName = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var categoryRowViewModel in this.Categories) { if (categoryRowViewModel.Thing.Container != rdl) { continue; } if (categoryRowViewModel.ContainerRdl != rdl.ShortName) { categoryRowViewModel.ContainerRdl = rdl.ShortName; } } }
/// <summary> /// Refresh the displayed container name for the category rows /// </summary> /// <param name="rdl"> /// The updated <see cref="ReferenceDataLibrary"/>. /// </param> private void RefreshContainerName(ReferenceDataLibrary rdl) { foreach (var scale in this.measurementScales) { if (scale.Thing.Container != rdl) { continue; } if (scale.ContainerRdl != rdl.ShortName) { scale.ContainerRdl = rdl.ShortName; } } }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain aptA -> ptcA -> aptB -> ptcB -> bptD this.booleanParameterTypeD = new BooleanParameterType { Iid = Guid.NewGuid() }; this.parameterTypeComponentD = new ParameterTypeComponent { Iid = Guid.NewGuid(), ParameterType = this.booleanParameterTypeD.Iid }; this.parameterTypeComponentB = new ParameterTypeComponent { Iid = Guid.NewGuid(), ParameterType = this.booleanParameterTypeD.Iid }; var parameterTypeComponentForB = new OrderedItem { K = 1, V = this.parameterTypeComponentB.Iid }; var parameterTypeComponentsForB = new List <OrderedItem> { parameterTypeComponentForB }; this.arrayParameterTypeB = new ArrayParameterType { Iid = Guid.NewGuid(), Component = parameterTypeComponentsForB }; this.parameterTypeComponentA = new ParameterTypeComponent { Iid = Guid.NewGuid(), ParameterType = this.arrayParameterTypeB.Iid }; var parameterTypeComponentForA = new OrderedItem { K = 1, V = this.parameterTypeComponentA.Iid }; var parameterTypeComponentsForA = new List <OrderedItem> { parameterTypeComponentForA }; this.arrayParameterTypeA = new ArrayParameterType { Iid = Guid.NewGuid(), Component = parameterTypeComponentsForA }; this.parameterTypeComponentC = new ParameterTypeComponent { Iid = Guid.NewGuid(), ParameterType = this.arrayParameterTypeA.Iid }; // There is a chain librayA -> LibraryB this.referenceDataLibraryB = new SiteReferenceDataLibrary { Iid = Guid.NewGuid(), ParameterType = { this.booleanParameterTypeD.Iid } }; this.referenceDataLibraryA = new ModelReferenceDataLibrary { Iid = Guid.NewGuid(), ParameterType = { this.arrayParameterTypeA .Iid, this.arrayParameterTypeB .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.arrayParameterTypeService = new Mock <IArrayParameterTypeService>(); this.arrayParameterTypeService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.booleanParameterTypeD.Iid, this.arrayParameterTypeA.Iid, this.arrayParameterTypeB.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <CompoundParameterType> { this.arrayParameterTypeA, this.arrayParameterTypeB }); this.compoundParameterTypeService = new Mock <ICompoundParameterTypeService>(); this.compoundParameterTypeService.Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.booleanParameterTypeD.Iid, this.arrayParameterTypeA.Iid, this.arrayParameterTypeB.Iid }, It.IsAny <ISecurityContext>())).Returns(new List <ArrayParameterType>()); this.parameterTypeComponentService = new Mock <IParameterTypeComponentService>(); this.parameterTypeComponentService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.parameterTypeComponentA.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <ParameterTypeComponent> { this.parameterTypeComponentA }); this.parameterTypeComponentService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.parameterTypeComponentB.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <ParameterTypeComponent> { this.parameterTypeComponentB }); this.parameterTypeComponentService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.parameterTypeComponentC.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <ParameterTypeComponent> { this.parameterTypeComponentC }); this.parameterTypeComponentService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.parameterTypeComponentD.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <ParameterTypeComponent> { this.parameterTypeComponentD }); this.sideEffect = new ArrayParameterTypeSideEffect() { CompoundParameterTypeService = this.compoundParameterTypeService.Object, ArrayParameterTypeService = this.arrayParameterTypeService.Object, ParameterTypeComponentService = this.parameterTypeComponentService.Object, SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object }; }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain d -> e -> f and e -> g -> c this.categoryA = new Category { Iid = Guid.NewGuid() }; this.categoryB = new Category { Iid = Guid.NewGuid() }; this.categoryC = new Category { Iid = Guid.NewGuid() }; this.categoryG = new Category { Iid = Guid.NewGuid(), SuperCategory = { this.categoryC.Iid } }; this.categoryF = new Category { Iid = Guid.NewGuid() }; this.categoryE = new Category { Iid = Guid.NewGuid(), SuperCategory = { this.categoryF.Iid, this.categoryG.Iid } }; this.categoryD = new Category { Iid = Guid.NewGuid(), SuperCategory = { this.categoryE.Iid } }; // There is a chain librayA -> LibraryB this.referenceDataLibraryB = new SiteReferenceDataLibrary { Iid = Guid.NewGuid(), DefinedCategory = { this.categoryC.Iid, this.categoryD.Iid, this.categoryE.Iid, this.categoryF.Iid, this.categoryG.Iid } }; this.referenceDataLibraryA = new ModelReferenceDataLibrary { Iid = Guid.NewGuid(), DefinedCategory = { this.categoryA.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.categoryService = new Mock <ICategoryService>(); this.categoryService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.categoryC.Iid, this.categoryD.Iid, this.categoryE.Iid, this.categoryF.Iid, this.categoryG.Iid, this.categoryA.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <Category> { this.categoryC, this.categoryD, this.categoryE, this.categoryF, this.categoryG, this.categoryA }); }
/// <summary> /// Checks whether the categories that a <see cref="ICategorizableThing"/> is a member of are in the chain of <see cref="ReferenceDataLibrary"/> /// </summary> /// <param name="categorizableThing"> /// The <see cref="ICategorizableThing"/> whose member <see cref="Category"/> are checked /// </param> /// <param name="referenceDataLibrary"> /// The <see cref="ReferenceDataLibrary"/> that is used as leaf for the chain of <see cref="ReferenceDataLibrary"/> /// </param> /// <param name="rule"> /// The <see cref="IRule"/> that is being checked /// </param> /// <returns> /// an instance of <see cref="RuleCheckResult"/> if a rule is violated, null if no rule is violated. /// </returns> private RuleCheckResult CheckWhetherCategoriesOfCategorizableThingAreInTheChainOfRdls(ICategorizableThing categorizableThing, ReferenceDataLibrary referenceDataLibrary, IRule rule) { var thing = categorizableThing as Thing; var outOfChainOfRdlCategories = new List <Category>(); foreach (var category in categorizableThing.Category) { if (!referenceDataLibrary.IsCategoryInChainOfRdls(category)) { outOfChainOfRdlCategories.Add(category); } } if (outOfChainOfRdlCategories.Any()) { var categoryIdentifiers = string.Join(",", outOfChainOfRdlCategories.Select(r => r.Iid)); var categoryShortNames = string.Join(",", outOfChainOfRdlCategories.Select(r => r.ShortName)); var result = new RuleCheckResult(thing, rule.Id, $"The ICategorizableThing is a member of Categories that are not in the chain of Reference Data Libraries: {categoryIdentifiers}:{categoryShortNames}", SeverityKind.Error); return(result); } return(null); }
/// <summary> /// Close a <see cref="ReferenceDataLibrary"/> by clearing all its contained elements /// </summary> /// <param name="rdl">The <see cref="ReferenceDataLibrary"/> to close</param> /// <returns>The async <see cref="Task"/></returns> public async Task CloseRdl(ReferenceDataLibrary rdl) { await this.threadLock.WaitAsync().ConfigureAwait(false); try { var startwatch = Stopwatch.StartNew(); this.thingsMarkedForDeletion = new List <Thing>(); foreach (var category in rdl.DefinedCategory) { this.RecursivelyMarksForRemoval(category); } foreach (var parameterType in rdl.ParameterType) { this.RecursivelyMarksForRemoval(parameterType); } foreach (var measurementScale in rdl.Scale) { this.RecursivelyMarksForRemoval(measurementScale); } foreach (var unitPrefix in rdl.UnitPrefix) { this.RecursivelyMarksForRemoval(unitPrefix); } foreach (var measurementUnit in rdl.Unit) { this.RecursivelyMarksForRemoval(measurementUnit); } foreach (var filetype in rdl.FileType) { this.RecursivelyMarksForRemoval(filetype); } foreach (var glossary in rdl.Glossary) { this.RecursivelyMarksForRemoval(glossary); } foreach (var referenceSource in rdl.ReferenceSource) { this.RecursivelyMarksForRemoval(referenceSource); } foreach (var rule in rdl.Rule) { this.RecursivelyMarksForRemoval(rule); } foreach (var constant in rdl.Constant) { this.RecursivelyMarksForRemoval(constant); } rdl.DefinedCategory.Clear(); rdl.ParameterType.Clear(); rdl.Scale.Clear(); rdl.UnitPrefix.Clear(); rdl.Unit.Clear(); rdl.FileType.Clear(); rdl.Glossary.Clear(); rdl.ReferenceSource.Clear(); rdl.Rule.Clear(); rdl.Constant.Clear(); rdl.BaseQuantityKind.Clear(); rdl.BaseUnit.Clear(); foreach (var thing in this.thingsMarkedForDeletion) { this.RemoveThingFromCache(thing); } CDPMessageBus.Current.SendObjectChangeEvent(rdl, EventKind.Updated); this.thingsMarkedForDeletion.Clear(); logger.Trace("Finish closing of {0} ({1}) in {2} [ms]", rdl.Name, this.IDalUri, startwatch.ElapsedMilliseconds); } catch (Exception e) { logger.Error(e.Message); } finally { this.threadLock.Release(); } }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain a -> b -> c this.specializedQuantityKindC = new SpecializedQuantityKind { Iid = Guid.NewGuid() }; this.specializedQuantityKindB = new SpecializedQuantityKind { Iid = Guid.NewGuid(), General = this.specializedQuantityKindC.Iid }; this.specializedQuantityKindA = new SpecializedQuantityKind { Iid = Guid.NewGuid(), General = this.specializedQuantityKindB.Iid }; this.specializedQuantityKindD = new SpecializedQuantityKind { Iid = Guid.NewGuid() }; // Outside the rdl chain this.specializedQuantityKindE = new SpecializedQuantityKind { Iid = Guid.NewGuid() }; // There is a chain librayA -> LibraryB this.referenceDataLibraryB = new SiteReferenceDataLibrary { Iid = Guid.NewGuid(), ParameterType = { this.specializedQuantityKindD.Iid } }; this.referenceDataLibraryA = new ModelReferenceDataLibrary { Iid = Guid.NewGuid(), ParameterType = { this.specializedQuantityKindA.Iid, this.specializedQuantityKindB.Iid, this.specializedQuantityKindC.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.specializedQuantityKindService = new Mock <ISpecializedQuantityKindService>(); this.specializedQuantityKindService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.specializedQuantityKindD.Iid, this.specializedQuantityKindA.Iid, this.specializedQuantityKindB.Iid, this.specializedQuantityKindC.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <SpecializedQuantityKind> { this.specializedQuantityKindD, this.specializedQuantityKindA, this.specializedQuantityKindB, this.specializedQuantityKindC }); }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain a -> b -> c this.prefixedUnitC = new PrefixedUnit { Iid = Guid.NewGuid() }; this.prefixedUnitB = new PrefixedUnit { Iid = Guid.NewGuid(), ReferenceUnit = this.prefixedUnitC.Iid }; this.prefixedUnitA = new PrefixedUnit { Iid = Guid.NewGuid(), ReferenceUnit = this.prefixedUnitB.Iid }; this.prefixedUnitD = new PrefixedUnit { Iid = Guid.NewGuid() }; // Outside the rdl chain this.prefixedUnitE = new PrefixedUnit { Iid = Guid.NewGuid() }; // There is a chain librayA -> LibraryB this.referenceDataLibraryB = new SiteReferenceDataLibrary { Iid = Guid.NewGuid(), Unit = { this.prefixedUnitD.Iid } }; this.referenceDataLibraryA = new ModelReferenceDataLibrary { Iid = Guid.NewGuid(), Unit = { this.prefixedUnitA.Iid, this.prefixedUnitB.Iid, this.prefixedUnitC.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.conversionBasedUnitService = new Mock <IConversionBasedUnitService>(); this.conversionBasedUnitService .Setup( x => x.Get( this.npgsqlTransaction, It.IsAny <string>(), new List <Guid> { this.prefixedUnitD.Iid, this.prefixedUnitA.Iid, this.prefixedUnitB.Iid, this.prefixedUnitC.Iid }, It.IsAny <ISecurityContext>())).Returns( new List <ConversionBasedUnit> { this.prefixedUnitD, this.prefixedUnitA, this.prefixedUnitB, this.prefixedUnitC }); }
/// <summary> /// Query the required <see cref="ReferenceDataLibrary"/> for the <paramref name="rdl"/> /// </summary> /// <param name="transaction">The current transaction</param> /// <param name="rdl">The <see cref="ReferenceDataLibrary"/></param> /// <returns>The required <see cref="ReferenceDataLibrary"/></returns> private IReadOnlyList <ReferenceDataLibrary> GetRequiredRdl(NpgsqlTransaction transaction, ReferenceDataLibrary rdl) { var requiredRdls = new List <ReferenceDataLibrary>(); if (!rdl.RequiredRdl.HasValue) { return(requiredRdls); } var requiredRdl = (ReferenceDataLibrary)this.ModelReferenceDataLibraryDao.Read(transaction, typeof(SiteDirectory).Name, new [] { rdl.RequiredRdl.Value }).FirstOrDefault(); if (requiredRdl != null) { requiredRdls.Add(requiredRdl); requiredRdls.AddRange(this.GetRequiredRdl(transaction, requiredRdl)); } else { requiredRdl = this.SiteReferenceDataLibraryDato.Read(transaction, typeof(SiteDirectory).Name, new[] { rdl.RequiredRdl.Value }).FirstOrDefault(); if (requiredRdl != null) { requiredRdls.Add(requiredRdl); } } return(requiredRdls); }
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> /// Query the required <see cref="ReferenceDataLibrary"/> for the <paramref name="rdl"/> /// </summary> /// <param name="transaction">The current transaction</param> /// <param name="rdl">The <see cref="ReferenceDataLibrary"/></param> /// <returns>The required <see cref="ReferenceDataLibrary"/></returns> private IReadOnlyList <ReferenceDataLibrary> GetRequiredRdl(NpgsqlTransaction transaction, ReferenceDataLibrary rdl) { var requiredRdls = new List <ReferenceDataLibrary>(); if (!rdl.RequiredRdl.HasValue) { return(requiredRdls); } var requiredRdl = this.ModelReferenceDataLibraryDao.Read(transaction, nameof(SiteDirectory), new[] { rdl.RequiredRdl.Value }, true).FirstOrDefault() as ReferenceDataLibrary ?? this.SiteReferenceDataLibraryDao.Read(transaction, nameof(SiteDirectory), new[] { rdl.RequiredRdl.Value }, true).FirstOrDefault(); if (requiredRdl != null) { this.TryCopyToRequiredRdls(new[] { requiredRdl }, requiredRdls); this.TryCopyToRequiredRdls(this.GetRequiredRdl(transaction, requiredRdl), requiredRdls); } return(requiredRdls); }