diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeDefinitionExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeDefinitionExtensionsTestFixture.cs index 01595ea..84fcaa7 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeDefinitionExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeDefinitionExtensionsTestFixture.cs @@ -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; @@ -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")); @@ -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()); + } + + [Test] + public void Verify_that_QueryDefaultValueAsFormattedString_returns_expected_results() + { var testDataCreator = new ReqIFTestDataCreator(); var reqif = testDataCreator.Create(); @@ -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 = "content" } + }; + + Assert.That(attributeDefinitionXhtml.QueryDefaultValueAsFormattedString(), Is.EqualTo("content")); + } + + [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()); + } + + 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; + } + } + } +} diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeValueExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeValueExtensionsTestFixture.cs index b9e0882..632cdc0 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeValueExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/AttributeValueExtensionsTestFixture.cs @@ -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; @@ -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"); @@ -60,8 +64,82 @@ public void Verify_that_QueryFormattedValue_returns_expected_results() var attributeValueString = specObject.Values.OfType().Single(); Assert.That(attributeValueString.QueryFormattedValue(), Is.EqualTo("a string value")); - var attributeValueXhtml = specObject.Values.OfType().First(); - Assert.That(attributeValueXhtml.QueryFormattedValue(), Is.EqualTo("XhtmlPType text before brtext after br text before spanXhtmlSpanTypetext after span text before emXhtmlEmTypetext after em text before strongXhtmlStrongTypetext after strong text before dfnXhtmlDfnTypetext after dfn text before codeXhtmlCodeTypetext after code text before sampXhtmlSampTypetext after samp text before kbdXhtmlKbdTypetext after kbd text before varXhtmlVarTypetext after var text before citeXhtmlCiteTypetext after cite text before abbrXhtmlAbbrTypetext after abbr text before acronymXhtmlAcronymTypetext after acronym text before qXhtmlQTypetext after q text before ttXhtmlInlPresTypetext after tt text before iXhtmlInlPresTypetext after i text before bXhtmlInlPresTypetext after b text before bigXhtmlInlPresTypetext after big text before smallXhtmlInlPresTypetext after small text before subXhtmlInlPresTypetext after sub text before supXhtmlInlPresTypetext after sup text before insXhtmlEditTypetext after ins text before delXhtmlEditTypetext after del")); - } - } -} + var attributeValueXhtml = specObject.Values.OfType().First(); + Assert.That(attributeValueXhtml.QueryFormattedValue(), Is.EqualTo("XhtmlPType text before brtext after br text before spanXhtmlSpanTypetext after span text before emXhtmlEmTypetext after em text before strongXhtmlStrongTypetext after strong text before dfnXhtmlDfnTypetext after dfn text before codeXhtmlCodeTypetext after code text before sampXhtmlSampTypetext after samp text before kbdXhtmlKbdTypetext after kbd text before varXhtmlVarTypetext after var text before citeXhtmlCiteTypetext after cite text before abbrXhtmlAbbrTypetext after abbr text before acronymXhtmlAcronymTypetext after acronym text before qXhtmlQTypetext after q text before ttXhtmlInlPresTypetext after tt text before iXhtmlInlPresTypetext after i text before bXhtmlInlPresTypetext after b text before bigXhtmlInlPresTypetext after big text before smallXhtmlInlPresTypetext after small text before subXhtmlInlPresTypetext after sub text before supXhtmlInlPresTypetext after sup text before insXhtmlEditTypetext after ins text before delXhtmlEditTypetext after del")); + } + + [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()); + } + + 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; + } + } + } +} diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/RelationGroupTypeExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/RelationGroupTypeExtensionsTestFixture.cs index 9dea1db..e88a352 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/RelationGroupTypeExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/RelationGroupTypeExtensionsTestFixture.cs @@ -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; /// /// Suite of tests for the class. @@ -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() .With.Message.Contains("The owning ReqIFContent of the RelationGroupType is not set.")); diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecElementWithAttributesExtensionTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecElementWithAttributesExtensionTestFixture.cs index de1196b..3ced4b6 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecElementWithAttributesExtensionTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecElementWithAttributesExtensionTestFixture.cs @@ -24,7 +24,7 @@ namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions using System.Linq; using System.Threading; using System.Threading.Tasks; - + using NUnit.Framework; using ReqIFSharp; diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectExtensionsTestFixture.cs index a732075..b3d70df 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectExtensionsTestFixture.cs @@ -21,11 +21,12 @@ namespace ReqIFSharp.Extensions.Tests.ReqIFExtensions { using System; - using System.Linq; - - using NUnit.Framework; - - using ReqIFSharp.Extensions.ReqIFExtensions; + using System.Linq; + + using NUnit.Framework; + + using ReqIFSharp; + using ReqIFSharp.Extensions.ReqIFExtensions; /// /// Suite of tests for the class @@ -67,29 +68,81 @@ public void SetUp() this.specRelation.Source = this.specObject; } - [Test] - public void Verify_that_QueryContainerSpecifications_returns_expected_result() - { - var specifications = this.specObject.QueryContainerSpecifications(); - - Assert.That(specifications.Single(), Is.EqualTo(this.specification)); - } - - [Test] - public void Verify_that_when_ReqIFContent_is_null_exception_is_thrown() - { - this.specObject = new SpecObject(); - - Assert.That(() => this.specObject.QueryContainerSpecifications(), - Throws.TypeOf()); - } - - [Test] - public void Verify_that_QuerySpecRelations_returns_expected_result() - { - var specRelations = this.specObject.QuerySpecRelations(); - - Assert.That(specRelations.Single(), Is.EqualTo(this.specRelation)); - } - } -} + [Test] + public void Verify_that_QueryContainerSpecifications_returns_expected_result() + { + var specifications = this.specObject.QueryContainerSpecifications(); + + Assert.That(specifications.Single(), Is.EqualTo(this.specification)); + } + + [Test] + public void Verify_that_QueryContainerSpecifications_returns_empty_when_specObject_not_in_specification() + { + var specObject = new SpecObject + { + ReqIFContent = this.reqIf.CoreContent + }; + + Assert.That(specObject.QueryContainerSpecifications(), Is.Empty); + } + + [Test] + public void Verify_that_QueryContainerSpecifications_throws_when_specObject_is_null() + { + Assert.That(() => SpecObjectExtensions.QueryContainerSpecifications(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_when_ReqIFContent_is_null_exception_is_thrown() + { + this.specObject = new SpecObject(); + + Assert.That(() => this.specObject.QueryContainerSpecifications(), + Throws.TypeOf()); + } + + [Test] + public void Verify_that_QuerySpecRelations_returns_expected_result() + { + var specRelations = this.specObject.QuerySpecRelations(); + + Assert.That(specRelations.Single(), Is.EqualTo(this.specRelation)); + } + + [Test] + public void Verify_that_QuerySpecRelations_returns_results_when_specObject_is_target() + { + var targetSpecObject = new SpecObject(this.reqIf.CoreContent, null) + { + Identifier = "target" + }; + + var specRelation = new SpecRelation(this.reqIf.CoreContent, null) + { + Target = targetSpecObject + }; + + var specRelations = targetSpecObject.QuerySpecRelations(); + + Assert.That(specRelations.Single(), Is.EqualTo(specRelation)); + } + + [Test] + public void Verify_that_QuerySpecRelations_returns_empty_when_no_relations_exist() + { + var specObject = new SpecObject + { + ReqIFContent = this.reqIf.CoreContent + }; + + Assert.That(specObject.QuerySpecRelations(), Is.Empty); + } + + [Test] + public void Verify_that_QuerySpecRelations_throws_when_specObject_is_null() + { + Assert.That(() => SpecObjectExtensions.QuerySpecRelations(null), Throws.ArgumentNullException); + } + } +} diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectTypeExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectTypeExtensionsTestFixture.cs index 5e29ab1..71a9896 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectTypeExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecObjectTypeExtensionsTestFixture.cs @@ -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; /// /// Suite of tests for the class. @@ -45,20 +46,49 @@ public void SetUp() } [Test] - public void Verify_that_QueryReferencingSpecObject_returns_expected_results() - { - var specObjectType = (SpecObjectType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "requirement"); - - var specObjects = specObjectType.QueryReferencingSpecObjects(); - - Assert.That(specObjects.Count(), Is.EqualTo(3)); - } - - [Test] - public void Verify_that_on_QueryReferencingSpecifications_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set() - { - var specObjectType = new SpecObjectType(); - + public void Verify_that_QueryReferencingSpecObject_returns_expected_results() + { + var specObjectType = (SpecObjectType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "requirement"); + + var specObjects = specObjectType.QueryReferencingSpecObjects(); + + Assert.That(specObjects.Count(), Is.EqualTo(3)); + } + + [Test] + public void Verify_that_QueryReferencingSpecObject_returns_empty_when_none_reference_type() + { + var reqIf = new ReqIF + { + CoreContent = new ReqIFContent() + }; + + var specObjectType = new SpecObjectType { ReqIFContent = reqIf.CoreContent }; + var otherSpecObjectType = new SpecObjectType { ReqIFContent = reqIf.CoreContent }; + + var specObject = new SpecObject(reqIf.CoreContent, null) + { + Type = otherSpecObjectType + }; + + reqIf.CoreContent.SpecObjects.Add(specObject); + + var result = specObjectType.QueryReferencingSpecObjects(); + + Assert.That(result, Is.Empty); + } + + [Test] + public void Verify_that_QueryReferencingSpecObject_throws_when_specObjectType_is_null() + { + Assert.That(() => SpecObjectTypeExtensions.QueryReferencingSpecObjects(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_on_QueryReferencingSpecifications_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set() + { + var specObjectType = new SpecObjectType(); + Assert.That(() => specObjectType.QueryReferencingSpecObjects(), Throws.Exception.TypeOf() .With.Message.Contains("The owning ReqIFContent of the SpecObjectType is not set.")); diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationExtensionsTestFixture.cs index 0a3ae73..336a057 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationExtensionsTestFixture.cs @@ -57,25 +57,66 @@ public async Task SetUp() } [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); - } - } + 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_QuerySpecHierarchies_throws_when_specification_is_null() + { + Assert.That(() => SpecificationExtensions.QueryAllContainedSpecHierarchies(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_SpecHierarchy_QueryAllContainedSpecHierarchies_returns_expected_results() + { + var rootHierarchy = new SpecHierarchy(); + var childHierarchy = new SpecHierarchy(); + var grandChildHierarchy = new SpecHierarchy(); + + rootHierarchy.Children.Add(childHierarchy); + childHierarchy.Children.Add(grandChildHierarchy); + + var result = rootHierarchy.QueryAllContainedSpecHierarchies(); + + Assert.That(result, Is.EquivalentTo(new[] { childHierarchy, grandChildHierarchy })); + } + + [Test] + public void Verify_that_QueryAllContainedSpecObjects_returns_the_expected_results() + { + var specification = this.reqIf.CoreContent.Specifications.Single(x => x.Identifier == "_o7scS6dbEeafNduaIhMwQg"); + + Assert.That(specification.QueryAllContainedSpecObjects().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); + } + + [Test] + public void Verify_that_QueryAttributeDefinitions_throws_when_specification_is_null() + { + Assert.That(() => SpecificationExtensions.QueryAttributeDefinitions(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_SpecHierarchy_QueryAllContainedSpecHierarchies_throws_when_specHierarchy_is_null() + { + Assert.That(() => SpecHierarchyExtensions.QueryAllContainedSpecHierarchies(null), Throws.ArgumentNullException); + } + } } \ No newline at end of file diff --git a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationTypeExtensionsTestFixture.cs b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationTypeExtensionsTestFixture.cs index 3f252fb..752b52a 100644 --- a/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationTypeExtensionsTestFixture.cs +++ b/ReqIFSharp.Extensions.Tests/ReqIFExtensions/SpecificationTypeExtensionsTestFixture.cs @@ -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; /// /// Suite of tests for the class. @@ -45,20 +46,49 @@ public void SetUp() } [Test] - public void Verify_that_QueryReferencingSpecifications_returns_expected_results() - { - var specificationType = (SpecificationType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "specificationtype"); - - var specObjects = specificationType.QueryReferencingSpecifications(); - - Assert.That(specObjects.Count(), Is.EqualTo(2)); - } - - [Test] - public void Verify_that_on_QueryReferencingSpecifications_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set() - { - var specificationType = new SpecificationType(); - + public void Verify_that_QueryReferencingSpecifications_returns_expected_results() + { + var specificationType = (SpecificationType)this.reqIf.CoreContent.SpecTypes.Single(x => x.Identifier == "specificationtype"); + + var specObjects = specificationType.QueryReferencingSpecifications(); + + Assert.That(specObjects.Count(), Is.EqualTo(2)); + } + + [Test] + public void Verify_that_QueryReferencingSpecifications_returns_empty_when_none_reference_type() + { + var reqIf = new ReqIF + { + CoreContent = new ReqIFContent() + }; + + var specificationType = new SpecificationType { ReqIFContent = reqIf.CoreContent }; + var otherSpecificationType = new SpecificationType { ReqIFContent = reqIf.CoreContent }; + + var specification = new Specification(reqIf.CoreContent, null) + { + Type = otherSpecificationType + }; + + reqIf.CoreContent.Specifications.Add(specification); + + var result = specificationType.QueryReferencingSpecifications(); + + Assert.That(result, Is.Empty); + } + + [Test] + public void Verify_that_QueryReferencingSpecifications_throws_when_specificationType_is_null() + { + Assert.That(() => SpecificationTypeExtensions.QueryReferencingSpecifications(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_on_QueryReferencingSpecifications_NullReferenceException_is_thrown_when_owning_ReqIFContent_is_not_set() + { + var specificationType = new SpecificationType(); + Assert.That(() => specificationType.QueryReferencingSpecifications(), Throws.Exception.TypeOf() .With.Message.Contains("The owning ReqIFContent of the SpecificationType is not set."));