Skip to content
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 @@ -20,7 +20,10 @@

namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions
{
using System.Linq;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -54,9 +57,9 @@ public void OneTimeSetUp()
});
}

[Test]
public void Verify_that_QueryDatatypeName_returns_expected_results()
{
[Test]
public void Verify_that_QueryDatatypeName_returns_expected_results()
{
var attributeDefinitionBoolean = new AttributeDefinitionBoolean();
Assert.That(attributeDefinitionBoolean.QueryDatatypeName(), Is.EqualTo("Boolean"));

Expand Down Expand Up @@ -96,13 +99,29 @@ public void Verify_that_QueryDatatypeName_returns_expected_results()
var attributeDefinitionXhtml = new AttributeDefinitionXHTML();
Assert.That(attributeDefinitionXhtml.QueryDatatypeName(), Is.EqualTo("XHTML"));

attributeDefinitionXhtml = new AttributeDefinitionXHTML(this.loggerFactory);
Assert.That(attributeDefinitionXhtml.QueryDatatypeName(), Is.EqualTo("XHTML"));
}

[Test]
public void Verify_that_QueryDefaultValueAsFormattedString_returns_expected_results()
{
attributeDefinitionXhtml = new AttributeDefinitionXHTML(this.loggerFactory);
Assert.That(attributeDefinitionXhtml.QueryDatatypeName(), Is.EqualTo("XHTML"));
}

[Test]
public void Verify_that_QueryDatatypeName_throws_when_input_is_null()
{
Assert.That(() => AttributeDefinitionExtensions.QueryDatatypeName(null), Throws.ArgumentNullException);
}

[Test]
public void Verify_that_QueryDatatypeName_throws_when_type_is_not_supported()
{
var unsupportedAttributeDefinition = new UnsupportedAttributeDefinition();

Assert.That(
() => unsupportedAttributeDefinition.QueryDatatypeName(),
Throws.Exception.TypeOf<InvalidOperationException>());
}

[Test]
public void Verify_that_QueryDefaultValueAsFormattedString_returns_expected_results()
{
var testDataCreator = new ReqIFTestDataCreator();
var reqif = testDataCreator.Create();

Expand All @@ -126,8 +145,98 @@ public void Verify_that_QueryDefaultValueAsFormattedString_returns_expected_resu
var attributeDefinitionString = (AttributeDefinitionString)specType.SpecAttributes.Single(x => x.Identifier == "requirement-string-attribute");
Assert.That(attributeDefinitionString.QueryDefaultValueAsFormattedString(), Is.EqualTo("NOT SET"));

var attributeDefinitionXHTML = (AttributeDefinitionXHTML)specType.SpecAttributes.Single(x => x.Identifier == "requirement-xhtml-attribute");
Assert.That(attributeDefinitionXHTML.QueryDefaultValueAsFormattedString(), Is.EqualTo("NOT SET"));
}
}
}
var attributeDefinitionXHTML = (AttributeDefinitionXHTML)specType.SpecAttributes.Single(x => x.Identifier == "requirement-xhtml-attribute");
Assert.That(attributeDefinitionXHTML.QueryDefaultValueAsFormattedString(), Is.EqualTo("NOT SET"));
}

[Test]
public void Verify_that_QueryDefaultValueAsFormattedString_returns_formatted_default_values()
{
var attributeDefinitionBoolean = new AttributeDefinitionBoolean
{
DefaultValue = new AttributeValueBoolean { TheValue = true }
};

Assert.That(attributeDefinitionBoolean.QueryDefaultValueAsFormattedString(), Is.EqualTo("True"));

var attributeDefinitionDate = new AttributeDefinitionDate
{
DefaultValue = new AttributeValueDate { TheValue = new DateTime(2020, 12, 25) }
};

Assert.That(attributeDefinitionDate.QueryDefaultValueAsFormattedString(), Is.EqualTo("December 25, 2020"));

var enumValue = new EnumValue { Identifier = "enum" };
var attributeDefinitionEnumeration = new AttributeDefinitionEnumeration
{
DefaultValue = new AttributeValueEnumeration()
};
attributeDefinitionEnumeration.DefaultValue.Values.Add(enumValue);

Assert.That(
attributeDefinitionEnumeration.QueryDefaultValueAsFormattedString(),
Is.EqualTo(enumValue.ToString()));

var attributeDefinitionInteger = new AttributeDefinitionInteger
{
DefaultValue = new AttributeValueInteger { TheValue = 42 }
};

Assert.That(attributeDefinitionInteger.QueryDefaultValueAsFormattedString(), Is.EqualTo("42"));

var attributeDefinitionReal = new AttributeDefinitionReal
{
DefaultValue = new AttributeValueReal { TheValue = 4.2 }
};

Assert.That(attributeDefinitionReal.QueryDefaultValueAsFormattedString(), Is.EqualTo("4.2"));

var attributeDefinitionString = new AttributeDefinitionString
{
DefaultValue = new AttributeValueString { TheValue = "value" }
};

Assert.That(attributeDefinitionString.QueryDefaultValueAsFormattedString(), Is.EqualTo("value"));

var attributeDefinitionXhtml = new AttributeDefinitionXHTML
{
DefaultValue = new AttributeValueXHTML { TheValue = "<xhtml:p>content</xhtml:p>" }
};

Assert.That(attributeDefinitionXhtml.QueryDefaultValueAsFormattedString(), Is.EqualTo("<xhtml:p>content</xhtml:p>"));
}

[Test]
public void Verify_that_QueryDefaultValueAsFormattedString_throws_when_input_is_null()
{
Assert.That(() => AttributeDefinitionExtensions.QueryDefaultValueAsFormattedString(null), Throws.ArgumentNullException);
}

[Test]
public void Verify_that_QueryDefaultValueAsFormattedString_throws_when_type_is_not_supported()
{
var unsupportedAttributeDefinition = new UnsupportedAttributeDefinition();

Assert.That(
() => unsupportedAttributeDefinition.QueryDefaultValueAsFormattedString(),
Throws.Exception.TypeOf<InvalidOperationException>());
}

private class UnsupportedAttributeDefinition : AttributeDefinition
{
protected override DatatypeDefinition GetDatatypeDefinition()
{
return null;
}

protected override void SetDatatypeDefinition(DatatypeDefinition datatypeDefinition)
{
}

internal override Task ReadXmlAsync(System.Xml.XmlReader reader, CancellationToken token)
{
return Task.CompletedTask;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions
{
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using NUnit.Framework;

Expand All @@ -34,11 +38,11 @@ namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions
[TestFixture]
public class AttributeValueExtensionsTestFixture
{
[Test]
public void Verify_that_QueryFormattedValue_returns_expected_results()
{
var testDataCreator = new ReqIFTestDataCreator();
var reqif = testDataCreator.Create();
[Test]
public void Verify_that_QueryFormattedValue_returns_expected_results()
{
var testDataCreator = new ReqIFTestDataCreator();
var reqif = testDataCreator.Create();

var specObject = reqif.CoreContent.SpecObjects.Single(x => x.Identifier == "specobject_1");

Expand All @@ -60,8 +64,82 @@ public void Verify_that_QueryFormattedValue_returns_expected_results()
var attributeValueString = specObject.Values.OfType<AttributeValueString>().Single();
Assert.That(attributeValueString.QueryFormattedValue(), Is.EqualTo("a string value"));

var attributeValueXhtml = specObject.Values.OfType<AttributeValueXHTML>().First();
Assert.That(attributeValueXhtml.QueryFormattedValue(), Is.EqualTo("<xhtml:p>XhtmlPType<xhtml:a accesskey=\"a\" charset=\"UTF-8\" href=\"http://eclipse.org/rmf\" hreflang=\"en\" rel=\"LinkTypes\" rev=\"LinkTypes\" style=\"text-decoration:underline\" tabindex=\"1\" title=\"text\" type=\"text/html\"> text before br<xhtml:br/>text after br text before span<xhtml:span>XhtmlSpanType</xhtml:span>text after span text before em<xhtml:em>XhtmlEmType</xhtml:em>text after em text before strong<xhtml:strong>XhtmlStrongType</xhtml:strong>text after strong text before dfn<xhtml:dfn>XhtmlDfnType</xhtml:dfn>text after dfn text before code<xhtml:code>XhtmlCodeType</xhtml:code>text after code text before samp<xhtml:samp>XhtmlSampType</xhtml:samp>text after samp text before kbd<xhtml:kbd>XhtmlKbdType</xhtml:kbd>text after kbd text before var<xhtml:var>XhtmlVarType</xhtml:var>text after var text before cite<xhtml:cite>XhtmlCiteType</xhtml:cite>text after cite text before abbr<xhtml:abbr>XhtmlAbbrType</xhtml:abbr>text after abbr text before acronym<xhtml:acronym>XhtmlAcronymType</xhtml:acronym>text after acronym text before q<xhtml:q>XhtmlQType</xhtml:q>text after q text before tt<xhtml:tt>XhtmlInlPresType</xhtml:tt>text after tt text before i<xhtml:i>XhtmlInlPresType</xhtml:i>text after i text before b<xhtml:b>XhtmlInlPresType</xhtml:b>text after b text before big<xhtml:big>XhtmlInlPresType</xhtml:big>text after big text before small<xhtml:small>XhtmlInlPresType</xhtml:small>text after small text before sub<xhtml:sub>XhtmlInlPresType</xhtml:sub>text after sub text before sup<xhtml:sup>XhtmlInlPresType</xhtml:sup>text after sup text before ins<xhtml:ins>XhtmlEditType</xhtml:ins>text after ins text before del<xhtml:del>XhtmlEditType</xhtml:del>text after del</xhtml:a></xhtml:p>"));
}
}
}
var attributeValueXhtml = specObject.Values.OfType<AttributeValueXHTML>().First();
Assert.That(attributeValueXhtml.QueryFormattedValue(), Is.EqualTo("<xhtml:p>XhtmlPType<xhtml:a accesskey=\"a\" charset=\"UTF-8\" href=\"http://eclipse.org/rmf\" hreflang=\"en\" rel=\"LinkTypes\" rev=\"LinkTypes\" style=\"text-decoration:underline\" tabindex=\"1\" title=\"text\" type=\"text/html\"> text before br<xhtml:br/>text after br text before span<xhtml:span>XhtmlSpanType</xhtml:span>text after span text before em<xhtml:em>XhtmlEmType</xhtml:em>text after em text before strong<xhtml:strong>XhtmlStrongType</xhtml:strong>text after strong text before dfn<xhtml:dfn>XhtmlDfnType</xhtml:dfn>text after dfn text before code<xhtml:code>XhtmlCodeType</xhtml:code>text after code text before samp<xhtml:samp>XhtmlSampType</xhtml:samp>text after samp text before kbd<xhtml:kbd>XhtmlKbdType</xhtml:kbd>text after kbd text before var<xhtml:var>XhtmlVarType</xhtml:var>text after var text before cite<xhtml:cite>XhtmlCiteType</xhtml:cite>text after cite text before abbr<xhtml:abbr>XhtmlAbbrType</xhtml:abbr>text after abbr text before acronym<xhtml:acronym>XhtmlAcronymType</xhtml:acronym>text after acronym text before q<xhtml:q>XhtmlQType</xhtml:q>text after q text before tt<xhtml:tt>XhtmlInlPresType</xhtml:tt>text after tt text before i<xhtml:i>XhtmlInlPresType</xhtml:i>text after i text before b<xhtml:b>XhtmlInlPresType</xhtml:b>text after b text before big<xhtml:big>XhtmlInlPresType</xhtml:big>text after big text before small<xhtml:small>XhtmlInlPresType</xhtml:small>text after small text before sub<xhtml:sub>XhtmlInlPresType</xhtml:sub>text after sub text before sup<xhtml:sup>XhtmlInlPresType</xhtml:sup>text after sup text before ins<xhtml:ins>XhtmlEditType</xhtml:ins>text after ins text before del<xhtml:del>XhtmlEditType</xhtml:del>text after del</xhtml:a></xhtml:p>"));
}

[Test]
public void Verify_that_QueryFormattedValue_joins_multiple_enumeration_values()
{
var enumerationValueA = new EnumValue
{
Properties = new EmbeddedValue { OtherContent = "A" }
};

var enumerationValueB = new EnumValue
{
Properties = new EmbeddedValue { OtherContent = "B" }
};

var attributeValueEnumeration = new AttributeValueEnumeration();
attributeValueEnumeration.Values.Add(enumerationValueA);
attributeValueEnumeration.Values.Add(enumerationValueB);

Assert.That(attributeValueEnumeration.QueryFormattedValue(), Is.EqualTo("A;B"));
}

[Test]
public void Verify_that_QueryFormattedValue_throws_when_attributeValue_is_null()
{
Assert.That(() => AttributeValueExtensions.QueryFormattedValue(null), Throws.ArgumentNullException);
}

[Test]
public void Verify_that_QueryFormattedValue_throws_when_type_is_not_supported()
{
var unsupportedAttributeValue = new UnsupportedAttributeValue();

Assert.That(
() => unsupportedAttributeValue.QueryFormattedValue(),
Throws.Exception.TypeOf<InvalidOperationException>());
}

private class UnsupportedAttributeValue : AttributeValue
{
public override object ObjectValue
{
get => null;
set
{
}
}

protected override AttributeDefinition GetAttributeDefinition()
{
return null;
}

protected override void SetAttributeDefinition(AttributeDefinition attributeDefinition)
{
}

internal override void ReadXml(System.Xml.XmlReader reader)
{
}

internal override Task ReadXmlAsync(System.Xml.XmlReader reader, CancellationToken token)
{
return Task.CompletedTask;
}

internal override void WriteXml(System.Xml.XmlWriter writer)
{
}

internal override Task WriteXmlAsync(System.Xml.XmlWriter writer, CancellationToken token)
{
return Task.CompletedTask;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions
{
using System;
using System.Linq;

using NUnit.Framework;

using ReqIFSharp.Extensions.ReqIFExtensions;
using ReqIFSharp.Extensions.Tests.TestData;
using System.Linq;

using NUnit.Framework;

using ReqIFSharp;
using ReqIFSharp.Extensions.ReqIFExtensions;
using ReqIFSharp.Extensions.Tests.TestData;

/// <summary>
/// Suite of tests for the <see cref="RelationGroupTypeExtensions"/> class.
Expand All @@ -45,20 +46,49 @@ public void SetUp()
}

[Test]
public void Verify_that_QueryReferencingRelationGroups_returns_expected_results()
{
var relationGroupType = (RelationGroupType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "relationgrouptype");

var specObjects = relationGroupType.QueryReferencingRelationGroups();

Assert.That(specObjects.Count(), Is.EqualTo(1));
}

[Test]
public void Verify_that_on_QueryReferencingRelationGroups_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set()
{
var relationGroupType = new RelationGroupType();

public void Verify_that_QueryReferencingRelationGroups_returns_expected_results()
{
var relationGroupType = (RelationGroupType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "relationgrouptype");

var specObjects = relationGroupType.QueryReferencingRelationGroups();

Assert.That(specObjects.Count(), Is.EqualTo(1));
}

[Test]
public void Verify_that_QueryReferencingRelationGroups_returns_empty_when_none_reference_type()
{
var reqIf = new ReqIF
{
CoreContent = new ReqIFContent()
};

var relationGroupType = new RelationGroupType { ReqIFContent = reqIf.CoreContent };
var otherRelationGroupType = new RelationGroupType { ReqIFContent = reqIf.CoreContent };

var relationGroup = new RelationGroup(reqIf.CoreContent, null)
{
Type = otherRelationGroupType
};

reqIf.CoreContent.SpecRelationGroups.Add(relationGroup);

var result = relationGroupType.QueryReferencingRelationGroups();

Assert.That(result, Is.Empty);
}

[Test]
public void Verify_that_QueryReferencingRelationGroups_throws_when_relationGroupType_is_null()
{
Assert.That(() => RelationGroupTypeExtensions.QueryReferencingRelationGroups(null), Throws.ArgumentNullException);
}

[Test]
public void Verify_that_on_QueryReferencingRelationGroups_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set()
{
var relationGroupType = new RelationGroupType();

Assert.That(() => relationGroupType.QueryReferencingRelationGroups(),
Throws.Exception.TypeOf<InvalidOperationException>()
.With.Message.Contains("The owning ReqIFContent of the RelationGroupType is not set."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using NUnit.Framework;

using ReqIFSharp;
Expand Down
Loading
Loading