Skip to content

Commit

Permalink
add rdashtest case
Browse files Browse the repository at this point in the history
  • Loading branch information
recca5p committed Dec 4, 2024
1 parent 938fa9d commit 6479e54
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 41 deletions.
1 change: 1 addition & 0 deletions e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public MainWindow()
RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider();
RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices();
RevealSdkSettings.DataSources.RegisterMySql();
RevealSdkSettings.License = "eyJhbGciOiJQUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImEwV1ZNMDAwMDAwTDY1ZDJBQyIsInByb2R1Y3RfY29kZSI6IkE4IiwicHJvZHVjdF92ZXJzaW9uIjoiNzAiLCJzZXJ2aWNlX2VuZF9kYXRlIjoiMjAzMS0wMS0wM1QwMDowMDowMC4wMDAwMDAwWiIsInNlcnZpY2VfbGV2ZWwiOiJQcmlvcml0eSIsImlhdCI6MTcwNjYzMTIzMCwibmJmIjoxNzA2NjMxMjMwfQ.NW9e1Nyo5PMBz9TYnF2DNrgW6EIb2dCRVzkEN_ovMBcM3vp4oCBmjBIRTs492EgpRktM7Bm1TMtfZO0A3wPEhR5sn9_1qxSWGmlyjF1ncFgT5zrEpXqfMzNx3DA9k7aJcD7VzcErXiF2RHTukHdP6x1jXBzBFJVbBBai806mOOnzoSp2C3584EmYE2ZQR9ArjcUk_8aoObh_YwtEGMoUsU1r_MKdoeZaHeiRVRpw6HcZV4RMqgeh8TqWCGHtgFSKeUCpD0XQcL7MIa71MLZ-NB1vVBykfaYmYIq4UQd9R6QThmapr48A_Mu8xmEnD_B1A7BlwqsqXTBCXFP03wRPGw";

_revealView.LinkedDashboardProvider = (string dashboardId, string linkTitle) =>
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using System.IO;
using System;
using Xunit;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Reveal.Sdk.Dom.Visualizations;
using Reveal.Sdk.Dom.Core.Serialization;

namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
{
Expand Down Expand Up @@ -36,5 +43,76 @@ public void ProcessDataOnServer_SetsAndGetsValue_WithInputs()
Assert.True(item.ProcessDataOnServer);
Assert.True(item.Properties.GetValue<bool>("ServerAggregation"));
}

[Fact]
public void RDashDocument_HasCorrectDataSourceItem_WhenLoadFromFile()
{
// Arrange
var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestMySQL.rdash");

// Act
var document = RdashDocument.Load(filePath);
var dataSource = document.DataSources.FirstOrDefault();
var dataSourceItem = document.Visualizations.FirstOrDefault().DataDefinition.DataSourceItem;

// Assert
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Equal(DataSourceProvider.MySQL, dataSource.Provider);
Assert.NotNull(dataSourceItem.Properties.GetValue<string>("Table"));
Assert.True(dataSourceItem.Properties.GetValue<bool>("ServerAggregation"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_ForMySQLDataSource()
{
// Arrange
var expectedJson = @"
{
""_type"": ""DataSourceItemType"",
""Id"": ""mySqlItemId"",
""Title"": ""MySQL DS Item"",
""DataSourceId"": ""mySqlId"",
""HasTabularData"": true,
""HasAsset"": false,
""Properties"": {},
""Parameters"": {}
}";

var dataSource = new MySQLDataSource()
{
Id = "mySqlId",
Title = "MySQL DS",
ProcessDataOnServerDefaultValue = true,
ProcessDataOnServerReadOnly = false,
Host = "mysqlserver.local",
Port = "3306",
Database = "northwind",
DefaultRefreshRate = "120",
};

var dataSourceItems = new MySqlDataSourceItem("DB Test", dataSource)
{
Id = "mySqlItemId",
Title = "MySQL DS Item",
Fields = new List<IField>
{
new TextField("_id"),
new TextField("name"),
}
};

var document = new RdashDocument("My Dashboard");
document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name"));

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

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}
}
79 changes: 54 additions & 25 deletions src/Reveal.Sdk.Dom.Tests/Data/DataSources/MySQLDataSourceFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Core.Serialization;
using Reveal.Sdk.Dom.Data;
using System.IO;
using System;
using Xunit;
using System.Linq;
using System.Collections.Generic;
using Reveal.Sdk.Dom.Visualizations;
using Xunit.Sdk;

namespace Reveal.Sdk.Dom.Tests.Data.DataSources
{
Expand All @@ -27,53 +34,75 @@ public void Constructor_InitializesPropertiesToDefaultValues_WhenInstanceIsCreat
Assert.NotNull(dataSource);
}

[Fact]
public void RDashDocument_HasCorrectDataSource_WhenLoadFromFile()
{
// Arrange
var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestMySQL.rdash");

// Act
var document = RdashDocument.Load(filePath);
var dataSource = document.DataSources.FirstOrDefault();

// Assert
Assert.Equal(DataSourceProvider.MySQL, dataSource.Provider);
Assert.NotNull(dataSource.Properties.GetValue<string>("ServerAggregationDefault"));
Assert.NotNull(dataSource.Properties.GetValue<string>("ServerAggregationReadOnly"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_ForMySQLDataSource()
{
// Arrange
var expectedJson = @"{
""_type"": ""DataSourceType"",
""Username"": ""username"",
""Password"": ""password"",
""Id"": ""mySqlId"",
""Provider"": ""MYSQL"",
""Description"": ""MySQL DS"",
""Subtitle"": ""Employees Table"",
""DefaultRefreshRate"": ""120"",
""Properties"": {
""ServerAggregationDefault"": true,
""ServerAggregationReadOnly"": false,
""Host"": ""mysqlserver.local"",
""Port"": ""3306"",
""Database"": ""northwind"",
""DefaultRefreshRate"": ""120"",
""Username"": ""username"",
""Password"": ""password""
}
var expectedJson = @"
{
""_type"": ""DataSourceType"",
""Id"": ""mySqlId"",
""Provider"": ""MYSQL"",
""Description"": ""MySQL DS"",
""DefaultRefreshRate"": ""120"",
""Properties"": {
""ServerAggregationDefault"": true,
""ServerAggregationReadOnly"": false,
""Host"": ""mysqlserver.local"",
""Port"": ""3306"",
""Database"": ""northwind"",
""DefaultRefreshRate"": ""120""
}
}";

var dataSource = new MySQLDataSource()
{
Id = "mySqlId",
Title = "MySQL DS",
Subtitle = "Employees Table",
ProcessDataOnServerDefaultValue = true,
ProcessDataOnServerReadOnly = false,
Host = "mysqlserver.local",
Port = "3306",
Database = "northwind",
DefaultRefreshRate = "120",
Username = "username",
Password = "password",
};

var dataSourceItems = new MySqlDataSourceItem("DB Test", dataSource)
{
Id = "mySqlItemId",
Title = "MySQL DS Item",
Fields = new List<IField>
{
new TextField("_id"),
new TextField("name"),
}
};

var document = new RdashDocument("My Dashboard");
document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name"));

// Act
var json = dataSource.ToJsonString();
var serializedDataSource = RdashSerializer.SerializeObject(dataSource);
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["DataSources"].FirstOrDefault();
var expectedJObject = JObject.Parse(expectedJson);
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(expectedJObject, actualJObject);
Expand Down
7 changes: 3 additions & 4 deletions src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
<None Update="Dashboards\Sales.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Dashboards\" />
<None Update="Dashboards\TestMySQL.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions src/Reveal.Sdk.Dom/Data/DataSources/MySQLDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,5 @@ public MySQLDataSource()
{
Provider = DataSourceProvider.MySQL;
}

public string Username
{
get => Properties.GetValue<string>("Username");
set => Properties.SetItem("Username", value);
}

public string Password
{
get => Properties.GetValue<string>("Password");
set => Properties.SetItem("Password", value);
}
}
}

0 comments on commit 6479e54

Please sign in to comment.