diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs index 5ee572e7..555717ae 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs @@ -1,4 +1,5 @@ -using Reveal.Sdk.Dom.Data; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Data; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems @@ -59,5 +60,49 @@ public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndDataSource(st Assert.NotSame(dataSource, dataSourceItem.DataSource); Assert.IsType(dataSourceItem.DataSource); } + + [Fact] + public void ToJsonString_CreateExpectedRevealJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceItemType"", + ""Id"": ""azureSqlDsItemId"", + ""Title"": ""Azure SQL DSItem"", + ""Subtitle"": ""Azure SQL DS Item SubTitle"", + ""DataSourceId"": ""azureSqlId"", + ""HasTabularData"": true, + ""HasAsset"": false, + ""Properties"": { + ""ServerAggregation"": true, + ""Database"": ""reveal"", + ""Table"": ""Categories"" + }, + ""Parameters"": {} + }"; + var dataSource = new MicrosoftAzureSqlServerDataSource() + { + Id = "azureSqlId" + }; + var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem("Azure SQL DSItem", dataSource) + { + Id = "azureSqlDsItemId", + Subtitle = "Azure SQL DS Item SubTitle", + HasTabularData = true, + HasAsset = false, + ProcessDataOnServer = true, + Database = "reveal", + Table = "Categories" + //DefaultRefreshRate = "161" // TODO: Check the DefaultRefreshRate when get Json, after DefaultRefreshRate is moved to Settings field + }; + + // Act + var json = dataSourceItem.ToJsonString(); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs index e700e89d..16911a15 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs @@ -1,4 +1,5 @@ -using Reveal.Sdk.Dom.Core.Extensions; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; using Xunit; @@ -30,5 +31,53 @@ public void GetTrustServerCertificate_ReturnSameValue_WhenSet() Assert.Equal(trustServerCertificate, dataSource.TrustServerCertificate); Assert.Equal(trustServerCertificate, dataSource.Properties.GetValue("TrustServerCertificate")); } + + [Fact] + public void ToJsonString_CreateExpectedRevealJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceType"", + ""Id"": ""azureSqlId"", + ""Provider"": ""AZURE_SQL"", + ""Description"": ""Azure SQL DS"", + ""Subtitle"": ""Azure SQL DS Item"", + ""Properties"": { + ""ServerAggregationDefault"": false, + ""ServerAggregationReadOnly"": true, + ""Host"": ""revealtesting.database.windows.net"", + ""Port"": 1433, + ""Database"": ""reveal"", + ""Schema"": ""azureSchema"", + ""TrustServerCertificate"": false, + ""Encrypt"": false + }, + + }"; + var dataSource = new MicrosoftAzureSqlServerDataSource() + { + Id = "azureSqlId", + Title = "Azure SQL DS", + Subtitle = "Azure SQL DS Item", + ProcessDataOnServerDefaultValue = false, + ProcessDataOnServerReadOnly = true, + Host = "revealtesting.database.windows.net", + Port = 1433, + Database = "reveal", + Schema = "azureSchema", + TrustServerCertificate = false, + Encrypt = false, + //DefaultRefreshRate = "161" // TODO: Check the DefaultRefreshRate when get Json, after DefaultRefreshRate is moved to Settings field + }; + + // Act + var json = dataSource.ToJsonString(); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } } + \ No newline at end of file