diff --git a/e2e/Sandbox/DashboardCreators/MSAzureSqlServerDSDashboard.cs b/e2e/Sandbox/DashboardCreators/MSAzureSqlServerDSDashboard.cs new file mode 100644 index 00000000..b94cafa6 --- /dev/null +++ b/e2e/Sandbox/DashboardCreators/MSAzureSqlServerDSDashboard.cs @@ -0,0 +1,48 @@ +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; + +namespace Sandbox.DashboardFactories +{ + internal class MSAzureSqlServerDSDashboard : IDashboardCreator + { + public string Name => "MS Azure Sql Server"; + + public RdashDocument CreateDashboard() + { + var document = new RdashDocument("MS Azure Sql Dashboard"); + + var msAzureSqlDS = new MicrosoftAzureSqlServerDataSource() + { + Id = "MSAzureSqlId", + Title = "Microsoft Azure Sql Server Data Source", + Subtitle = "MS Azure Sql Server DS Subtitle", + Database = "reveal", + DefaultRefreshRate = "180", + Encrypt = false, + Host = "revealtesting.database.windows.net", + Port = 1433, + TrustServerCertificate = false + }; + + var msAzureSqlDSItem = new MicrosoftAzureSqlServerDataSourceItem("Microsoft Azure Sql Data Source Item", msAzureSqlDS) + { + Id = "MSAzureSqlItemId", + Title = "Microsoft Azure Sql Server Data Source Item", + Subtitle = "MS Azure Sql Server DSI Subtitle", + Table = "Customers", + Fields = new List() + { + new TextField("City"), + new TextField("CustomerID"), + } + }; + + document.Visualizations.Add(new GridVisualization("Customers in France", msAzureSqlDSItem) + .SetColumns("CustomerID", "City")); + + return document; + } + } +} diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index d907f340..fe7af7dc 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -48,6 +48,7 @@ public partial class MainWindow : Window new HealthcareDashboard(), new ManufacturingDashboard(), new MarketingDashboard(), + new MSAzureSqlServerDSDashboard(), new PostgresqlDashboard(), new RestDataSourceDashboard(), new SalesDashboard(), diff --git a/e2e/Sandbox/Reveal/AuthenticationProvider.cs b/e2e/Sandbox/Reveal/AuthenticationProvider.cs index a3621387..3a251330 100644 --- a/e2e/Sandbox/Reveal/AuthenticationProvider.cs +++ b/e2e/Sandbox/Reveal/AuthenticationProvider.cs @@ -11,7 +11,11 @@ internal class AuthenticationProvider : IRVAuthenticationProvider public Task ResolveCredentialsAsync(RVDashboardDataSource dataSource) { IRVDataSourceCredential userCredential = null; - if (dataSource is RVSqlServerDataSource) + if (dataSource is RVAzureSqlDataSource) + { + userCredential = new RVUsernamePasswordDataSourceCredential("azure-username", "password"); + } + else if (dataSource is RVSqlServerDataSource) { userCredential = new RVUsernamePasswordDataSourceCredential(); } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs index d8efdb23..abcfdd08 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItemFixture.cs @@ -1,9 +1,5 @@ -using Reveal.Sdk.Dom.Data; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Data; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems @@ -13,7 +9,7 @@ public class MicrosoftAzureSqlServerDataSourceItemFixture [Theory] [InlineData("DS Title", "DS Item Title", "DS Title", "DS Item Title")] [InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")] - public void Constructor_SetsTitleAndDatasource_AsProvided(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle) + public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndMSAzureSqlServerDataSource(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle) { // Arrange var dataSource = new MicrosoftAzureSqlServerDataSource() { Title = dSTitle }; @@ -23,11 +19,89 @@ public void Constructor_SetsTitleAndDatasource_AsProvided(string dSTitle, string // Assert Assert.Equal(expectedDSItemTitle, dataSourceItem.Title); - Assert.Equal(dataSource, dataSourceItem.DataSource); + Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id); Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId); Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title); - Assert.Equal(dSItemTitle, dataSourceItem.Title); - Assert.Equal(dataSource, dataSourceItem.DataSource); + Assert.Same(dataSource, dataSourceItem.DataSource); + } + + [Fact] + public void Constructor_CreateDSItemWithExpectedFields_WithTitle() + { + // Arrange + var expectedDSItemTitle = "Azure SQL DS Item title"; + + // Act + var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem(expectedDSItemTitle); + + // Assert + Assert.Equal(expectedDSItemTitle, dataSourceItem.Title); + Assert.NotNull(dataSourceItem.DataSource); + Assert.IsType(dataSourceItem.DataSource); + Assert.Equal(expectedDSItemTitle, dataSourceItem.DataSource.Title); + } + + [Theory] + [InlineData("DS Title", "DS Item Title", "DS Title", "DS Item Title")] + [InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")] + public void Constructor_CreateDSItemWithExpectedFields_WithTitleAndDataSource(string dSTitle, string dSItemTitle, string expectedDSTitle, string expectedDSItemTitle) + { + // Arrange + var dataSource = new DataSource () { Title = dSTitle }; + + // Act + var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem(dSItemTitle, dataSource); + + // Assert + Assert.Equal(expectedDSItemTitle, dataSourceItem.Title); + Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id); + Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId); + Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title); + Assert.NotSame(dataSource, dataSourceItem.DataSource); + Assert.IsType(dataSourceItem.DataSource); + } + + [Fact] + public void ToJsonString_CreateExpectedRevealJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceItemType"", + ""Id"": ""azureSqlDsItemId"", + ""Title"": ""Azure SQL DSItem"", + ""Subtitle"": ""Azure SQL DS Item SubTitle"", + ""DataSourceId"": ""azureSqlId"", + ""HasTabularData"": true, + ""HasAsset"": false, + ""Properties"": { + ""ServerAggregation"": true, + ""Database"": ""reveal"", + ""Table"": ""Categories"" + }, + ""Parameters"": {} + }"; + var dataSource = new MicrosoftAzureSqlServerDataSource() + { + Id = "azureSqlId" + }; + var dataSourceItem = new MicrosoftAzureSqlServerDataSourceItem("Azure SQL DSItem", dataSource) + { + Id = "azureSqlDsItemId", + Subtitle = "Azure SQL DS Item SubTitle", + HasTabularData = true, + HasAsset = false, + ProcessDataOnServer = true, + Database = "reveal", + Table = "Categories", + }; + + // Act + var json = dataSourceItem.ToJsonString(); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs index 75e3f4d0..dd912ec6 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/MicrosoftAzureSqlServerDataSourceFixture.cs @@ -1,10 +1,6 @@ -using Reveal.Sdk.Dom.Core.Extensions; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSources @@ -22,7 +18,7 @@ public void Constructor_SetProviderToMicrosoftAzureSqlServer_WhenConstructed() } [Fact] - public void TrustServerCertificate_SaveValueAndProperties_WhenSet() + public void GetTrustServerCertificate_ReturnSameValue_WhenSet() { // Arrange var dataSource = new MicrosoftAzureSqlServerDataSource(); @@ -35,5 +31,56 @@ public void TrustServerCertificate_SaveValueAndProperties_WhenSet() Assert.Equal(trustServerCertificate, dataSource.TrustServerCertificate); Assert.Equal(trustServerCertificate, dataSource.Properties.GetValue("TrustServerCertificate")); } + + [Fact] + public void ToJsonString_CreateExpectedRevealJson_NoConditions() + { + // Arrange + var expectedJson = """ + { + "_type": "DataSourceType", + "Id": "azureSqlId", + "Provider": "AZURE_SQL", + "Description": "Azure SQL DS", + "Subtitle": "Azure SQL DS Item", + "Properties": { + "ServerAggregationDefault": false, + "ServerAggregationReadOnly": true, + "Host": "revealtesting.database.windows.net", + "Port": 1433, + "Database": "reveal", + "Schema": "azureSchema", + "TrustServerCertificate": false, + "Encrypt": false + }, + "Settings": { + "DefaultRefreshRate": 180 + } + } + """; + var dataSource = new MicrosoftAzureSqlServerDataSource() + { + Id = "azureSqlId", + Title = "Azure SQL DS", + Subtitle = "Azure SQL DS Item", + ProcessDataOnServerDefaultValue = false, + ProcessDataOnServerReadOnly = true, + Host = "revealtesting.database.windows.net", + Port = 1433, + Database = "reveal", + Schema = "azureSchema", + TrustServerCertificate = false, + Encrypt = false, + DefaultRefreshRate = "180" + }; + + // Act + var json = dataSource.ToJsonString(); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } -} +} diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItem.cs index e9e8a927..d242c6eb 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItems/MicrosoftAzureSqlServerDataSourceItem.cs @@ -1,9 +1,22 @@ namespace Reveal.Sdk.Dom.Data { - internal class MicrosoftAzureSqlServerDataSourceItem : MicrosoftSqlServerDataSourceItem + public class MicrosoftAzureSqlServerDataSourceItem : MicrosoftSqlServerDataSourceItem { public MicrosoftAzureSqlServerDataSourceItem(string title, DataSource dataSource) : base(title, dataSource) { } + + public MicrosoftAzureSqlServerDataSourceItem(string title, MicrosoftAzureSqlServerDataSource dataSource) : + base(title, dataSource) + { } + + public MicrosoftAzureSqlServerDataSourceItem(string title) : + base(title, new MicrosoftAzureSqlServerDataSource()) + { } + + protected override DataSource CreateDataSourceInstance(DataSource dataSource) + { + return Create(dataSource); + } } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSources/MicrosoftAzureSqlServerDataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSources/MicrosoftAzureSqlServerDataSource.cs index 2c3d45d2..b94126f8 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSources/MicrosoftAzureSqlServerDataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSources/MicrosoftAzureSqlServerDataSource.cs @@ -3,7 +3,7 @@ namespace Reveal.Sdk.Dom.Data { - internal class MicrosoftAzureSqlServerDataSource : MicrosoftSqlServerDataSource + public class MicrosoftAzureSqlServerDataSource : MicrosoftSqlServerDataSource { public MicrosoftAzureSqlServerDataSource() {