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); + } + } +} 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; } + } + } +} 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); + } + } +} 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); + } + } +} 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); + } + } +}