public void VerifyThatDialogResultIsReturnedWhenOk() { var submitmessage = "this is the submitmessage"; var processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); var valueSetValue = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); processedValueSet.UpdateClone(valueSetValue); var processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); processedValueSets.Add(processedValueSet.OriginalThing.Iid, processedValueSet); var viewmodel = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All); viewmodel.SubmitMessage = submitmessage; var row = viewmodel.ParameterOrOverrideWorkbookRebuildRowViewModels.Single(); Assert.IsTrue(row.IsSelected); Assert.IsTrue(viewmodel.OkCommand.CanExecute(null)); viewmodel.OkCommand.Execute(null); var result = (SubmitConfirmationDialogResult)viewmodel.DialogResult; Assert.IsTrue(result.Result.Value); Assert.AreEqual(submitmessage, result.SubmitMessage); Assert.IsNotEmpty(result.Clones); }
public void VerifyThatPropertiesAreSetByConstructor() { var processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); Assert.AreEqual(this.parameterValueSet, processedValueSet.OriginalThing); Assert.AreEqual(ValidationResultKind.Valid, processedValueSet.ValidationResult); Assert.IsNull(processedValueSet.ClonedThing); }
public void VerifyThatIsDirtyMethodsThrowExceptionWhenUpdateCloneHasNotBeenCalled() { ProcessedValueSet processedValueSet; processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); Assert.Throws <InvalidOperationException>(() => processedValueSet.IsManualValueDirty(0)); Assert.Throws <InvalidOperationException>(() => processedValueSet.IsComputedValueDirty(0)); Assert.Throws <InvalidOperationException>(() => processedValueSet.IsReferenceValueDirty(0)); Assert.Throws <InvalidOperationException>(() => processedValueSet.IsFormulaValueDirty(0)); Assert.Throws <InvalidOperationException>(() => processedValueSet.IsValueSwitchDirty()); }
public void VerifyThatIsDirtyReturnsExpectedResultForParameterSubscriptionValueSet() { ValueSetValues valueSetValues; var processedValueSet = new ProcessedValueSet(this.parameterSubscriptionValueSet, ValidationResultKind.Valid); var isDirty = processedValueSet.IsDirty(0, this.parameterType, ParameterSwitchKind.COMPUTED, "1", "1", "1", "1", out valueSetValues); Assert.IsTrue(isDirty); isDirty = processedValueSet.IsDirty(0, this.parameterType, ParameterSwitchKind.MANUAL, "-", "-", "-", "-", out valueSetValues); Assert.IsFalse(isDirty); }
public void VerifyThatCheckAllWorks() { var processedValueSet1 = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); var parameterValueSet2 = new ParameterValueSet(Guid.NewGuid(), null, null) { Manual = new ValueArray <string>(new List <string>() { "1" }), Computed = new ValueArray <string>(new List <string>() { "2" }), Reference = new ValueArray <string>(new List <string>() { "3" }), Formula = new ValueArray <string>(new List <string>() { "-" }), ValueSwitch = ParameterSwitchKind.MANUAL }; var parameter2 = new Parameter(Guid.NewGuid(), null, null) { ParameterType = this.parameterType }; this.elementDefinition.Parameter.Add(parameter2); parameter2.ValueSet.Add(parameterValueSet2); var processedValueSet2 = new ProcessedValueSet(parameterValueSet2, ValidationResultKind.Valid); var valueSetValue1 = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); processedValueSet1.UpdateClone(valueSetValue1); processedValueSet2.UpdateClone(valueSetValue1); var processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); processedValueSets.Add(processedValueSet1.OriginalThing.Iid, processedValueSet1); processedValueSets.Add(processedValueSet2.OriginalThing.Iid, processedValueSet2); var vm = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All); var rows = vm.ParameterOrOverrideWorkbookRebuildRowViewModels; Assert.AreEqual(2, rows.Count); Assert.IsTrue(rows.All(r => r.IsSelected)); }
public void VerifyThatRowsAreCreated() { var processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); var valueSetValue = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); processedValueSet.UpdateClone(valueSetValue); var processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); processedValueSets.Add(processedValueSet.OriginalThing.Iid, processedValueSet); var viewmodel = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All); Assert.AreEqual(1, viewmodel.ParameterOrOverrideWorkbookRebuildRowViewModels.Count); }
/// <summary> /// Process the <see cref="ParameterValueSet"/> . /// </summary> /// <param name="parameterValueSet"> /// The <see cref="ParameterValueSetBase"/> to be processed. /// </param> /// <param name="parameterOrOverrideBase"> /// The <see cref="ParameterOrOverrideBase"/> the <see cref="ParameterValueSetBase"/ belongs to. /// </param> /// <param name="componentIndex"> /// The index of the <see cref="ParameterTypeComponent"/>. /// </param> /// <param name="computedValue"> /// The manual value of the <see cref="ParameterValueSet"/>. /// </param> /// <param name="processedValueSets"> /// A <see cref="Dictionary{Guid,ProcessedValueSet}"/> of ProcessedValueSe that capture the updated <see cref="Thing"/>s with its value validation result /// </param> /// <param name="provider"> /// The <see cref="IFormatProvider"/> used to validate. /// </param> /// <param name="validationErrorText"> /// <see cref="String"/> that holds the validation error text. /// </param> /// <returns> /// The added or changed <see cref="ProcessedValueSet"/> /// </returns> private ProcessedValueSet ProcessValueSet(ParameterValueSetBase parameterValueSet, ParameterOrOverrideBase parameterOrOverrideBase, int componentIndex, string computedValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, IFormatProvider provider, out string validationErrorText) { var validationResult = ValidationResultKind.InConclusive; var switchKind = parameterValueSet.ValueSwitch; var measurementScale = parameterOrOverrideBase.Scale; var parameterType = parameterOrOverrideBase.ParameterType; validationErrorText = string.Empty; if (parameterType != null) { if (ValueSetConverter.TryParseDouble(computedValue, parameterType, out var convertedComputedValue)) { computedValue = convertedComputedValue.ToString(CultureInfo.InvariantCulture); } computedValue = computedValue?.ToValueSetObject(parameterType).ToValueSetString(parameterType) ?? parameterValueSet.Computed[componentIndex]; var validManualValue = parameterType.Validate(computedValue, measurementScale, provider); if (validManualValue.ResultKind > validationResult) { validationResult = validManualValue.ResultKind; validationErrorText = validManualValue.Message; } } var valueSetExists = processedValueSets.TryGetValue(parameterValueSet.Iid, out var processedValueSet); if (!valueSetExists) { processedValueSet = new ProcessedValueSet(parameterValueSet, validationResult); } if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, parameterValueSet.Manual[componentIndex], computedValue, parameterValueSet.Reference[componentIndex], computedValue, out var valueSetValues)) { processedValueSet.UpdateClone(valueSetValues); if (!valueSetExists) { processedValueSets.Add(parameterValueSet.Iid, processedValueSet); } } return(processedValueSet); }
public void VerifyThatDialogResultIsReturnedWhenCancelled() { var processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); var valueSetValue = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); processedValueSet.UpdateClone(valueSetValue); var processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); processedValueSets.Add(processedValueSet.OriginalThing.Iid, processedValueSet); var viewmodel = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All); viewmodel.CancelCommand.Execute(null); var result = (BaseDialogResult)viewmodel.DialogResult; Assert.IsFalse(result.Result.Value); }
/// <summary> /// Process the <see cref="ParameterValueSet"/> . /// </summary> /// <param name="parameterSubscriptionValueSet"> /// The <see cref="ParameterSubscriptionValueSet"/> to be processed. /// </param> /// <param name="parameterSubscription"> /// The <see cref="ParameterSubscription"/> the <see cref="ParameterSubscriptionValueSet"/ belongs to. /// </param> /// <param name="componentIndex"> /// The index of the <see cref="ParameterTypeComponent"/>. /// </param> /// <param name="computedValue"> /// The manual value of the <see cref="ParameterValueSet"/>. /// </param> /// <param name="processedValueSets"> /// A <see cref="Dictionary{Guid,ProcessedValueSet}"/> of ProcessedValueSe that capture the updated <see cref="Thing"/>s with its value validation result /// </param> /// <param name="provider"> /// The <see cref="IFormatProvider"/> used to validate. /// </param> /// <param name="validationErrorText"> /// <see cref="String"/> that holds the validation error text. /// </param> /// <returns> /// The added or changed <see cref="ProcessedValueSet"/> /// </returns> private ProcessedValueSet ProcessValueSet(ParameterSubscriptionValueSet parameterSubscriptionValueSet, ParameterSubscription parameterSubscription, int componentIndex, string computedValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, IFormatProvider provider, out string validationErrorText) { var validationResult = ValidationResultKind.InConclusive; var switchKind = parameterSubscriptionValueSet.ValueSwitch; var measurementScale = parameterSubscription.Scale; var parameterType = parameterSubscription.ParameterType; validationErrorText = string.Empty; if (parameterType != null) { computedValue = computedValue.ToValueSetObject(parameterType).ToValueSetString(parameterType); var validManualValue = parameterType.Validate(computedValue, measurementScale, provider); if (validManualValue.ResultKind > validationResult) { validationResult = validManualValue.ResultKind; validationErrorText = validManualValue.Message; } } var valueSetExists = processedValueSets.TryGetValue(parameterSubscriptionValueSet.Iid, out var processedValueSet); if (!valueSetExists) { processedValueSet = new ProcessedValueSet(parameterSubscriptionValueSet, validationResult); } if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, computedValue, null, null, null, out var valueSetValues)) { processedValueSet.UpdateClone(valueSetValues); if (!valueSetExists) { processedValueSets.Add(parameterSubscriptionValueSet.Iid, processedValueSet); } } return(processedValueSet); }
public void VerifyUpdateParameterSubscriptionValueset() { var processedValueSet = new ProcessedValueSet(this.parameterSubscriptionValueSet, ValidationResultKind.Valid); processedValueSet.UpdateClone(this.valueSetValues); Assert.IsNotNull(processedValueSet.ClonedThing); Assert.IsTrue(processedValueSet.IsManualValueDirty(0)); Assert.IsFalse(processedValueSet.IsComputedValueDirty(0)); Assert.IsFalse(processedValueSet.IsReferenceValueDirty(0)); Assert.IsFalse(processedValueSet.IsFormulaValueDirty(0)); Assert.IsTrue(processedValueSet.IsValueSwitchDirty()); this.valueSetValues = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.MANUAL, "-", "-", "-", "-"); processedValueSet.UpdateClone(this.valueSetValues); Assert.IsFalse(processedValueSet.IsManualValueDirty(0)); Assert.IsFalse(processedValueSet.IsComputedValueDirty(0)); Assert.IsFalse(processedValueSet.IsReferenceValueDirty(0)); Assert.IsFalse(processedValueSet.IsFormulaValueDirty(0)); Assert.IsFalse(processedValueSet.IsValueSwitchDirty()); }
public void VerifyThatAtLeastOneRowHasToBeSelectedBeforeOkCanExecute() { var processedValueSet = new ProcessedValueSet(this.parameterValueSet, ValidationResultKind.Valid); var valueSetValue = new ValueSetValues(0, this.parameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); processedValueSet.UpdateClone(valueSetValue); var processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); processedValueSets.Add(processedValueSet.OriginalThing.Iid, processedValueSet); var viewmodel = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All); var row = viewmodel.ParameterOrOverrideWorkbookRebuildRowViewModels.Single(); Assert.IsTrue(row.IsSelected); Assert.IsTrue(viewmodel.OkCommand.CanExecute(null)); row.IsSelected = false; Assert.IsFalse(viewmodel.OkCommand.CanExecute(null)); }
public void SetUp() { this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); this.uri = new Uri("http://www.rheagroup.com"); this.textParameterType = new TextParameterType(Guid.NewGuid(), this.cache, this.uri); this.textParameterType.Name = "text"; this.textParameterType.ShortName = "TXT"; var satellite = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); satellite.ShortName = "Sat"; satellite.Name = "Satellite"; var battery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); battery.ShortName = "Bat"; battery.Name = "Battery"; var elementUsage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri); elementUsage.ElementDefinition = battery; satellite.ContainedElement.Add(elementUsage); this.parameter = new Parameter(Guid.NewGuid(), this.cache, this.uri); this.parameter.ParameterType = this.textParameterType; satellite.Parameter.Add(this.parameter); this.parameterOverride = new ParameterOverride(Guid.NewGuid(), this.cache, this.uri); this.parameterOverride.Parameter = this.parameter; var parameterValueSet = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri); parameterValueSet.Manual = new ValueArray <string>(new List <string> { "1" }); parameterValueSet.Reference = new ValueArray <string>(new List <string> { "2" }); parameterValueSet.Computed = new ValueArray <string>(new List <string> { "3" }); parameterValueSet.Formula = new ValueArray <string>(new List <string> { "-" }); parameterValueSet.Published = new ValueArray <string>(new List <string> { "-" }); parameterValueSet.ValueSwitch = ParameterSwitchKind.MANUAL; this.parameter.ValueSet.Add(parameterValueSet); var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), this.cache, this.uri); parameterOverrideValueSet.Manual = new ValueArray <string>(new List <string> { "1.1" }); parameterOverrideValueSet.Reference = new ValueArray <string>(new List <string> { "2.1" }); parameterOverrideValueSet.Computed = new ValueArray <string>(new List <string> { "3.1" }); parameterOverrideValueSet.Formula = new ValueArray <string>(new List <string> { "-" }); parameterOverrideValueSet.Published = new ValueArray <string>(new List <string> { "-" }); parameterOverrideValueSet.ValueSwitch = ParameterSwitchKind.MANUAL; this.parameterOverride.ValueSet.Add(parameterOverrideValueSet); parameterOverrideValueSet.ParameterValueSet = parameterValueSet; elementUsage.ParameterOverride.Add(this.parameterOverride); var parameterSubscribtionValueSet = new ParameterSubscriptionValueSet(Guid.NewGuid(), this.cache, this.uri); parameterSubscribtionValueSet.Manual = new ValueArray <string>(new List <string> { "1.2" }); parameterSubscribtionValueSet.ValueSwitch = ParameterSwitchKind.MANUAL; parameterSubscribtionValueSet.SubscribedValueSet = parameterValueSet; var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri); this.parameter.ParameterSubscription.Add(parameterSubscription); parameterSubscription.ValueSet.Add(parameterSubscribtionValueSet); this.processedValueSets = new Dictionary <Guid, ProcessedValueSet>(); var valueSetValue = new ValueSetValues(0, this.textParameterType, ParameterSwitchKind.COMPUTED, "a gazilion", "a gazilion", "a gazilion", "a gazilion"); var parameterValueSetProcessedValueSet = new ProcessedValueSet(parameterValueSet, ValidationResultKind.Valid); parameterValueSetProcessedValueSet.UpdateClone(valueSetValue); var parameterOverrideValueSetProcessedValueSet = new ProcessedValueSet(parameterOverrideValueSet, ValidationResultKind.Valid); parameterOverrideValueSetProcessedValueSet.UpdateClone(valueSetValue); var parameterSubscribtionValueSetProcessedValueSet = new ProcessedValueSet(parameterSubscribtionValueSet, ValidationResultKind.Valid); parameterSubscribtionValueSetProcessedValueSet.UpdateClone(valueSetValue); this.processedValueSets.Add(parameterValueSetProcessedValueSet.OriginalThing.Iid, parameterValueSetProcessedValueSet); this.processedValueSets.Add(parameterOverrideValueSetProcessedValueSet.OriginalThing.Iid, parameterOverrideValueSetProcessedValueSet); this.processedValueSets.Add(parameterSubscribtionValueSetProcessedValueSet.OriginalThing.Iid, parameterSubscribtionValueSetProcessedValueSet); }
/// <summary> /// Process the <see cref="ParameterSubscriptionValueSet"/> . /// </summary> /// <param name="parameterSubscriptionValueSet"> /// The <see cref="ParameterSubscriptionValueSet"/> to be processed. /// </param> /// <param name="componentIndex"> /// The index of the <see cref="ParameterTypeComponent"/>. /// </param> /// <param name="currentRow"> /// The row in the Parameter sheet that contains the <see cref="ParameterValueSet"/>. /// </param> /// <param name="manualValue"> /// The manual value of the <see cref="ParameterValueSet"/>. /// </param> /// <param name="switchValue"> /// The string value of the <see cref="ParameterSwitchKind"/> of the <see cref="ParameterSubscriptionValueSet"/> /// </param> /// <param name="valuesets"> /// A <see cref="Dictionary{Guid,ProcessedValueSet}"/> of <see cref="ProcessedValueSet"/>s that capture the updated <see cref="Thing"/>s with its value validation result /// </param> /// <param name="provider"> /// The <see cref="IFormatProvider"/> used to validate. /// </param> /// <returns> /// The <see cref="ValidationResultKind"/> for the <see cref="ParameterSubscriptionValueSet"/> /// </returns> private void ProcessValueSet(ParameterSubscriptionValueSet parameterSubscriptionValueSet, int componentIndex, int currentRow, object manualValue, string switchValue, ref Dictionary <Guid, ProcessedValueSet> valuesets, IFormatProvider provider) { var validationResult = ValidationResultKind.InConclusive; var switchKind = ParameterSwitchKind.MANUAL; ParameterType parameterType = null; MeasurementScale measurementScale = null; ParameterSheetUtilities.QueryParameterTypeAndScale(parameterSubscriptionValueSet, componentIndex, out parameterType, out measurementScale); ValidationResult validSwitch; var isValidSwitchKind = Enum.IsDefined(typeof(ParameterSwitchKind), switchValue); if (isValidSwitchKind) { switchKind = (ParameterSwitchKind)Enum.Parse(typeof(ParameterSwitchKind), switchValue); validSwitch = new ValidationResult { ResultKind = ValidationResultKind.Valid, Message = string.Empty }; } else { switchKind = ParameterSwitchKind.MANUAL; validSwitch = new ValidationResult { ResultKind = ValidationResultKind.Invalid, Message = string.Format("{0} is not a valid Parameter Switch Kind", switchValue) }; } if (validSwitch.ResultKind > validationResult) { validationResult = validSwitch.ResultKind; } var validManualValue = new ValidationResult { ResultKind = ValidationResultKind.InConclusive, Message = string.Empty }; if (parameterType != null) { if (parameterType is TimeOfDayParameterType) { ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref manualValue, parameterType); } validManualValue = parameterType.Validate(manualValue, measurementScale, provider); if (validManualValue.ResultKind > validationResult) { validationResult = validManualValue.ResultKind; } } ParameterSheetUtilities.Decorate(validManualValue, this.parameterSheet, currentRow, ParameterSheetConstants.ManualColumn); ProcessedValueSet processedValueSet; var valueSetExists = valuesets.TryGetValue(parameterSubscriptionValueSet.Iid, out processedValueSet); if (!valueSetExists) { processedValueSet = new ProcessedValueSet(parameterSubscriptionValueSet, validationResult); } ValueSetValues valueSetValues; if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, manualValue, null, null, null, out valueSetValues)) { processedValueSet.UpdateClone(valueSetValues); if (!valueSetExists) { valuesets.Add(parameterSubscriptionValueSet.Iid, processedValueSet); } } }