Skip to content

Commit

Permalink
Add unit tests for to JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
vulh-infragistics committed Dec 10, 2024
1 parent 0a81912 commit 597afb7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,5 +60,49 @@ public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndDataSource(st
Assert.NotSame(dataSource, dataSourceItem.DataSource);
Assert.IsType<MicrosoftAzureSqlServerDataSource>(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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -30,5 +31,53 @@ public void GetTrustServerCertificate_ReturnSameValue_WhenSet()
Assert.Equal(trustServerCertificate, dataSource.TrustServerCertificate);
Assert.Equal(trustServerCertificate, dataSource.Properties.GetValue<bool>("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);
}
}
}

0 comments on commit 597afb7

Please sign in to comment.