Skip to content

Commit

Permalink
Add ToJson unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vulh-infragistics committed Dec 6, 2024
1 parent 664eb16 commit da98be0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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.Data;
using Xunit;
Expand Down Expand Up @@ -63,5 +64,52 @@ public void GetProcessDataOnServer_ReturnSameValue_AfterSet()
Assert.Equal(expectedProcessDataOnServer, item.ProcessDataOnServer);
Assert.Equal(expectedProcessDataOnServer, item.Properties.GetValue<bool>("ServerAggregation"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
var expectedJson = @"{
""_type"": ""DataSourceItemType"",
""Id"": ""a60ab508-0ed4-46e4-8d90-c3a9c09c29b8"",
""Title"": ""SnowFlake DSI"",
""DataSourceId"": ""snowflake_ds"",
""HasTabularData"": true,
""HasAsset"": false,
""Properties"": {
""ServerAggregation"": true,
""Table"": ""CALL_CENTER"",
""Schema"": ""TPCDS_SF100TCL""
},
""Parameters"": {
""RPCustomQuery"": ""Select CC_CALL_CENTER_ID, CC_CALL_CENTER_SK from CALL_CENTER""
}
}";

var dataSource = new SnowflakeDataSource()
{
Id = "snowflake_ds",
};
var dataSourceItem = new SnowflakeDataSourceItem("SnowFlake DSI", dataSource)
{
Id = "a60ab508-0ed4-46e4-8d90-c3a9c09c29b8",
HasTabularData = true,
HasAsset = false,
ProcessDataOnServer = true,
Table = "CALL_CENTER",
Schema = "TPCDS_SF100TCL",
CustomQuery = "Select CC_CALL_CENTER_ID, CC_CALL_CENTER_SK from CALL_CENTER",
};

var expectedJObject = JObject.Parse(expectedJson);

// Act
var json = dataSourceItem.ToJsonString();
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 @@ -63,5 +64,51 @@ public void SetWarehouse_ReturnSameValue_AfterSetWarehouse(string warehouse)
Assert.Equal(warehouse, dataSource.Warehouse);
Assert.Equal(warehouse, dataSource.Properties.GetValue<string>("Warehouse"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
var expectedJson = @"{
""_type"": ""DataSourceType"",
""Id"": ""snowflake_ds"",
""Provider"": ""SNOWFLAKE"",
""Description"": ""Snowflake TEST"",
""Subtitle"": ""Snowflake TEST Subtitle"",
""Properties"": {
""ServerAggregationDefault"": true,
""ServerAggregationReadOnly"": false,
""Host"": ""gpiskyj-al16914.snowflakecomputing.com"",
""Database"": ""SNOWFLAKE_SAMPLE_DATA"",
""Account"": ""pqwkobs-xb90908"",
""Warehouse"": ""COMPUTE_WH"",
""Schema"": ""TPCDS_SF100TCL""
},
//""Settings"": {} // TODO: Update to check settings fields after Postgresql PR is merged
}";

var dataSource = new SnowflakeDataSource()
{
Id = "snowflake_ds",
Title = "Snowflake TEST",
Subtitle = "Snowflake TEST Subtitle",
ProcessDataOnServerDefaultValue = true,
ProcessDataOnServerReadOnly = false,
Host = "gpiskyj-al16914.snowflakecomputing.com",
Database = "SNOWFLAKE_SAMPLE_DATA",
Account = "pqwkobs-xb90908",
Warehouse = "COMPUTE_WH",
Schema = "TPCDS_SF100TCL",
};
var expectedJObject = JObject.Parse(expectedJson);

// Act
var json = dataSource.ToJsonString();
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(expectedJObject, actualJObject);

}
}
}

0 comments on commit da98be0

Please sign in to comment.