Skip to content

[Add] methods to build a ReqIF document in code; fixes #85 - #109

Merged
samatstariongroup merged 2 commits into
developmentfrom
GH85
Oct 24, 2026
Merged

samatstariongroup merged 2 commits into
developmentfrom
GH85

Conversation

@samatstariongroup

@samatstariongroup samatstariongroup commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #85.

What changes

  • Methods to build a document in code. Each one adds the new element to its owner, sets its back-references and, except for attribute values, gives it a valid identifier (_ + GUID) and a LastChange of now.
    • ReqIF.Create(title): a document with a header and a content.
    • ReqIFContent.CreateDatatypeDefinition… for all seven datatypes, CreateSpecObjectType, CreateSpecificationType, CreateSpecRelationType, CreateRelationGroupType, CreateSpecObject, CreateSpecification, CreateSpecRelation, CreateRelationGroup.
    • DatatypeDefinitionEnumeration.CreateEnumValue, SpecType.CreateAttributeDefinition and SpecElementWithAttributes.CreateAttributeValue, with an overload per kind.
    • Specification.AddChild and SpecHierarchy.AddChild.
  • Identifiable.CreateIdentifier() returns a valid xsd:ID; Identifiable.MarkAsChanged() sets LastChange to now.
  • Argument checks, following the ReqIF 1.2 specification:
    • a long name is required where the spec makes it mandatory (attribute definitions, enum values, relation groups);
    • an element of another document is rejected;
    • CreateAttributeValue throws when the element has no type (InvalidOperationException) or the definition has no datatype, is not an attribute of the element's type, already has a value, or the value does not fit its datatype (range, max length, enumeration literals, multi-valued);
    • XHTML must be well-formed with one xhtml:div or xhtml:p root; an undeclared xhtml prefix gets its xmlns:xhtml, and xhtml:object elements get their ExternalObject.
  • Fix: an infinite real value was written as Infinity, which is not a valid xsd:double; it is now written as INF / -INF, as the datatype limits already were.

Notes for the reviewer

  • Behaviour change: the XHTML TheValue and TheOriginalValue are now read as they are in the document; before, whitespace at the start and end was trimmed, so a document read and written again could differ. Listed under Changed, not marked breaking; code that compares TheValue or checks StartsWith("<xhtml:div") on an indented document will see the leading whitespace.
  • A relation group can have values, as the ReqIF metamodel allows, but the XML schema has no VALUES on RELATION-GROUP, so such a document is not schema-valid. Documented in the XML docs and the changelog.
  • Deliberately lenient: CreateDatatypeDefinitionReal accepts NaN limits, and ReqIF.Create(null) writes an empty TITLE.
  • The wiki page "Writing ReqIF" mentioned in the issue still has to be updated; it is not part of this repository.

Review recommendations not addressed here

A pre-PR review (code reviewer and test-gap finder) made these recommendations; they are left out of this PR on purpose:

  • Marking the XHTML whitespace change as breaking in the changelog (see the note above); it stays under Changed.
  • Test gaps:
    • no test for ReqIF.Create(null) being written with an empty TITLE and valid against the schema, sync and async;
    • the XHTML prefix declaration has an exact expected result only for CRLF line breaks before the root, not for LF or a lone CR;
    • an owner that belongs to no document (for example new Specification().AddChild(...)) is never tested, and the test for an element of no document only asserts that nothing throws;
    • the logger-factory test leaves out the XHTML and numeric kinds.
  • Behaviour no doc pins down: the same enumeration literal passed twice is accepted, a processing instruction before the XHTML root is accepted, and a string's MaxLength counts UTF-16 code units.

Tests

  • CreateElementsTestFixture (40 tests): every create method and overload, every error path, schema validity of built, empty and extended documents (sync and async), a full write/read round trip, and infinite real values.
  • CreatedDocumentQueriesTestFixture: all ReqIFSharp.Extensions Query* methods on a document built only with the new methods (the issue's acceptance criterion).

dotnet build ReqIFSharp.sln -c Release: 0 warnings. dotnet test ReqIFSharp.sln: 688 passed.

🤖 Generated with Claude Code

samatstarion and others added 2 commits October 23, 2026 10:53
- add ReqIF.Create, the Create... methods on ReqIFContent for every datatype, spec type and spec element, DatatypeDefinitionEnumeration.CreateEnumValue, SpecType.CreateAttributeDefinition and SpecElementWithAttributes.CreateAttributeValue (an overload per kind), and AddChild on Specification and SpecHierarchy; each sets a valid identifier, LastChange and the back-references
- add Identifiable.CreateIdentifier and Identifiable.MarkAsChanged
- validate the arguments: mandatory long names, elements of another document, an element without a type or a definition without a datatype, values outside their datatype, and XHTML that cannot be a value
- read the XHTML TheValue and TheOriginalValue without trimming them
- write infinite real values as INF and -INF instead of Infinity, which is not a valid xsd:double
- add CreateElementsTestFixture and CreatedDocumentQueriesTestFixture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- AttributeValueXHTML.EnsureValidValue -> ValidateXhtml
- ReqIFContent.EnsureSameContent -> ValidateSameContent
- SpecElementWithAttributes.EnsureValueCanBeCreated -> ValidateValueCanBeCreated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@samatstariongroup
samatstariongroup merged commit 3633322 into development Oct 24, 2026
8 checks passed
@samatstariongroup
samatstariongroup deleted the GH85 branch October 24, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Helpers to create and change elements with valid identifiers, LastChange and ReqIFContent references

1 participant