From f982a926ee57cb1f49cb0dd24a79bad5bdb6e146 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 16:37:51 +0700 Subject: [PATCH 1/3] Create Unit test for IFinanceExtensions --- .../Extensions/IFinanceExtensionsFixture.cs | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs new file mode 100644 index 00000000..87b21af5 --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs @@ -0,0 +1,217 @@ +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions +{ + public class IFinanceExtensionsFixture + { + [Fact] + public void SetOpen_UpdateOpen_WithFieldName() + { + // Arrange + var visualization = new MockIFiananceVisualization(); + var fieldName = "TestFieldName"; + var field = new NumberDataField(fieldName); + field.Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true + }; + var expectedOpen = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetOpen(fieldName); + + // Assert + Assert.Equivalent(expectedOpen, visualization.Opens); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void SetOpen_UpdateOpen_WithNumberDataField(bool isFormattingNull) + { + // Arrange + var visualization = new MockIFiananceVisualization(); + + var fieldFormat = isFormattingNull ? null : new NumberFormatting() + { + DecimalDigits = 2, + ShowGroupingSeparator = false + }; + var field = new NumberDataField("TestField") + { + Formatting = fieldFormat + }; + + var expectedOpen = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetOpen(field); + + // Assert + Assert.Equivalent(expectedOpen, visualization.Opens); + } + + [Fact] + public void SetClose_UpdateClose_WithFieldName() + { + // Arrange + var visualization = new MockIFiananceVisualization(); + var fieldName = "TestFieldName"; + var field = new NumberDataField(fieldName); + field.Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true + }; + var expectedClose = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetClose(fieldName); + + // Assert + Assert.Equivalent(expectedClose, visualization.Closes); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void SetClose_UpdateClose_WithNumberDataField(bool isFormattingNull) + { + // Arrange + var visualization = new MockIFiananceVisualization(); + + var fieldFormat = isFormattingNull ? null : new NumberFormatting() + { + DecimalDigits = 2, + ShowGroupingSeparator = false + }; + var field = new NumberDataField("TestField") + { + Formatting = fieldFormat + }; + + var expectedClose = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetClose(field); + + // Assert + Assert.Equivalent(expectedClose, visualization.Closes); + } + + [Fact] + public void SetHigh_UpdateHigh_WithFieldName() + { + // Arrange + var visualization = new MockIFiananceVisualization(); + var fieldName = "TestFieldName"; + var field = new NumberDataField(fieldName); + field.Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true + }; + var expectedHigh = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetHigh(fieldName); + + // Assert + Assert.Equivalent(expectedHigh, visualization.Highs); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void SetHigh_UpdateHigh_WithNumberDataField(bool isFormattingNull) + { + // Arrange + var visualization = new MockIFiananceVisualization(); + + var fieldFormat = isFormattingNull ? null : new NumberFormatting() + { + DecimalDigits = 2, + ShowGroupingSeparator = false + }; + var field = new NumberDataField("TestField") + { + Formatting = fieldFormat + }; + + var expectedHigh = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetHigh(field); + + // Assert + Assert.Equivalent(expectedHigh, visualization.Highs); + } + + [Fact] + public void SetLow_UpdateLow_WithFieldName() + { + // Arrange + var visualization = new MockIFiananceVisualization(); + var fieldName = "TestFieldName"; + var field = new NumberDataField(fieldName); + field.Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true + }; + var expectedLow = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetLow(fieldName); + + // Assert + Assert.Equivalent(expectedLow, visualization.Lows); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void SetLow_UpdateLow_WithNumberDataField(bool isFormattingNull) + { + // Arrange + var visualization = new MockIFiananceVisualization(); + + var fieldFormat = isFormattingNull ? null : new NumberFormatting() + { + DecimalDigits = 2, + ShowGroupingSeparator = false + }; + var field = new NumberDataField("TestField") + { + Formatting = fieldFormat + }; + + var expectedLow = new List { new MeasureColumn() { DataField = field } }; + + // Act + visualization.SetLow(field); + + // Assert + Assert.Equivalent(expectedLow, visualization.Lows); + } + + + private class MockIFiananceVisualization : IFinance + { + public List Opens { get; set; } = new List(); + + public List Highs { get; set; } = new List(); + + public List Lows { get; set; } = new List(); + + public List Closes { get; set; } = new List(); + } + } +} From ed82af36e3ed246d203e15db76450dc902d36250 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 16:42:08 +0700 Subject: [PATCH 2/3] Update unit tests to increase coverage --- .../Extensions/IFinanceExtensionsFixture.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs index 87b21af5..bd4dcdb3 100644 --- a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs @@ -14,7 +14,7 @@ public class IFinanceExtensionsFixture public void SetOpen_UpdateOpen_WithFieldName() { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Opens = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldName = "TestFieldName"; var field = new NumberDataField(fieldName); field.Formatting = new NumberFormatting() @@ -37,7 +37,7 @@ public void SetOpen_UpdateOpen_WithFieldName() public void SetOpen_UpdateOpen_WithNumberDataField(bool isFormattingNull) { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Opens = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldFormat = isFormattingNull ? null : new NumberFormatting() { @@ -62,7 +62,7 @@ public void SetOpen_UpdateOpen_WithNumberDataField(bool isFormattingNull) public void SetClose_UpdateClose_WithFieldName() { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Closes = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldName = "TestFieldName"; var field = new NumberDataField(fieldName); field.Formatting = new NumberFormatting() @@ -85,7 +85,7 @@ public void SetClose_UpdateClose_WithFieldName() public void SetClose_UpdateClose_WithNumberDataField(bool isFormattingNull) { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Closes = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldFormat = isFormattingNull ? null : new NumberFormatting() { @@ -110,7 +110,7 @@ public void SetClose_UpdateClose_WithNumberDataField(bool isFormattingNull) public void SetHigh_UpdateHigh_WithFieldName() { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Highs = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldName = "TestFieldName"; var field = new NumberDataField(fieldName); field.Formatting = new NumberFormatting() @@ -133,7 +133,7 @@ public void SetHigh_UpdateHigh_WithFieldName() public void SetHigh_UpdateHigh_WithNumberDataField(bool isFormattingNull) { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Highs = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldFormat = isFormattingNull ? null : new NumberFormatting() { @@ -158,7 +158,7 @@ public void SetHigh_UpdateHigh_WithNumberDataField(bool isFormattingNull) public void SetLow_UpdateLow_WithFieldName() { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Lows = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldName = "TestFieldName"; var field = new NumberDataField(fieldName); field.Formatting = new NumberFormatting() @@ -181,7 +181,7 @@ public void SetLow_UpdateLow_WithFieldName() public void SetLow_UpdateLow_WithNumberDataField(bool isFormattingNull) { // Arrange - var visualization = new MockIFiananceVisualization(); + var visualization = new MockIFiananceVisualization() { Lows = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } } }; var fieldFormat = isFormattingNull ? null : new NumberFormatting() { From 12f028e11bca950049cb53e2fe342da09fd708a9 Mon Sep 17 00:00:00 2001 From: Viktor Date: Tue, 24 Dec 2024 22:18:57 +0700 Subject: [PATCH 3/3] Update unit tests and Equivalent mode to strict --- .../Extensions/IFinanceExtensionsFixture.cs | 74 ++++++++++++------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs index bd4dcdb3..309e6cbc 100644 --- a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IFinanceExtensionsFixture.cs @@ -22,13 +22,13 @@ public void SetOpen_UpdateOpen_WithFieldName() DecimalDigits = 0, ShowGroupingSeparator = true }; - var expectedOpen = new List { new MeasureColumn() { DataField = field } }; + var expectedOpens = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetOpen(fieldName); // Assert - Assert.Equivalent(expectedOpen, visualization.Opens); + Assert.Equivalent(expectedOpens, visualization.Opens, true); } [Theory] @@ -41,21 +41,27 @@ public void SetOpen_UpdateOpen_WithNumberDataField(bool isFormattingNull) var fieldFormat = isFormattingNull ? null : new NumberFormatting() { - DecimalDigits = 2, - ShowGroupingSeparator = false + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = false, + CurrencySymbol = "AUD", + FormatType = NumberFormattingType.Currency, + NegativeFormat = NegativeFormatType.Parenthesis, + OverrideDefaultSettings = true, + SchemaTypeName = "TestSchema" }; var field = new NumberDataField("TestField") { Formatting = fieldFormat }; - var expectedOpen = new List { new MeasureColumn() { DataField = field } }; + var expectedOpens = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetOpen(field); // Assert - Assert.Equivalent(expectedOpen, visualization.Opens); + Assert.Equivalent(expectedOpens, visualization.Opens, true); } [Fact] @@ -70,13 +76,13 @@ public void SetClose_UpdateClose_WithFieldName() DecimalDigits = 0, ShowGroupingSeparator = true }; - var expectedClose = new List { new MeasureColumn() { DataField = field } }; + var expectedCloses = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetClose(fieldName); // Assert - Assert.Equivalent(expectedClose, visualization.Closes); + Assert.Equivalent(expectedCloses, visualization.Closes, true); } [Theory] @@ -89,21 +95,27 @@ public void SetClose_UpdateClose_WithNumberDataField(bool isFormattingNull) var fieldFormat = isFormattingNull ? null : new NumberFormatting() { - DecimalDigits = 2, - ShowGroupingSeparator = false + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = false, + CurrencySymbol = "AUD", + FormatType = NumberFormattingType.Currency, + NegativeFormat = NegativeFormatType.Parenthesis, + OverrideDefaultSettings = true, + SchemaTypeName = "TestSchema" }; var field = new NumberDataField("TestField") { Formatting = fieldFormat }; - var expectedClose = new List { new MeasureColumn() { DataField = field } }; + var expectedCloses = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetClose(field); // Assert - Assert.Equivalent(expectedClose, visualization.Closes); + Assert.Equivalent(expectedCloses, visualization.Closes, true); } [Fact] @@ -118,13 +130,13 @@ public void SetHigh_UpdateHigh_WithFieldName() DecimalDigits = 0, ShowGroupingSeparator = true }; - var expectedHigh = new List { new MeasureColumn() { DataField = field } }; + var expectedHighs = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetHigh(fieldName); // Assert - Assert.Equivalent(expectedHigh, visualization.Highs); + Assert.Equivalent(expectedHighs, visualization.Highs, true); } [Theory] @@ -137,21 +149,27 @@ public void SetHigh_UpdateHigh_WithNumberDataField(bool isFormattingNull) var fieldFormat = isFormattingNull ? null : new NumberFormatting() { - DecimalDigits = 2, - ShowGroupingSeparator = false + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = false, + CurrencySymbol = "AUD", + FormatType = NumberFormattingType.Currency, + NegativeFormat = NegativeFormatType.Parenthesis, + OverrideDefaultSettings = true, + SchemaTypeName = "TestSchema" }; var field = new NumberDataField("TestField") { Formatting = fieldFormat }; - var expectedHigh = new List { new MeasureColumn() { DataField = field } }; + var expectedHighs = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetHigh(field); // Assert - Assert.Equivalent(expectedHigh, visualization.Highs); + Assert.Equivalent(expectedHighs, visualization.Highs, true); } [Fact] @@ -166,13 +184,13 @@ public void SetLow_UpdateLow_WithFieldName() DecimalDigits = 0, ShowGroupingSeparator = true }; - var expectedLow = new List { new MeasureColumn() { DataField = field } }; + var expectedLows = new List { new MeasureColumn() { DataField = field } }; // Act - visualization.SetLow(fieldName); + visualization.SetLow(field); // Assert - Assert.Equivalent(expectedLow, visualization.Lows); + Assert.Equivalent(expectedLows, visualization.Lows, true); } [Theory] @@ -185,21 +203,27 @@ public void SetLow_UpdateLow_WithNumberDataField(bool isFormattingNull) var fieldFormat = isFormattingNull ? null : new NumberFormatting() { - DecimalDigits = 2, - ShowGroupingSeparator = false + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = false, + CurrencySymbol = "AUD", + FormatType = NumberFormattingType.Currency, + NegativeFormat = NegativeFormatType.Parenthesis, + OverrideDefaultSettings = true, + SchemaTypeName = "TestSchema" }; var field = new NumberDataField("TestField") { Formatting = fieldFormat }; - var expectedLow = new List { new MeasureColumn() { DataField = field } }; + var expectedLows = new List { new MeasureColumn() { DataField = field } }; // Act visualization.SetLow(field); // Assert - Assert.Equivalent(expectedLow, visualization.Lows); + Assert.Equivalent(expectedLows, visualization.Lows, true); }