Skip to content

Commit

Permalink
[Add] SpecificationPage that lists Specifications contained by select…
Browse files Browse the repository at this point in the history
…ed ReqIF file; fixes #17

[Refactor] navigation to: /reqif/identifier/.../{some-other-identifier}

[Add] SpecificationDetailsPage

[Add] SpecElementWithAttributesExtensions, SpecHierarchyExtensions, SpecificationExtensions

[Update] solution dependencies
[Update] SpecificationPage and SpecificationDetailsPage

[Add] AttributeValuesComponent
  • Loading branch information
sam.gerene committed Dec 21, 2021
1 parent dab6313 commit 04819d3
Show file tree
Hide file tree
Showing 18 changed files with 762 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecElementWithAttributesExtensionTestFixture.cs" company="RHEA System S.A.">
//
// Copyright 2021 RHEA System S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Infrastructure.Tests.ReqIFExtensions
{
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Components;

using NUnit.Framework;

using ReqIFSharp;
using ReqifViewer.Infrastructure.ReqIFExtensions;
using ReqifViewer.Infrastructure.Services;

/// <summary>
/// Suite of tests for the <see cref="SpecElementWithAttributesExtensions"/>
/// </summary>
[TestFixture]
public class SpecElementWithAttributesExtensionTestFixture
{
private ReqIF reqIf;

[SetUp]
public async Task SetUp()
{
var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
var reqIfLoaderService = new ReqIFLoaderService();
await reqIfLoaderService.Load(fileStream);

this.reqIf = reqIfLoaderService.ReqIFData.Single();
}

[Test]
public void Verify_that_ExtractSpecificationName_returns_expected_result()
{
var specObject = this.reqIf.CoreContent.SpecObjects.Single(x => x.Identifier == "_o7scQ6dbEeafNduaIhMwQg");
var markupString = new MarkupString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">Stakeholder Requirements</xhtml:div>");
Assert.That(specObject.ExtractDisplayName(), Is.EqualTo(markupString));

var specification = this.reqIf.CoreContent.Specifications.Single(x => x.Identifier == "_o7scS6dbEeafNduaIhMwQg");
Assert.That(specification.ExtractDisplayName(), Is.EqualTo("Requirements Document"));

specObject = this.reqIf.CoreContent.SpecObjects.Single(x => x.Identifier == "_DqMpsKddEeafNduaIhMwQg");
Assert.That(specObject.ExtractDisplayName(), Is.EqualTo("REQ-6"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecificationExtensionsTestFixture.cs" company="RHEA System S.A.">
//
// Copyright 2021 RHEA System S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Infrastructure.Tests.ReqIFExtensions
{
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using NUnit.Framework;

using ReqIFSharp;

using ReqifViewer.Infrastructure.ReqIFExtensions;
using ReqifViewer.Infrastructure.Services;

/// <summary>
/// Suite of tests for the <see cref="SpecificationExtensions"/> class
/// </summary>
[TestFixture]
public class SpecificationExtensionsTestFixture
{
private ReqIF reqIf;

[SetUp]
public async Task SetUp()
{
var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");

await using var fileStream = new FileStream(reqifPath, FileMode.Open);
var reqIfLoaderService = new ReqIFLoaderService();
await reqIfLoaderService.Load(fileStream);

this.reqIf = reqIfLoaderService.ReqIFData.Single();
}

[Test]
public void Verify_that_QuerySpecHierarchies_returns_the_expected_results()
{
var specification = this.reqIf.CoreContent.Specifications.Single(x => x.Identifier == "_o7scS6dbEeafNduaIhMwQg");

Assert.That(specification.QueryAllContainedSpecHierarchies().Count(), Is.EqualTo(13));
}

[Test]
public void Verify_that_QueryAttributeDefinitions_returns_the_expected_results()
{
var specification = this.reqIf.CoreContent.Specifications.Single(x => x.Identifier == "_o7scS6dbEeafNduaIhMwQg");

var attributeDefinitions = specification.QueryAttributeDefinitions().ToList();

Assert.That(attributeDefinitions.Count, Is.EqualTo(3));

Assert.That(attributeDefinitions.Single(x => x.Identifier == "_o7scPKdbEeafNduaIhMwQg"), Is.Not.Null);
Assert.That(attributeDefinitions.Single(x => x.Identifier == "_o7scPadbEeafNduaIhMwQg"), Is.Not.Null);
Assert.That(attributeDefinitions.Single(x => x.Identifier == "_o7scO6dbEeafNduaIhMwQg"), Is.Not.Null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecElementWithAttributesExtensions.cs" company="RHEA System S.A.">
//
// Copyright 2021 RHEA System S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Infrastructure.ReqIFExtensions
{
using System.Linq;

using Microsoft.AspNetCore.Components;

using ReqIFSharp;

/// <summary>
/// The <see cref="SpecElementWithAttributesExtensions"/> class provides a number of extension methods for the <see cref="SpecElementWithAttributes"/> class
/// </summary>
public static class SpecElementWithAttributesExtensions
{
/// <summary>
/// Extracts the name (value to be displayed to the user) of the <see cref="SpecElementWithAttributes"/>
/// </summary>
/// <param name="specElementWithAttributes">
/// The subject <see cref="SpecElementWithAttributes"/>
/// </param>
/// <returns>
/// an object that represents the <see cref="specElementWithAttributes"/> name (value to be displayed to the user)
/// </returns>
/// <remarks>
/// 1. The <see cref="Identifiable.LongName"/> is returned in case it is not empty or null
/// 2. The first <see cref="AttributeValue"/> is returned in case it is not null (order matters, results may be unexpected and are determined on order in the original ReqIF document)
/// 3. The <see cref="Identifiable.Identifier"/> is returned in case the <see cref="Identifiable.LongName"/> is empty or null and no <see cref="AttributeValue"/>s are present
/// </remarks>
public static object ExtractDisplayName(this SpecElementWithAttributes specElementWithAttributes)
{
if (string.IsNullOrEmpty(specElementWithAttributes.LongName))
{
var attributeValue = specElementWithAttributes.Values.FirstOrDefault();
if (attributeValue != null)
{
if (attributeValue is AttributeValueXHTML attributeValueXhtml)
{
var markupString = new MarkupString(attributeValueXhtml.TheValue);
return markupString;
}
else
{
return attributeValue.ObjectValue.ToString();
}
}
else
{
return specElementWithAttributes.Identifier;
}
}
else
{
return specElementWithAttributes.LongName;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecHierarchyExtensions.cs" company="RHEA System S.A.">
//
// Copyright 2021 RHEA System S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Infrastructure.ReqIFExtensions
{
using System.Collections.Generic;

using ReqIFSharp;

/// <summary>
/// The <see cref="SpecHierarchyExtensions"/> class provides a number of extension methods for the <see cref="SpecHierarchy"/> class
/// </summary>
public static class SpecHierarchyExtensions
{
/// <summary>
/// Queries all the contained (child) <see cref="SpecHierarchy"/> objects in a recursive manner from the <see cref="SpecHierarchy"/>
/// </summary>
/// <param name="specHierarchy">
/// The subject <see cref="SpecHierarchy"/> from which all the child <see cref="SpecHierarchy"/> are queried.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{SpecHierarchy}"/>
/// </returns>
public static IEnumerable<SpecHierarchy> QueryAllContainedSpecHierarchies(this SpecHierarchy specHierarchy)
{
var result = new List<SpecHierarchy>();

foreach (var child in specHierarchy.Children)
{
result.Add(child);

var subChildren = child.QueryAllContainedSpecHierarchies();

result.AddRange(subChildren);
}

return result;
}
}
}
105 changes: 105 additions & 0 deletions ReqifViewer.Infrastructure/ReqIFExtensions/SpecificationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecificationExtensions.cs" company="RHEA System S.A.">
//
// Copyright 2021 RHEA System S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Infrastructure.ReqIFExtensions
{
using System.Collections.Generic;

using ReqIFSharp;

/// <summary>
/// The <see cref="SpecificationExtensions"/> class provides a number of extension methods for the <see cref="Specification"/> class
/// </summary>
public static class SpecificationExtensions
{
/// <summary>
/// Queries all the contained (child) <see cref="SpecHierarchy"/> objects in a recursive manner from the <see cref="Specification"/>
/// </summary>
/// <param name="specification">
/// The subject <see cref="Specification"/> from which all the child <see cref="SpecHierarchy"/> are queried.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{SpecHierarchy}"/>
/// </returns>
public static IEnumerable<SpecHierarchy> QueryAllContainedSpecHierarchies(this Specification specification)
{
var result = new List<SpecHierarchy>();

foreach (var specHierarchy in specification.Children)
{
result.Add(specHierarchy);

var specHierarchies = specHierarchy.QueryAllContainedSpecHierarchies();
result.AddRange(specHierarchies);
}

return result;
}

/// <summary>
/// Queries all the referenced <see cref="SpecObject"/> objects in a recursive manner from the <see cref="Specification"/>
/// </summary>
/// <param name="specification">
/// The subject <see cref="Specification"/> from which all the referenced <see cref="SpecObject"/> are queried.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{SpecObject}"/>
/// </returns>
public static IEnumerable<SpecObject> QueryAllContainedSpecObjects(this Specification specification)
{
var result = new List<SpecObject>();

var specHierarchies = specification.QueryAllContainedSpecHierarchies();

foreach (var specHierarchy in specHierarchies)
{
result.Add(specHierarchy.Object);
}

return result;
}

/// <summary>
/// Queries all the referenced <see cref="SpecObject"/> objects in a recursive manner from the <see cref="Specification"/>
/// </summary>
/// <param name="specification">
/// The subject <see cref="Specification"/> from which all the referenced <see cref="SpecObject"/> are queried.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{SpecObject}"/>
/// </returns>
public static IEnumerable<AttributeDefinition> QueryAttributeDefinitions(this Specification specification)
{
var result = new HashSet<AttributeDefinition>();

var specObjects = specification.QueryAllContainedSpecObjects();

foreach (var specObject in specObjects)
{
foreach (var attributeValue in specObject.Values)
{
result.Add(attributeValue.AttributeDefinition);
}
}

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.13" />
<PackageReference Include="ReqIFSharp" Version="5.0.0-rc2" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 04819d3

Please sign in to comment.