From 86504713f2385dadc4ed0c8f91af0fef33251955 Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 19 Dec 2024 21:50:35 +0700 Subject: [PATCH 1/5] create unit tests for ITargetExtensions --- .../Extensions/ITargetExtensionsFixture.cs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITargetExtensionsFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITargetExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITargetExtensionsFixture.cs new file mode 100644 index 0000000..7df472d --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITargetExtensionsFixture.cs @@ -0,0 +1,102 @@ +using Moq; +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 ITargetExtensionsFixture + { + [Fact] + public void SetTarget_UpdateTargets_WithFieldName() + { + // Arrange + var mockTarget = new Mock(); + var targets = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } }; + mockTarget.Setup(s => s.Targets).Returns(targets); + var targetObj = mockTarget.Object; + + var fieldName = "TestField"; + var numberField = new NumberDataField(fieldName); + var expectedTargetList = new List() { new MeasureColumn() { DataField = numberField } }; + + // Act + targetObj.SetTarget(fieldName); + + // Assert + Assert.Equivalent(expectedTargetList, targetObj.Targets); + } + + [Fact] + public void SetTarget_UpdateTargets_WithNumberDataField() + { + // Arrange + var mockTarget = new Mock(); + var targets = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } }; + mockTarget.Setup(s => s.Targets).Returns(targets); + var targetObj = mockTarget.Object; + + var fieldName = "TestField"; + var numberField = new NumberDataField(fieldName); + var expectedTargetList = new List() { new MeasureColumn() { DataField = numberField } }; + + // Act + targetObj.SetTarget(numberField); + + // Assert + Assert.Equivalent(expectedTargetList, targetObj.Targets); + } + + [Fact] + public void SetTargets_UpdateTargets_WithListFieldNames() + { + // Arrange + var mockTarget = new Mock(); + var targets = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } }; + mockTarget.Setup(s => s.Targets).Returns(targets); + var targetObj = mockTarget.Object; + + var fieldNames = new List() { "FirstField", "SecondField" }; + var expectedTargetList = fieldNames.Select(fieldName => new MeasureColumn() + { + DataField = new NumberDataField(fieldName) + }); + + // Act + targetObj.SetTargets(fieldNames.ToArray()); + + // Assert + Assert.Equivalent(expectedTargetList, targetObj.Targets); + } + + [Fact] + public void SetTargets_UpdateTargets_WithListNumberDataField() + { + // Arrange + var mockTarget = new Mock(); + var targets = new List() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } }; + mockTarget.Setup(s => s.Targets).Returns(targets); + var targetObj = mockTarget.Object; + + var numberFields = new List() + { + new NumberDataField("FirstField"), + new NumberDataField("SecondField"), + }; + var expectedTargetList = numberFields.Select(field => new MeasureColumn() + { + DataField = field + }); + + // Act + targetObj.SetTargets(numberFields.ToArray()); + + // Assert + Assert.Equivalent(expectedTargetList, targetObj.Targets); + } + } +} From 87192bd091d54cffe4346d392b489f43a13ee6f2 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 09:15:06 +0700 Subject: [PATCH 2/5] create unit tests for ITabularColumnsExtensions --- .../ITabularColumnsExtensionsFixture.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITabularColumnsExtensionsFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITabularColumnsExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITabularColumnsExtensionsFixture.cs new file mode 100644 index 0000000..144b3a2 --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ITabularColumnsExtensionsFixture.cs @@ -0,0 +1,32 @@ +using Moq; +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 ITabularColumnsExtensionsFixture + { + [Fact] + public void SetColumns_UpdateColumns_WithListFieldNames() + { + // Arrange + var mockTabularColumn = new Mock(); + mockTabularColumn.SetupGet(s => s.Columns).Returns(new List { new TabularColumn("InitialColumn") }); + var visualization = mockTabularColumn.Object; + + var fieldNames = new List { "FirstField", "SecondField" }; + var expectedColumns = fieldNames.Select(fieldName => new TabularColumn(fieldName)).ToList(); + + // Act + visualization.SetColumns(fieldNames.ToArray()); + + // Assert + Assert.Equivalent(expectedColumns, visualization.Columns); + } + } +} From f1a7677a1fae4c585acc7662299797a7be338f75 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 10:20:20 +0700 Subject: [PATCH 3/5] Create unit tests for IRowExtension class --- .../Extensions/IRowsExtensionsFixture.cs | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IRowsExtensionsFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IRowsExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IRowsExtensionsFixture.cs new file mode 100644 index 0000000..94ab5a4 --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IRowsExtensionsFixture.cs @@ -0,0 +1,94 @@ +using Moq; +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions +{ + public class IRowsExtensionsFixture + { + [Fact] + public void SetRow_UpdateRows_WithFieldName() + { + // Arrange + var mockRow = new Mock(); + mockRow.Setup(s => s.Rows).Returns(new List() { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockRow.Object; + + var fieldName = "TestField"; + var expectedRows = new List { new DimensionColumn() { DataField = new TextDataField(fieldName) } }; + + // Act + visualization.SetRow(fieldName); + + // Assert + Assert.Equivalent(expectedRows, visualization.Rows); + } + + [Fact] + public void SetRow_UpdateRows_WithDimensionDataField() + { + // Arrange + var mockRow = new Mock(); + mockRow.Setup(s => s.Rows).Returns(new List() { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockRow.Object; + + var mockDimensionDataField = new Mock("TestField"); + var field = mockDimensionDataField.Object; + var expectedRows = new List { new DimensionColumn() { DataField = field } }; + + // Act + visualization.SetRow(field); + + // Assert + Assert.Equivalent(expectedRows, visualization.Rows); + } + + [Fact] + public void SetRows_UpdateRows_WithFieldNames() + { + // Arrange + var mockRow = new Mock(); + mockRow.Setup(s => s.Rows).Returns(new List() { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockRow.Object; + + var fieldNames = new List{ "FirstField", "SecondField" }; + var expectedVSRows = fieldNames.Select(fieldName => new DimensionColumn() { DataField= new TextDataField(fieldName) }); + + // Act + visualization.SetRows(fieldNames.ToArray()); + + // Assert + Assert.Equivalent(expectedVSRows, visualization.Rows); + } + + [Fact] + public void SetRows_UpdateRows_WithListDimensionDataFields() + { + // Arrange + var mockRow = new Mock(); + mockRow.Setup(s => s.Rows).Returns(new List() { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockRow.Object; + + var listFields = new List(); + var expectedRows = new List(); + + var firstMockDimensionDataField = new Mock("FirstFieldName"); + var firstField = firstMockDimensionDataField.Object; + expectedRows.Add(new DimensionColumn() { DataField = firstField }); + listFields.Add(firstField); + + var secondMockDimensionDataField = new Mock("SecondFieldName"); + var secondField = secondMockDimensionDataField.Object; + expectedRows.Add(new DimensionColumn() { DataField = secondField }); + listFields.Add(secondField); + + // Act + visualization.SetRows(listFields.ToArray()); + + // Assert + Assert.Equivalent(expectedRows, visualization.Rows); + } + } +} From b976ff510e317efef69a0f259144f5dc755275f0 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 11:55:35 +0700 Subject: [PATCH 4/5] Create unit test for IMapExtensions --- .../Extensions/IMapExtensionsFixture.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IMapExtensionsFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IMapExtensionsFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IMapExtensionsFixture.cs new file mode 100644 index 0000000..ad105e4 --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/IMapExtensionsFixture.cs @@ -0,0 +1,33 @@ +using Moq; +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 IMapExtensionsFixture + { + [Fact] + public void SetMap_UpdateMap_WithMapName() + { + // Arrange + var map = new MockMap(); + var expectedMapName = "TestMap"; + + // Act + map.SetMap(expectedMapName); + + // Assert + Assert.Equal(expectedMapName, map.Map); + } + + private class MockMap : IMap + { + public string Map { get; set; } + } + } +} From 2bc58930735e712c536db0b77a5fda6ce3d7054a Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 20 Dec 2024 15:12:41 +0700 Subject: [PATCH 5/5] Create unit test for ILabelsExtensions --- .../Extensions/ILabelsExtensions.csFixture.cs | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ILabelsExtensions.csFixture.cs diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ILabelsExtensions.csFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ILabelsExtensions.csFixture.cs new file mode 100644 index 0000000..aabd94b --- /dev/null +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/Extensions/ILabelsExtensions.csFixture.cs @@ -0,0 +1,104 @@ +using Moq; +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 ILabelsExtensions + { + [Fact] + public void SetLabel_UpdateLabels_WithFieldName() + { + // Arrange + var mockLabel = new Mock(); + mockLabel.Setup(x => x.Labels).Returns(new List { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockLabel.Object; + + var fieldName = "TestName"; + var expectedLabels = new List { new DimensionColumn() { DataField = new TextDataField(fieldName) } }; + + // Act + visualization.SetLabel(fieldName); + + // Assert + Assert.Equivalent(expectedLabels, visualization.Labels); + } + + [Fact] + public void SetLabel_UpdateLabels_WithDimensionDataField() + { + // Arrange + var mockLabel = new Mock(); + mockLabel.Setup(x => x.Labels).Returns(new List { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockLabel.Object; + + var mockDimensionDataField = new Mock("TestField"); + var dimensionDataField = mockDimensionDataField.Object; + var expectedLabels = new List { new DimensionColumn() { DataField = dimensionDataField } }; + + // Act + visualization.SetLabel(dimensionDataField); + + // Assert + Assert.Equivalent(expectedLabels, visualization.Labels); + } + + [Fact] + public void SetLabels_UpdateLabels_WithListFieldNames() + { + // Arrange + var mockLabel = new Mock(); + mockLabel.Setup(x => x.Labels).Returns(new List { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockLabel.Object; + + var listFieldNames = new List + { + "FirstField", + "SecondField" + }; + var expectedLabels = listFieldNames.Select(fieldName => new DimensionColumn() + { + DataField = new TextDataField(fieldName) + }).ToList(); + + // Act + visualization.SetLabels(listFieldNames.ToArray()); + + // Assert + Assert.Equivalent(expectedLabels, visualization.Labels); + } + + [Fact] + public void SetLabels_UpdateLabels_WithListDimensionDateFields() + { + // Arrange + var mockLabel = new Mock(); + mockLabel.Setup(x => x.Labels).Returns(new List { new DimensionColumn() { DataField = new TextDataField("InitialField") } }); + var visualization = mockLabel.Object; + + var listFields = new List(); + var expectedLabels = new List(); + + var mockDimensionDataField1 = new Mock("FirstField"); + var firstField = mockDimensionDataField1.Object; + listFields.Add(firstField); + expectedLabels.Add(new DimensionColumn(firstField)); + + var mockDimensionDataField2 = new Mock("SecondField"); + var secondField = mockDimensionDataField2.Object; + listFields.Add(secondField); + expectedLabels.Add(new DimensionColumn(secondField)); + + // Act + visualization.SetLabels(listFields.ToArray()); + + // Assert + Assert.Equivalent(expectedLabels, visualization.Labels); + } + } +}