From f1e37d29dc44cc02aef2830e09def765ae3b9b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20L=2E=20Charlier?= Date: Sun, 30 Dec 2018 16:05:03 +0100 Subject: [PATCH] Fix new set of bugs related to tolerance --- NBi.Core/Scalar/Comparer/ToleranceFactory.cs | 3 +- NBi.Testing/NBi.Testing.csproj | 1 + .../Scalar/Comparer/ToleranceFactoryTest.cs | 45 +++++++++++++++++++ .../Items/ResultSet/ColumnDefinitionXml.cs | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 NBi.Testing/Unit/Core/Scalar/Comparer/ToleranceFactoryTest.cs diff --git a/NBi.Core/Scalar/Comparer/ToleranceFactory.cs b/NBi.Core/Scalar/Comparer/ToleranceFactory.cs index ea173c8e1..bcbfe577a 100644 --- a/NBi.Core/Scalar/Comparer/ToleranceFactory.cs +++ b/NBi.Core/Scalar/Comparer/ToleranceFactory.cs @@ -21,7 +21,8 @@ public static Tolerance Instantiate(IColumnDefinition columnDefinition) public static Tolerance Instantiate(ColumnType type, string value) { - + if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)) + return None(type); Tolerance tolerance=null; switch (type) diff --git a/NBi.Testing/NBi.Testing.csproj b/NBi.Testing/NBi.Testing.csproj index 586a06382..bcdd87d96 100644 --- a/NBi.Testing/NBi.Testing.csproj +++ b/NBi.Testing/NBi.Testing.csproj @@ -333,6 +333,7 @@ + diff --git a/NBi.Testing/Unit/Core/Scalar/Comparer/ToleranceFactoryTest.cs b/NBi.Testing/Unit/Core/Scalar/Comparer/ToleranceFactoryTest.cs new file mode 100644 index 000000000..88aa08a53 --- /dev/null +++ b/NBi.Testing/Unit/Core/Scalar/Comparer/ToleranceFactoryTest.cs @@ -0,0 +1,45 @@ +using NBi.Core.ResultSet; +using NBi.Core.Scalar.Comparer; +using NBi.Xml.Items.ResultSet; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace NBi.Testing.Unit.Core.Scalar.Comparer +{ + public class ToleranceFactoryTest + { + [Test] + [TestCase(ColumnRole.Key)] + [TestCase(ColumnRole.Value)] + [TestCase(ColumnRole.Ignore)] + public void Instantiate_NoToleranceDefined_InstantiatedToNullOrNone(ColumnRole columnRole) + { + var colDef = new ColumnDefinitionXml() + { + Index = 0, + Role = columnRole, + Tolerance = string.Empty + }; + var tolerance = ToleranceFactory.Instantiate(colDef); + + Assert.That(Tolerance.IsNullOrNone(tolerance), Is.True); + } + + [Test] + [TestCase(ColumnType.Text)] + [TestCase(ColumnType.Numeric)] + [TestCase(ColumnType.DateTime)] + [TestCase(ColumnType.Boolean)] + public void Instantiate_NoToleranceDefined_InstantiatedToNullOrNone(ColumnType columnType) + { + var tolerance = ToleranceFactory.Instantiate(columnType, string.Empty); + Assert.That(Tolerance.IsNullOrNone(tolerance), Is.True); + } + } +} diff --git a/NBi.Xml/Items/ResultSet/ColumnDefinitionXml.cs b/NBi.Xml/Items/ResultSet/ColumnDefinitionXml.cs index 0a148e213..ef6f18ba5 100644 --- a/NBi.Xml/Items/ResultSet/ColumnDefinitionXml.cs +++ b/NBi.Xml/Items/ResultSet/ColumnDefinitionXml.cs @@ -41,7 +41,7 @@ public class ColumnDefinitionXml: IColumnDefinition [XmlIgnore()] public bool IsToleranceSpecified { - get => string.IsNullOrEmpty(Tolerance); + get => !string.IsNullOrEmpty(Tolerance); } [XmlIgnore()]