diff --git a/src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash new file mode 100644 index 00000000..1f6d7105 Binary files /dev/null and b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash differ diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/RestDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/RestDataSourceItemFixture.cs index 012fd482..d1061f4b 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/RestDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/RestDataSourceItemFixture.cs @@ -1,10 +1,14 @@ -using Reveal.Sdk.Dom.Core.Constants; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Constants; using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Core.Serialization; using Reveal.Sdk.Dom.Core.Utilities; using Reveal.Sdk.Dom.Data; using Reveal.Sdk.Dom.Visualizations; +using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using Xunit; @@ -404,5 +408,21 @@ public void UseCsv_Should_Add_TwoDataSources() Assert.Equal(DataSourceIds.CSV, document.DataSources[0].Id); Assert.Equal(DataSourceProvider.CSV, document.DataSources[0].Provider); } + + [Fact] + public void RDashDocument_HasCorrectDataSourceItem_WhenLoadFromFile() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestRest.rdash"); + + // Act + var document = RdashDocument.Load(filePath); + var dataSource = document.DataSources.LastOrDefault(); + var dataSourceItem = document.Visualizations.LastOrDefault().DataDefinition.DataSourceItem; + + // Assert + Assert.Equal(DataSourceProvider.REST, dataSource.Provider); + Assert.NotNull(dataSourceItem.Properties.GetValue("ServerAggregation")); + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs index b4476405..76f7de40 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs @@ -1,7 +1,12 @@ +using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using Newtonsoft.Json.Linq; using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Core.Serialization; using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSources @@ -104,5 +109,70 @@ public void Method_SetsAndGetsValue_WithDifferentInputs(string method) Assert.Equal(method, dataSource.Method); Assert.Equal(method, dataSource.Properties.GetValue("Method")); } + + [Fact] + public void RDashDocument_HasCorrectDataSource_WhenLoadFromFile() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestRest.rdash"); + + // Act + var document = RdashDocument.Load(filePath); + var dataSource = document.DataSources.LastOrDefault(); + + // Assert + Assert.Equal(DataSourceProvider.REST, dataSource.Provider); + Assert.NotNull(dataSource.Properties.GetValue("Url")); + Assert.NotNull(dataSource.Properties.GetValue("_rpUseAnonymousAuthentication")); + Assert.NotNull(dataSource.Properties.GetValue("_rpUsePreemptiveAuthentication")); + } + + [Fact] + public void ToJsonString_CreatesFormattedJson_ForRestDataSource() + { + // Arrange + var expectedJson = @" + { + ""_type"": ""DataSourceType"", + ""Id"": ""Rest"", + ""Provider"": ""REST"", + ""Description"": ""Rest DS"", + ""Subtitle"": ""Excel2Json"", + ""Properties"": {} + }"; + + var dataSource = new RestDataSource() + { + Id = "Rest", + Title = "Rest DS", + DefaultRefreshRate = "120", + Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9", + Subtitle = "Excel2Json" + }; + + var dataSourceItems = new RestDataSourceItem("DB Test", dataSource) + { + Id = "RestItem", + Title = "Rest DS Item", + Fields = new List + { + new TextField("_id"), + new TextField("name"), + } + }; + + var document = new RdashDocument("My Dashboard"); + document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name")); + + // Act + RdashSerializer.SerializeObject(document); + var json = document.ToJsonString(); + var jObject = JObject.Parse(json); + var actualJObject = jObject["DataSources"].LastOrDefault(); + var expectedJObject = JObject.Parse(expectedJson); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } } \ No newline at end of file diff --git a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj index f3313f39..fe1efcb3 100644 --- a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj +++ b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj @@ -36,10 +36,9 @@ PreserveNewest - - - - + + PreserveNewest +