diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index a537859e..29da4abe 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -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) => { diff --git a/src/Reveal.Sdk.Dom.Tests/Dashboards/TestMySQL.rdash b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestMySQL.rdash new file mode 100644 index 00000000..38582c54 Binary files /dev/null and b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestMySQL.rdash differ diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MySqlDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MySqlDataSourceItemFixture.cs index dda57dd0..840af157 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MySqlDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MySqlDataSourceItemFixture.cs @@ -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 { @@ -36,5 +43,76 @@ public void ProcessDataOnServer_SetsAndGetsValue_WithInputs() Assert.True(item.ProcessDataOnServer); Assert.True(item.Properties.GetValue("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("Table")); + Assert.True(dataSourceItem.Properties.GetValue("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 + { + 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); + } } } \ No newline at end of file diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MySQLDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MySQLDataSourceFixture.cs index 3edc06dd..79f276d2 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MySQLDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MySQLDataSourceFixture.cs @@ -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 { @@ -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("ServerAggregationDefault")); + Assert.NotNull(dataSource.Properties.GetValue("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 + { + 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); diff --git a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj index f3313f39..5cfb7561 100644 --- a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj +++ b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj @@ -36,10 +36,9 @@ PreserveNewest - - - - + + PreserveNewest + diff --git a/src/Reveal.Sdk.Dom/Data/DataSources/MySQLDataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSources/MySQLDataSource.cs index 927609ef..b1148047 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSources/MySQLDataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSources/MySQLDataSource.cs @@ -8,17 +8,5 @@ public MySQLDataSource() { Provider = DataSourceProvider.MySQL; } - - public string Username - { - get => Properties.GetValue("Username"); - set => Properties.SetItem("Username", value); - } - - public string Password - { - get => Properties.GetValue("Password"); - set => Properties.SetItem("Password", value); - } } }