Skip to content

Commit

Permalink
[Refactor] NestedElementTreeGenerator to compare options based on uni…
Browse files Browse the repository at this point in the history
…que identifier, this resolves #4
  • Loading branch information
sam.gerene committed Jan 23, 2018
1 parent a7ba1ff commit a183775
Show file tree
Hide file tree
Showing 20 changed files with 821 additions and 511 deletions.
2 changes: 1 addition & 1 deletion CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>

<PackageReference Include="CDP4Common-CE" Version="1.0.2" />
<PackageReference Include="CDP4Common-CE" Version="1.0.3" />
<!--
<ProjectReference Include="..\CDP4Common\CDP4Common.csproj" />
<PackageReference Include="NLog" Version="4.5.0-rc03" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NestedElementTreeGeneratorTestFixtre.cs" company="RHEA System S.A.">
// Copyright (c) 2018 RHEA System S.A.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.Tests.Helpers
{
using System;
using System.Collections.Concurrent;
using System.Linq;

using CDP4Common.CommonData;
using CDP4Common.EngineeringModelData;
using CDP4Common.Helpers;
using CDP4Common.SiteDirectoryData;
using NUnit.Framework;

/// <summary>
/// Suite of tests for the <see cref="NestedElementTreeGenerator"/> class.
/// </summary>
[TestFixture]
public class NestedElementTreeGeneratorTestFixtre
{
private NestedElementTreeGenerator nestedElementTreeGenerator;
private Uri uri;
private ConcurrentDictionary<Tuple<Guid, Guid?>, Lazy<Thing>> cache;
private Iteration iteration;
private DomainOfExpertise domainOfExpertise;


[SetUp]
public void SetUp()
{
this.nestedElementTreeGenerator = new NestedElementTreeGenerator();

this.uri = new Uri("http://www.rheagroup.com");
this.cache = new ConcurrentDictionary<Tuple<Guid, Guid?>, Lazy<Thing>>();

this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "SYS",
Name = "System"
};

this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);

var option_A = new Option(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "OPT_A",
Name = "Option A"
};
this.iteration.Option.Add(option_A);
this.iteration.DefaultOption = option_A;

var option_B = new Option(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "OPT_B",
Name = "Option B"
};
this.iteration.Option.Add(option_B);

var satellite = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "Sat",
Name = "Satellite"
};
this.iteration.Element.Add(satellite);
this.iteration.TopElement = satellite;

var battery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "Bat",
Name = "Battery"
};
this.iteration.Element.Add(battery);

var battery_a = new ElementUsage(Guid.NewGuid(), this.cache, this.uri)
{
ElementDefinition = battery,
ShortName = "bat_a",
Name = "battery a"
};
satellite.ContainedElement.Add(battery_a);

var battery_b = new ElementUsage(Guid.NewGuid(), this.cache, this.uri)
{
ElementDefinition = battery,
ShortName = "bat_b",
Name = "battery b"
};
battery_b.ExcludeOption.Add(option_A);

satellite.ContainedElement.Add(battery_b);
}

[Test]
public void Verify_that_null_arguments_throws_exception()
{
Assert.Throws<ArgumentNullException>(() => this.nestedElementTreeGenerator.Generate(null, null));

var option = this.iteration.Option.First();
Assert.Throws<ArgumentNullException>(() => this.nestedElementTreeGenerator.Generate(option, null));
}

[Test]
public void Verify_that_excluded_usage_option_a_does_not_get_generated_as_nested_element()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_A");

var nestedElements = this.nestedElementTreeGenerator.Generate(option, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

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

[Test]
public void Verify_that_excluded_usage_option_a_does_not_get_generated_as_nested_element_if_option_is_a_cloned_object()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_A");
var optionClone = option.Clone(false);

var nestedElements = this.nestedElementTreeGenerator.Generate(optionClone, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

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

[Test]
public void Verify_that_excluded_usage_from_a_In_option_b_get_generated_as_nested_element()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_B");

var nestedElements = this.nestedElementTreeGenerator.Generate(option, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

Assert.AreEqual(3, nestedElements.Count());
}
}
}
2 changes: 1 addition & 1 deletion CDP4Common.Tests/CDP4Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>

<PackageReference Include="CDP4Common-CE" Version="1.0.2" />
<PackageReference Include="CDP4Common-CE" Version="1.0.3" />
<!--
<ProjectReference Include="..\CDP4Common\CDP4Common.csproj" />
<PackageReference Include="NLog" Version="4.5.0-rc03" />
Expand Down
152 changes: 152 additions & 0 deletions CDP4Common.Tests/Helpers/NestedElementTreeGeneratorTestFixtre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NestedElementTreeGeneratorTestFixtre.cs" company="RHEA System S.A.">
// Copyright (c) 2018 RHEA System S.A.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.Tests.Helpers
{
using System;
using System.Collections.Concurrent;
using System.Linq;

using CDP4Common.CommonData;
using CDP4Common.EngineeringModelData;
using CDP4Common.Helpers;
using CDP4Common.SiteDirectoryData;
using NUnit.Framework;

/// <summary>
/// Suite of tests for the <see cref="NestedElementTreeGenerator"/> class.
/// </summary>
[TestFixture]
public class NestedElementTreeGeneratorTestFixtre
{
private NestedElementTreeGenerator nestedElementTreeGenerator;
private Uri uri;
private ConcurrentDictionary<Tuple<Guid, Guid?>, Lazy<Thing>> cache;
private Iteration iteration;
private DomainOfExpertise domainOfExpertise;


[SetUp]
public void SetUp()
{
this.nestedElementTreeGenerator = new NestedElementTreeGenerator();

this.uri = new Uri("http://www.rheagroup.com");
this.cache = new ConcurrentDictionary<Tuple<Guid, Guid?>, Lazy<Thing>>();

this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "SYS",
Name = "System"
};

this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);

var option_A = new Option(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "OPT_A",
Name = "Option A"
};
this.iteration.Option.Add(option_A);
this.iteration.DefaultOption = option_A;

var option_B = new Option(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "OPT_B",
Name = "Option B"
};
this.iteration.Option.Add(option_B);

var satellite = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "Sat",
Name = "Satellite"
};
this.iteration.Element.Add(satellite);
this.iteration.TopElement = satellite;

var battery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
{
ShortName = "Bat",
Name = "Battery"
};
this.iteration.Element.Add(battery);

var battery_a = new ElementUsage(Guid.NewGuid(), this.cache, this.uri)
{
ElementDefinition = battery,
ShortName = "bat_a",
Name = "battery a"
};
satellite.ContainedElement.Add(battery_a);

var battery_b = new ElementUsage(Guid.NewGuid(), this.cache, this.uri)
{
ElementDefinition = battery,
ShortName = "bat_b",
Name = "battery b"
};
battery_b.ExcludeOption.Add(option_A);

satellite.ContainedElement.Add(battery_b);
}

[Test]
public void Verify_that_null_arguments_throws_exception()
{
Assert.Throws<ArgumentNullException>(() => this.nestedElementTreeGenerator.Generate(null, null));

var option = this.iteration.Option.First();
Assert.Throws<ArgumentNullException>(() => this.nestedElementTreeGenerator.Generate(option, null));
}

[Test]
public void Verify_that_excluded_usage_option_a_does_not_get_generated_as_nested_element()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_A");

var nestedElements = this.nestedElementTreeGenerator.Generate(option, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

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

[Test]
public void Verify_that_excluded_usage_option_a_does_not_get_generated_as_nested_element_if_option_is_a_cloned_object()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_A");
var optionClone = option.Clone(false);

var nestedElements = this.nestedElementTreeGenerator.Generate(optionClone, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

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

[Test]
public void Verify_that_excluded_usage_from_a_In_option_b_get_generated_as_nested_element()
{
var option = this.iteration.Option.Single(x => x.ShortName == "OPT_B");

var nestedElements = this.nestedElementTreeGenerator.Generate(option, this.domainOfExpertise);

foreach (var nestedElement in nestedElements)
{
Console.WriteLine(nestedElement.ShortName);
}

Assert.AreEqual(3, nestedElements.Count());
}
}
}
4 changes: 2 additions & 2 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;netstandard1.6;netstandard2.0</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Patxi</Authors>
Expand All @@ -16,7 +16,7 @@
<PackageTags>CDP CDP4 ECSS-E-TM-10-25</PackageTags>
<PackageLicenseUrl>https://github.com/RHEAGROUP/CDP4-SDK-Community-Edition/blob/master/LICENSE</PackageLicenseUrl>
<Configurations>Debug;Release</Configurations>
<PackageReleaseNotes>[Add] InvalidOperationException to GetTopContainerRoute() when PartialRoutes is empty</PackageReleaseNotes>
<PackageReleaseNotes>[Refactor] NestedElementTreeGenerator to compare options based on unique identifier</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit a183775

Please sign in to comment.