Skip to content

Commit

Permalink
[Add] resetXXXValue methods to the IValueSet interface
Browse files Browse the repository at this point in the history
  • Loading branch information
samatrhea committed May 6, 2018
1 parent 871e21a commit be8730c
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 51 deletions.
72 changes: 69 additions & 3 deletions CDP4Common.NetCore.Tests/Poco/ParameterOverrideTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterOverrideTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2018 RHEA System S.A.
//
Expand All @@ -22,7 +21,6 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
#endregion

namespace CDP4Common.Tests.Poco
{
Expand Down Expand Up @@ -308,5 +306,73 @@ public void VerifyThatToBePublishedReturnsExpectedResult()

Assert.IsTrue(this.parameterOverride.ToBePublished);
}

[Test]
public void Verify_that_when_QueryParameterType_throws_exception_when_container_not_set()
{
var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);

Assert.Throws<ContainmentException>(() => parameterOverrideValueSet.QueryParameterType());
}

[Test]
public void Verify_that_Manual_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Manual);

parameterOverrideValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Manual);
}

[Test]
public void Verify_that_Computed_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Computed);

parameterOverrideValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Computed);
}

[Test]
public void Verify_that_Formula_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Formula);

parameterOverrideValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Formula);
}

[Test]
public void Verify_that_Reference_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Reference);

parameterOverrideValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Reference);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterOverrideValueSetTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2018 RHEA System S.A.
//
Expand All @@ -22,18 +21,16 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
#endregion

namespace CDP4Common.Tests.Poco
{
using System;
using System.Collections.Generic;
using System.Linq;

using CDP4Common.EngineeringModelData;
using CDP4Common.Exceptions;
using CDP4Common.SiteDirectoryData;
using CDP4Common.Types;

using NUnit.Framework;

[TestFixture]
Expand Down Expand Up @@ -228,5 +225,13 @@ public void VerifyThatCloneWithCloneValueArrayReturnsCloneWithNewValueArrays()
Assert.AreEqual(newComputedValue, clone.Computed[0]);
Assert.AreEqual(computedValue, parameterOverrideValueSet.Computed[0]);
}

[Test]
public void Verify_that_when_QueryParameterType_throws_exception_when_container_not_set()
{
var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);

Assert.Throws<ContainmentException>(() => parameterOverrideValueSet.QueryParameterType());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Linq;

namespace CDP4Common.Tests.Poco
{
using System;
using System.Collections.Generic;
using System.Linq;
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using CDP4Common.Types;
Expand Down Expand Up @@ -227,5 +226,46 @@ public void Verify_that_Validate_poco_returns_errors_when_size_of_valuearray_is_

Assert.AreEqual(2, errors.Count());
}

[Test]
public void Verify_that_Manual_value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var p = new Parameter(Guid.NewGuid(), null, null);
p.ParameterType = this.booleanParameterType;

var ps = new ParameterSubscription(Guid.NewGuid(), null, null);
var psvs = new ParameterSubscriptionValueSet(Guid.NewGuid(), null, null);
ps.ValueSet.Add(psvs);
p.ParameterSubscription.Add(ps);

psvs.ResetManual();
Assert.AreEqual(defaultValueArray, psvs.Manual);

psvs.ResetManual();
Assert.AreEqual(defaultValueArray, psvs.Manual);
}

[Test]
public void Verify_that_ResetComputed_throws_exception()
{
var psvs = new ParameterSubscriptionValueSet(Guid.NewGuid(), null, null);
Assert.Throws<NotSupportedException>(() => psvs.ResetComputed());
}

[Test]
public void Verify_that_ResetReference_throws_exception()
{
var psvs = new ParameterSubscriptionValueSet(Guid.NewGuid(), null, null);
Assert.Throws<NotSupportedException>(() => psvs.ResetReference());
}

[Test]
public void Verify_that_ResetFormula_throws_exception()
{
var psvs = new ParameterSubscriptionValueSet(Guid.NewGuid(), null, null);
Assert.Throws<NotSupportedException>(() => psvs.ResetFormula());
}
}
}
52 changes: 49 additions & 3 deletions CDP4Common.NetCore.Tests/Poco/ParameterValueSetTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterValueSetTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2018 RHEA System S.A.
//
Expand All @@ -22,7 +21,6 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
#endregion

namespace CDP4Common.Tests.Poco
{
Expand Down Expand Up @@ -191,5 +189,53 @@ public void Verify_that_when_container_not_set_QueryParameterType_throws_Excepti
var parameterValueSet = new ParameterValueSet(Guid.NewGuid(), null, null);
Assert.Throws<ContainmentException>(() => parameterValueSet.QueryParameterType());
}

[Test]
public void Verify_that_Manual_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

this.parameterValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Manual);

this.parameterValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Manual);
}

[Test]
public void Verify_that_Computed_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

this.parameterValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Computed);

this.parameterValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Computed);
}

[Test]
public void Verify_that_Formula_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

this.parameterValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Formula);

this.parameterValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Formula);
}

[Test]
public void Verify_that_Reference_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

this.parameterValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Reference);

this.parameterValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, this.parameterValueSet.Reference);
}
}
}
82 changes: 70 additions & 12 deletions CDP4Common.Tests/Poco/ParameterOverrideTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Copyright
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterOverrideTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2018 RHEA System S.A.
//
Expand All @@ -22,7 +21,6 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
#endregion

namespace CDP4Common.Tests.Poco
{
Expand Down Expand Up @@ -57,17 +55,17 @@ internal class ParameterOverrideTestFixture
[SetUp]
public void Setup()
{
this.domain = new DomainOfExpertise(Guid.NewGuid(), null, null) { Name = "domain", ShortName = "d"};
this.domain = new DomainOfExpertise(Guid.NewGuid(), null, null) { Name = "domain", ShortName = "d" };
this.elementDefinition1 = new ElementDefinition(Guid.NewGuid(), null, null) { Owner = this.domain, ShortName = "Sat" };
this.elementDefinition2 = new ElementDefinition(Guid.NewGuid(), null, null) { Owner = this.domain, ShortName = "Bat" };
this.elementUsage = new ElementUsage(Guid.NewGuid(), null, null)
{
ShortName = "battery_1",
ElementDefinition = this.elementDefinition2
};
this.elementUsage = new ElementUsage(Guid.NewGuid(), null, null)
{
ShortName = "battery_1",
ElementDefinition = this.elementDefinition2
};
this.elementDefinition1.ContainedElement.Add(this.elementUsage);

this.parameterOverride = new ParameterOverride(Guid.NewGuid(), null, null) { Owner = this.domain};
this.parameterOverride = new ParameterOverride(Guid.NewGuid(), null, null) { Owner = this.domain };
this.parameter = new Parameter(Guid.NewGuid(), null, null) { Owner = this.domain };
this.parameter.ParameterType = new BooleanParameterType(Guid.NewGuid(), null, null) { ShortName = "bool" };
this.parameter.IsOptionDependent = true;
Expand All @@ -85,7 +83,7 @@ public void Setup()

this.possibleList = new PossibleFiniteStateList(Guid.NewGuid(), null, null) { Name = "possible list", ShortName = "pl" };
this.possibleState1 = new PossibleFiniteState(Guid.NewGuid(), null, null) { Name = "ps1", ShortName = "ps1" };
this.possibleState2 = new PossibleFiniteState(Guid.NewGuid(), null, null) { Name = "ps2", ShortName = "ps2" };
this.possibleState2 = new PossibleFiniteState(Guid.NewGuid(), null, null) { Name = "ps2", ShortName = "ps2" };
this.possibleList.PossibleState.Add(this.possibleState1);
this.possibleList.PossibleState.Add(this.possibleState2);

Expand Down Expand Up @@ -286,7 +284,7 @@ public void VerifyThatCanBePublishedReturnsExpectedResult()
public void VerifyThatToBePublishedReturnsExpectedResult()
{
var valuesetoverriden = new ParameterValueSet(Guid.NewGuid(), null, null);
var valueset = new ParameterOverrideValueSet(Guid.NewGuid(), null, null) { ParameterValueSet = valuesetoverriden};
var valueset = new ParameterOverrideValueSet(Guid.NewGuid(), null, null) { ParameterValueSet = valuesetoverriden };
var data = new List<string> { "-" };
valueset.ValueSwitch = ParameterSwitchKind.MANUAL;
valueset.Manual = new ValueArray<string>(data);
Expand All @@ -307,6 +305,66 @@ public void VerifyThatToBePublishedReturnsExpectedResult()
valueset.Manual = new ValueArray<string>(updatedData);

Assert.IsTrue(this.parameterOverride.ToBePublished);
}

[Test]
public void Verify_that_Manual_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Manual);

parameterOverrideValueSet.ResetManual();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Manual);
}

[Test]
public void Verify_that_Computed_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Computed);

parameterOverrideValueSet.ResetComputed();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Computed);
}

[Test]
public void Verify_that_Formula_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Formula);

parameterOverrideValueSet.ResetFormula();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Formula);
}

[Test]
public void Verify_that_Reference_Value_can_be_reset()
{
var defaultValueArray = new ValueArray<string>(new List<string> { "-" });

var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);
parameterOverride.ValueSet.Add(parameterOverrideValueSet);

parameterOverrideValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Reference);

parameterOverrideValueSet.ResetReference();
Assert.AreEqual(defaultValueArray, parameterOverrideValueSet.Reference);
}
}
}
Loading

0 comments on commit be8730c

Please sign in to comment.