Skip to content

Commit

Permalink
add UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan Phat VO authored and Tan Phat VO committed Dec 11, 2024
1 parent daa4530 commit fc99670
Showing 1 changed file with 88 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,77 +58,99 @@ public void RDashDocument_HasCorrectDataSource_WhenLoadFromFile()
Assert.NotNull(webServiceDataSource.Properties.GetValue<string>("_rpUseAnonymousAuthentication"));
}

//[Fact]
//public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
//{
// // Arrange
// var expectedJson =
// """
// {
// "_type": "DataSourceItemType",
// "Id": "webServiceItemId",
// "Title": "Sales by Category",
// "Subtitle": "Excel2Json",
// "DataSourceId": "__JSON",
// "HasTabularData": true,
// "HasAsset": false,
// "Properties": {},
// "Parameters": {},
// "ResourceItem": {
// "_type": "DataSourceItemType",
// "Id": "webServiceItemId",
// "Title": "DB Test",
// "Subtitle": "Excel2Json",
// "DataSourceId": "JSON",
// "HasTabularData": true,
// "HasAsset": false,
// "Properties": {
// "Url": "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"
// },
// "Parameters": {}
// }
// }
// """;
[Fact]
public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
{
// Arrange
var expectedJson =
"""
{
"_type": "DataSourceItemType",
"Id": "webServiceItemId",
"Title": "Sales by Category",
"Subtitle": "Excel2Json",
"DataSourceId": "__JSON",
"HasTabularData": true,
"HasAsset": false,
"Properties": {},
"Parameters": {
"config": {
"iterationDepth": 0,
"columnsConfig": [
{
"key": "CategoryID",
"type": 1
},
{
"key": "CategoryName",
"type": 0
},
{
"key": "ProductName",
"type": 0
},
{
"key": "ProductSales",
"type": 1
}
]
}
},
"ResourceItem": {
"_type": "DataSourceItemType",
"Id": "webServiceItemId",
"Title": "DB Test",
"Subtitle": "Excel2Json",
"DataSourceId": "JSON",
"HasTabularData": true,
"HasAsset": false,
"Properties": {
"Url": "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"
},
"Parameters": {}
}
}
""";

// var dataSource = new DataSource()
// {
// Id = "JSON",
// Title = "JSON Data Source",
// Subtitle = "JSON Data Source Subtitle",
// };
var dataSource = new DataSource()
{
Id = "JSON",
Title = "JSON Data Source",
Subtitle = "JSON Data Source Subtitle",
};

// var dataSourceItems = new WebServiceDataSourceItem("DB Test", dataSource)
// {
// Id = "webServiceItemId",
// Title = "Sales by Category",
// Subtitle = "Excel2Json",
// Uri = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9",
// Fields = new List<IField>
// {
// new NumberField("CategoryID"),
// new TextField("CategoryName"),
// new TextField("ProductName"),
// new NumberField("ProductSales"),
// }
// };
var dataSourceItems = new WebServiceDataSourceItem("DB Test", dataSource)
{
Id = "webServiceItemId",
Title = "Sales by Category",
Subtitle = "Excel2Json",
Uri = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9",
Fields = new List<IField>
{
new NumberField("CategoryID"),
new TextField("CategoryName"),
new TextField("ProductName"),
new NumberField("ProductSales"),
}
};

// var document = new RdashDocument("My Dashboard");
// document.Visualizations.Add(
// new ColumnChartVisualization("Test List", dataSourceItems)
// .SetLabel("CategoryName")
// .SetValue("ProductName")
// );
var document = new RdashDocument("My Dashboard");
document.Visualizations.Add(
new ColumnChartVisualization("Test List", dataSourceItems)
.SetLabel("CategoryName")
.SetValue("ProductName")
);

// var expectedJObject = JObject.Parse(expectedJson);
var expectedJObject = JObject.Parse(expectedJson);

// // Act
// RdashSerializer.SerializeObject(document);
// var json = document.ToJsonString();
// var jObject = JObject.Parse(json);
// var actualJObject = jObject["Widgets"].FirstOrDefault()["DataSpec"]["DataSourceItem"];
// Act
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["Widgets"].FirstOrDefault()["DataSpec"]["DataSourceItem"];

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

0 comments on commit fc99670

Please sign in to comment.