From 6479e54b96cc729d8cef0907843928ae0a5bad2f Mon Sep 17 00:00:00 2001 From: Phat Vo Date: Wed, 4 Dec 2024 09:33:50 +0700 Subject: [PATCH] add rdashtest case --- e2e/Sandbox/MainWindow.xaml.cs | 1 + .../Dashboards/TestMySQL.rdash | Bin 0 -> 1675 bytes .../MySqlDataSourceItemFixture.cs | 78 +++++++++++++++++ .../DataSources/MySQLDataSourceFixture.cs | 79 ++++++++++++------ .../Reveal.Sdk.Dom.Tests.csproj | 7 +- .../Data/DataSources/MySQLDataSource.cs | 12 --- 6 files changed, 136 insertions(+), 41 deletions(-) create mode 100644 src/Reveal.Sdk.Dom.Tests/Dashboards/TestMySQL.rdash 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 0000000000000000000000000000000000000000..38582c5480b42f0305033f33fba061b779bab274 GIT binary patch literal 1675 zcmV;626XvQO9KQH000080ANUjS;R(S5e)_a0E;6401f~E07PMPXku?+a%3)Qb8l|k zTHSBkHV}Uwu>T=2_E-l_oql9*uAS7z>?F0kZ0Rrzv~;$KQKCjtP1K_Q`;OGNL`i;F zfz^Jot^4VC_q*efI_k@hKb)NnHdHYf{ER<9s#WZKSPoto!3`HaQ4b&_m=q zOd`dXB<7LA%SuF$NPeT<9+bpuf9U^bXJ3*p6#b>*&i4I7V&t5eP*Kd=ZE(m47+CEXf- zbGwZ=X94_>@fbjshMEyYoDf`;=Ps3<+K_F;h{#}7@3Q-OBwSc1@T*$NdaAg(nw+SB z3w3y+fp=c~vY6fLSKT(Fd=+C3{KJaNHT;~&lDl;tGsr|r(8;kQOxC3Lf`=d!MN4W# zq}FVSG#2O1RV~m?k!`0_2yxs4_@rBn1L6~i$$l?jPgIiR+M6=$Yt?uMl%m1jm|hdz z6G41XI9-gekd<+R>*tV)Y_N;V%OXRQ92F#xA(!A;$Q#^HU|wl{C7(Kn26c@=vDc%A?$dzk1%oyruMQq@;7+99Vx z!W#B^i`Pv<7wA-oxaU$4HsxMlmFNSW3L&^o21@kKkS^4zP%-B|+#hWEYYRv>?o{Zw zepV2eUQ5rDS~u=g=)j08-d8l*F{eVqEyrDT4-FldQ=wrEA&w(AeHqb%`+s*aia&pr z+df58sAvFH03Rai{(VDP+I*@Cannh4zlku@HfsWO8;rWpi%W>6Qk7hsNOzDyif9h7 z%Nh|zKbuBZxo1{Vmv=p<2O^a9jz%N3g34k!oln-A3e0HC#ik=%kxv*yr;`vgnrzO2 zKP_Pofg!q<1{ezzFd9IfNwpvk9JHLlm>Lra{d+{YP1738^a(UJ^J zwz=v#rV7u zlaHMHS;XdC(9ax`LD%C^I}Q()aQrrugA%Byx@ZBF^wc0a2AYiDEq-OPM_cY-ecy8t zYxy0X5HO-MY&bf9*@k*=5To7oe%GiuQ z1#P~kxQrrwmvf97G+&tKZ)-IUXr0ZnE_X?{ObQ`JW9-WPXdN6|>iI^&_ zthT*K%@$+vYBh}UlP}uYr?L^L{cYQqB(?46>{$Vkk$`WRJI11;lc)X2tNF~;1ug9w z?O_;LatH0UsOs509=8Y0E5k9_m+XYUUH&DSyZ7A&I0KjZ1h*V}YUXOWlvm33d%>en zTM8i_xhgK~yLE$~Mgli%ZtTSVmYYcaWF7q0MCVg^rqCdg4lc-6{OXqiX%AFttghY3 za=i%5#vwKKznFhF^ciqN9;ACo%i5!xYUb%-XRO8aD?^RmL}TeSfbRD<3Y_&Fj*hnn z^pnpg%pD!B!Rj%8&&0@PAYDPjbQ6MV&Ps2hWOrL%8)%;5r^#ts^y|j?3G@Bz{*s6n9_&*`n3hUXyv1R{TBcL|NjF3P)h*<6aW+e000O8 zU`T{n#71Hf4F&)Jiz5I44gdfE000000000000000002Z`b7*33VRB?HYIARHP)h{{ V000000RRC2JOBUyIR*d#008R?7r_7k literal 0 HcmV?d00001 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); - } } }