From ff0bb93f0b9738caa6cfca7ecec250ceb1b4e72c Mon Sep 17 00:00:00 2001 From: Viktor Date: Tue, 7 Jan 2025 17:16:21 +0700 Subject: [PATCH] Add UT for ToJsonString method --- ...catorTargetVisualizationDataSpecFixture.cs | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Visualizations/VisualizationSpecs/IndicatorTargetVisualizationDataSpecFixture.cs b/src/Reveal.Sdk.Dom.Tests/Visualizations/VisualizationSpecs/IndicatorTargetVisualizationDataSpecFixture.cs index fadc65d6..beae14dd 100644 --- a/src/Reveal.Sdk.Dom.Tests/Visualizations/VisualizationSpecs/IndicatorTargetVisualizationDataSpecFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Visualizations/VisualizationSpecs/IndicatorTargetVisualizationDataSpecFixture.cs @@ -1,6 +1,8 @@ -using Reveal.Sdk.Dom.Core.Constants; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Constants; using Reveal.Sdk.Dom.Visualizations; using Reveal.Sdk.Dom.Visualizations.VisualizationSpecs; +using System.Collections.Generic; using Xunit; namespace Reveal.Sdk.Dom.Tests.Visualizations.VisualizationSpecs @@ -18,5 +20,48 @@ public void Constructor_FieldsHaveDefaultValue_WithoutParameters() Assert.Equal(KpiGoalPeriod.YearToDate, indicatorTargetVSDataSpec.DateFilterType); Assert.Equal(SchemaTypeNames.IndicatorTargetVisualizationDataSpecType, indicatorTargetVSDataSpec.SchemaTypeName); } + + [Fact] + public void ToJsonString_CreateCorrectJsonString_WithoutCondition() + { + // Arrange + var expectedJson = """ + { + "_type": "AssetVisualizationSettingsType", + "Target": [], + "DateFilterType": "PreviousMonth", + "CustomDateRange": {}, + "Date": { + "_type": "DimensionColumnSpecType" + }, + "Value": [], + "AdHocFields": 11, + "FormatVersion": 2, + "AdHocExpandedElements": [], + "Rows": [] + } + """; + var indicatorTargetVSDataSpec = new IndicatorTargetVisualizationDataSpec() + { + SchemaTypeName = SchemaTypeNames.AssetVisualizationSettingsType, + Value = new List(), + AdHocExpandedElements = new List(), + AdHocFields = 11, + CustomDateRange = new DateRange(), + Date = new DimensionColumn(), + DateFilterType = KpiGoalPeriod.PreviousMonth, + FormatVersion = 2, + Rows = new List(), + Target = new List(), + }; + + // Act + var actualJson = indicatorTargetVSDataSpec.ToJsonString(); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(actualJson); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } }