Skip to content

Commit

Permalink
ix the 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 10, 2024
1 parent d2bc093 commit f6e3032
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void Constructor_SetsTitleAndDataSource_WhenConstructed()

// Assert
Assert.Equal(title, item.Title);
Assert.Equal(dataSource, item.DataSource);
}

[Theory]
Expand Down Expand Up @@ -71,11 +70,44 @@ public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
""Id"": ""webServiceItemId"",
""Title"": ""Sales by Category"",
""Subtitle"": ""Excel2Json"",
""DataSourceId"": ""webServiceId"",
""DataSourceId"": ""__JSON"",
""HasTabularData"": true,
""HasAsset"": false,
""Properties"": {},
""Parameters"": {}
""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"": ""webServiceId"",
""HasTabularData"": true,
""HasAsset"": false,
""Properties"": {},
""Parameters"": {}
}
}";

var dataSource = new WebServiceDataSource()
Expand Down
117 changes: 105 additions & 12 deletions src/Reveal.Sdk.Dom.Tests/Data/DataSources/WebServiceDataSourceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,121 @@ public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
var expectedJson = @"
{
""_type"": ""DataSourceType"",
""Id"": ""webServiceId"",
""Id"": ""1821521e-0225-4768-80c2-28c89f55b256"",
""Provider"": ""WEBSERVICE"",
""Description"": ""Web Data Source"",
""Subtitle"": ""Web Data Source Subtitle"",
""Description"": ""JSON DS"",
""Subtitle"": ""JSON DS Subtitle"",
""Properties"": {}
}";

var dataSourceItems = new WebServiceDataSourceItem("DB Test", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" })
{
Id = "webServiceItemId",
Title = "Sales by Category",
Subtitle = "Excel2Json",
Url = "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 expectedJObject = JObject.Parse(expectedJson);

// Act
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["DataSources"].LastOrDefault();

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

[Fact]
public void ToJsonString_CreatesFormattedJsonUseCsv_ForWebServiceDataSource()
{
// Arrange
var expectedJson = @"
{
""_type"": ""DataSourceType"",
""Id"": ""a30dc863-47a4-4ea4-b9fb-9e8006281ce4"",
""Provider"": ""WEBSERVICE"",
""Description"": ""JSON DS"",
""Subtitle"": ""JSON DS Subtitle"",
""Properties"": {
""URL"": ""https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"",
""UseAnonymousAuthentication"": true
""Result-Type"": "".csv""
}
}";

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

var dataSourceItems = new WebServiceDataSourceItem("DB Test", dataSource)
dataSourceItems.UseCsv();

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

var expectedJObject = JObject.Parse(expectedJson);

// Act
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["DataSources"].LastOrDefault();

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

[Fact]
public void ToJsonString_CreatesFormattedJsonUseExcel_ForWebServiceDataSource()
{
// Arrange
var expectedJson = @"
{
""_type"": ""DataSourceType"",
""Id"": ""97018983-2f13-415b-a38c-e6ff4fa3f123"",
""Provider"": ""WEBSERVICE"",
""Description"": ""JSON DS"",
""Subtitle"": ""JSON DS Subtitle"",
""Properties"": {
""Result-Type"": "".xlsx""
}
}";

var dataSourceItems = new WebServiceDataSourceItem("DB Test", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" })
{
Id = "webServiceItemId",
Title = "Sales by Category",
Subtitle = "Excel2Json",
Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9",
Fields = new List<IField>
{
new NumberField("CategoryID"),
Expand All @@ -113,6 +204,8 @@ public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
}
};

dataSourceItems.UseExcel();

var document = new RdashDocument("My Dashboard");
document.Visualizations.Add(
new ColumnChartVisualization("Test List", dataSourceItems)
Expand All @@ -126,7 +219,7 @@ public void ToJsonString_CreatesFormattedJson_ForWebServiceDataSource()
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["DataSources"].FirstOrDefault();
var actualJObject = jObject["DataSources"].LastOrDefault();

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

0 comments on commit f6e3032

Please sign in to comment.