Skip to content
Closed
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 @@ -26,6 +26,8 @@ namespace ReqIFSharp.Tests
using System.Threading;
using System.Xml;

using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

using ReqIFSharp;
Expand Down Expand Up @@ -86,5 +88,22 @@ public void Verify_That_WriteXmlAsync_Throws_Exception_When_Type_I_sNull()
Assert.That(async () => await attributeDefinitionEnumeration.WriteXmlAsync(writer, cancellationTokenSource.Token),
Throws.Exception.TypeOf<SerializationException>());
}

[Test]
public void Verify_that_when_invalid_IsMultiValued_Exception_is_raised()
{
var xml = """
<ATTRIBUTE-DEFINITION-ENUMERATION IDENTIFIER="AD1" MULTI-VALUED="not-a-bool" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinitionEnumeration = new AttributeDefinitionEnumeration(specType, NullLoggerFactory.Instance);

Assert.That(() => attributeDefinitionEnumeration.ReadXml(xmlReader),
Throws.InstanceOf<SerializationException>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace ReqIFSharp.Tests
using System.Threading;
using System.Xml;

using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

using ReqIFSharp;
Expand Down Expand Up @@ -159,5 +161,20 @@ public void Verify_that_ReadXmlAsync_throws_exception_when_cancelled()
Assert.That(async () => await attributeValueBoolean.ReadXmlAsync(xmlReader, cts.Token),
Throws.Exception.TypeOf<OperationCanceledException>());
}

[Test]
public void Verify_that_when_invalid_IsMultiValued_Exception_is_raised()
{
var xml = """
<ATTRIBUTE-VALUE-BOOLEAN THE-VALUE="not-a-boolean" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var attributeValueBoolean = new AttributeValueBoolean(NullLoggerFactory.Instance);

Assert.That(() => attributeValueBoolean.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace ReqIFSharp.Tests
using System.Threading;
using System.Xml;

using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

using ReqIFSharp;
Expand Down Expand Up @@ -160,5 +162,41 @@ public void Verify_that_ReadXmlAsync_throws_exception_when_cancelled()
Assert.That(async () => await attributeValueDate.ReadXmlAsync(xmlReader, cts.Token),
Throws.Exception.TypeOf<OperationCanceledException>());
}

[Test]
public void Verify_that_when_invalid_Value_Exception_is_raised()
{
var xml = """
<ATTRIBUTE-VALUE-DATE THE-VALUE="not-a-date" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionDate { SpecType = specType };

var attributeValueDate = new AttributeValueDate(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueDate.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}

[Test]
public void Verify_that_when_too_large_small_Value_Exception_is_raised()
{
var xml = """
<ATTRIBUTE-VALUE-DATE THE-VALUE="999-11-12" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionDate { SpecType = specType };

var attributeValueDate = new AttributeValueDate(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueDate.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ namespace ReqIFSharp.Tests
{
using System;
using System.IO;
using System.Threading;
using System.Runtime.Serialization;
using System.Threading;
using System.Xml;

using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

using ReqIFSharp;
Expand Down Expand Up @@ -158,5 +160,43 @@ public void Verify_that_ReadXmlAsync_throws_exception_when_cancelled()
Assert.That(async () => await attributeValueInteger.ReadXmlAsync(xmlReader, cts.Token),
Throws.Exception.TypeOf<OperationCanceledException>());
}

[Test]
public void Verify_that_when_too_large_Value_Exception_is_not_raised()
{
var xml = """
<ATTRIBUTE-VALUE-INTEGER THE-VALUE="9223372036854775808" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionInteger() { SpecType = specType };

var attributeValueInteger = new AttributeValueInteger(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueInteger.ReadXml(xmlReader), Throws.Nothing);

Assert.That(attributeValueInteger.TheValue, Is.EqualTo(0));
}

[Test]
public void Verify_that_when_too_invalid_Value_Exception_is_not_raised()
{
var xml = """
<ATTRIBUTE-VALUE-INTEGER THE-VALUE="not-an-integer" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionInteger() { SpecType = specType };

var attributeValueInteger = new AttributeValueInteger(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueInteger.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace ReqIFSharp.Tests
using System.Xml;

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

Expand Down Expand Up @@ -181,5 +182,43 @@ public void Verify_that_ReadXmlAsync_throws_exception_when_cancelled()
Assert.That(async () => await attributeValueReal.ReadXmlAsync(xmlReader, cts.Token),
Throws.Exception.TypeOf<OperationCanceledException>());
}

[Test]
public void Verify_that_when_too_large_Value_Exception_is_not_raised()
{
var xml = """
<ATTRIBUTE-VALUE-REAL THE-VALUE="1E+309" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionReal() { SpecType = specType };

var attributeValueReal = new AttributeValueReal(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueReal.ReadXml(xmlReader), Throws.Nothing);

Assert.That(attributeValueReal.TheValue, Is.EqualTo(double.PositiveInfinity));
}

[Test]
public void Verify_that_when_too_invalid_Value_Exception_is_not_raised()
{
var xml = """
<ATTRIBUTE-VALUE-REAL THE-VALUE="not-a-real" />
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var specType = new SpecificationType { ReqIFContent = new ReqIFContent() };
var attributeDefinition = new AttributeDefinitionReal() { SpecType = specType };

var attributeValueReal = new AttributeValueReal(attributeDefinition, NullLoggerFactory.Instance);

Assert.That(() => attributeValueReal.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}
}
}
117 changes: 117 additions & 0 deletions ReqIFSharp.Tests/Datatype/DatatypeDefinitionIntegerTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="DatatypeDefinitionIntegerTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2017-2025 Starion Group 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 ReqIFSharp.Tests
{
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;

using Microsoft.Extensions.Logging.Abstractions;

using NUnit.Framework;

using ReqIFSharp;

[TestFixture]
public class DatatypeDefinitionIntegerTestFixture
{
[Test]
public void Verify_that_when_MAX_is_too_large_exception_is_thrown()
{
var xml = """
<DATATYPE-DEFINITION-INTEGER IDENTIFIER="_IrT00AfhEeelU71CdMk83g" LAST-CHANGE="2017-03-13T12:35:17.083+01:00" LONG-NAME="T_Int" MAX="9223372036854775808" MIN="-100">
<ALTERNATIVE-ID>
<ALTERNATIVE-ID IDENTIFIER="_IrT00AfhEeelU71CdMk83g"/>
</ALTERNATIVE-ID>
</DATATYPE-DEFINITION-INTEGER>
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var datatypeDefinitionInteger = new DatatypeDefinitionInteger(NullLoggerFactory.Instance);

Assert.That(() => datatypeDefinitionInteger.ReadXml(xmlReader), Throws.Nothing);

Assert.That(datatypeDefinitionInteger.Max, Is.EqualTo(Int64.MaxValue));
}

[Test]
public void Verify_that_when_MAX_is_invalid_exception_is_thrown()
{
var xml = """
<DATATYPE-DEFINITION-INTEGER IDENTIFIER="_IrT00AfhEeelU71CdMk83g" LAST-CHANGE="2017-03-13T12:35:17.083+01:00" LONG-NAME="T_Int" MAX="not-an-integer" MIN="-100">
<ALTERNATIVE-ID>
<ALTERNATIVE-ID IDENTIFIER="_IrT00AfhEeelU71CdMk83g"/>
</ALTERNATIVE-ID>
</DATATYPE-DEFINITION-INTEGER>
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var datatypeDefinitionInteger = new DatatypeDefinitionInteger(NullLoggerFactory.Instance);

Assert.That(() => datatypeDefinitionInteger.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}

[Test]
public void Verify_that_when_MIN_is_too_large_exception_is_thrown()
{
var xml = """
<DATATYPE-DEFINITION-INTEGER IDENTIFIER="_IrT00AfhEeelU71CdMk83g" LAST-CHANGE="2017-03-13T12:35:17.083+01:00" LONG-NAME="T_Int" MAX="100" MIN="-9223372036854775809">
<ALTERNATIVE-ID>
<ALTERNATIVE-ID IDENTIFIER="_IrT00AfhEeelU71CdMk83g"/>
</ALTERNATIVE-ID>
</DATATYPE-DEFINITION-INTEGER>
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var datatypeDefinitionInteger = new DatatypeDefinitionInteger(NullLoggerFactory.Instance);

Assert.That(() => datatypeDefinitionInteger.ReadXml(xmlReader), Throws.Nothing);

Assert.That(datatypeDefinitionInteger.Min, Is.EqualTo(Int64.MinValue));
}

[Test]
public void Verify_that_when_MIN_is_invalid_exception_is_thrown()
{
var xml = """
<DATATYPE-DEFINITION-INTEGER IDENTIFIER="_IrT00AfhEeelU71CdMk83g" LAST-CHANGE="2017-03-13T12:35:17.083+01:00" LONG-NAME="T_Int" MAX="100" MIN="not-an-integer">
<ALTERNATIVE-ID>
<ALTERNATIVE-ID IDENTIFIER="_IrT00AfhEeelU71CdMk83g"/>
</ALTERNATIVE-ID>
</DATATYPE-DEFINITION-INTEGER>
""";

var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();

var datatypeDefinitionInteger = new DatatypeDefinitionInteger(NullLoggerFactory.Instance);

Assert.That(() => datatypeDefinitionInteger.ReadXml(xmlReader), Throws.InstanceOf<SerializationException>());
}
}
}
Loading
Loading