Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] (de)serialization of AlternativeID; fixes #54 #55

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SpecElementWithAttributesExtensionTestFixture
{
private ReqIF reqIf;

private IReqIFLoaderService reqIFLoaderService;
private ReqIFLoaderService reqIFLoaderService;

[SetUp]
public async Task SetUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ public static async Task<IEnumerable<Tuple<ExternalObject, string>>> QueryBase64
{
var result = new List<Tuple<ExternalObject, string>>();

var cts = new CancellationTokenSource();

foreach (var specObjectValue in specElementWithAttributes.Values.OfType<AttributeValueXHTML>())
using (var cts = new CancellationTokenSource())
{
foreach (var externalObject in specObjectValue.ExternalObjects)
foreach (var specObjectValue in specElementWithAttributes.Values.OfType<AttributeValueXHTML>())
{
var payload = await reqIfLoaderService.QueryData(externalObject, cts.Token);
result.Add(new Tuple<ExternalObject, string>(externalObject, payload));
foreach (var externalObject in specObjectValue.ExternalObjects)
{
var payload = await reqIfLoaderService.QueryData(externalObject, cts.Token);
result.Add(new Tuple<ExternalObject, string>(externalObject, payload));
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions ReqIFSharp.Tests/DeSerializeAndSerializeTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,21 @@ public async Task Verify_that_DefaultValueDemo_file_is_deserialized_and_async_se
Assert.That(attributeDefinitionString.DefaultValue.TheValue, Is.EqualTo("LAH ---.---.---.-"));
Assert.That(attributeDefinitionString.DefaultValue.Definition.Identifier, Is.EqualTo("_d0368b53-d0c6-43a1-a746-45243624b027"));
}

[Test]
public void Verify_That_ProRailDemo_with_validation_and_assert_alternaiveid()
{
var cancellationTokenSource = new CancellationTokenSource();

var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");
var deserializer = new ReqIFDeserializer();

var reqIfs = deserializer.Deserialize(reqifPath, true);

var reqif = reqIfs.Single();
var alternativeId = reqif.CoreContent.DataTypes.Single(x => x.Identifier == "_o7scM6dbEeafNduaIhMwQg_ald").AlternativeId;

Assert.That(alternativeId.Identifier, Is.EqualTo("_o7scM6dbEeafNduaIhMwQg_ald"));
}
}
}
21 changes: 17 additions & 4 deletions ReqIFSharp.Tests/ReqIFDeSerializerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,14 @@ public async Task Verify_that_AlternativeId_can_be_deserialized_async()

var specObjectType = reqif.CoreContent.SpecTypes.OfType<SpecObjectType>().Single(x => x.Identifier == "_jgCytAfNEeeAO8RifBaE-g");

foreach (var attributeDefinition in specObjectType.SpecAttributes)
foreach (var datatypeDefinition in reqif.CoreContent.DataTypes)
{
Assert.That(attributeDefinition.AlternativeId.Identifier, Is.EqualTo(attributeDefinition.Identifier));
Assert.That(datatypeDefinition.AlternativeId.Identifier, Is.EqualTo(datatypeDefinition.Identifier));
}

foreach (var datatypeDefinition in reqif.CoreContent.DataTypes)
foreach (var attributeDefinition in specObjectType.SpecAttributes)
{
Assert.That(datatypeDefinition.AlternativeId.Identifier, Is.EqualTo(datatypeDefinition.Identifier));
Assert.That(attributeDefinition.AlternativeId.Identifier, Is.EqualTo(attributeDefinition.Identifier));
}

foreach (var specType in reqif.CoreContent.SpecTypes)
Expand Down Expand Up @@ -706,5 +706,18 @@ public void Verify_that_sampleGH43_can_be_deserialized_async()

Assert.That(async () => await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token), Throws.Nothing);
}

[Test]
public void Verify_that_ReqIfSharp_file_can_be_deserialized_async_with_validation()
{
var cancellationTokenSource = new CancellationTokenSource();

var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "reqifsharpgenerated.reqif");

var deserializer = new ReqIFDeserializer();

Assert.That(async () => await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token, true), Throws.Nothing);
}

}
}
4 changes: 1 addition & 3 deletions ReqIFSharp.Tests/ReqIFSerializerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ internal class ReqIFSerializerTestFixture
private string asyncResultFileUri;
private string asyncResultFileUriArchive;

private const string ReqIFNamespace = @"http://www.omg.org/spec/ReqIF/20110401/reqif.xsd";

private string specobject_1_id;

private string specobject_2_id;
Expand Down Expand Up @@ -709,7 +707,7 @@ private void CreateValuesForSpecElementWithAttributes(SpecElementWithAttributes
var simplifiedAttributeValueXhtml = new AttributeValueXHTML();
simplifiedAttributeValueXhtml.Definition = (AttributeDefinitionXHTML)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionXHTML));
simplifiedAttributeValueXhtml.IsSimplified = true;
simplifiedAttributeValueXhtml.TheValue = "simplified content";
simplifiedAttributeValueXhtml.TheValue = this.xhtmlcontent;
simplifiedAttributeValueXhtml.TheOriginalValue= this.xhtmlcontent;
specElementWithAttributes.Values.Add(simplifiedAttributeValueXhtml);
}
Expand Down
3 changes: 3 additions & 0 deletions ReqIFSharp.Tests/ReqIFSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<None Update="TestData\ProR_Traceability-Template-v1.0.reqif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestData\reqifsharpgenerated.reqif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestData\requirements-and-objects.reqifz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Loading
Loading