Skip to content

Commit

Permalink
Merge pull request #52 from RevealBi/dsi-refactor
Browse files Browse the repository at this point in the history
Added MS Sql Server Data Source object
  • Loading branch information
brianlagunas authored May 16, 2024
2 parents e4ff473 + 16fbd95 commit 816d8b3
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 105 deletions.
19 changes: 8 additions & 11 deletions e2e/Sandbox/Factories/RestDataSourceDashboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal static RdashDocument CreateDashboard()
//json - default
var jsonDataSourceItem = new RestDataSourceItem("Sales by Category", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" })
{
Id = "TESTING",
Subtitle = "JSON Data Source Item",
Uri = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9",
IsAnonymous = true,
Expand All @@ -25,10 +24,10 @@ internal static RdashDocument CreateDashboard()
.SetLabel("CategoryName").SetValue("ProductSales"));

//excel
RestDataSourceItem excelDataSourceItem = new RestDataSourceItem("Marketing", new DataSource { Title = "Excel DS", Subtitle = "Excel DS Subtitle" })
RestDataSourceItem excelDataSourceItem = new RestDataSourceItem("Marketing", "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx",
new DataSource { Title = "Excel DS", Subtitle = "Excel DS Subtitle" })
{
Subtitle = "Excel Data Source Item",
Uri = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx",
IsAnonymous = true,
Fields = DataSourceFactory.GetMarketingDataSourceFields(),
};
Expand All @@ -38,14 +37,12 @@ internal static RdashDocument CreateDashboard()
.SetLabel("Territory").SetValue("Conversions"));

//csv
var csvDataSourceItem = new RestDataSourceItem("Illinois School Info", new DataSource { Title = "CSV DS", Subtitle = "CSV DS Subtitle" })
{
Subtitle = "CSV Data Source Item",
Uri = "https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto",
IsAnonymous = true,
Fields = DataSourceFactory.GetCsvDataSourceFields(),
};
csvDataSourceItem.UseCsv();
var csvDataSourceItem = new RestDataSourceItem("Illinois School Info", new DataSource() { Title = "CSV DS", Subtitle = "CSV DS Subtitle" })
.SetSubtitle("CSV Data Source Item")
.SetUri("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto")
.SetIsAnonymous(true)
.SetFields(DataSourceFactory.GetCsvDataSourceFields())
.WithCsv();

document.Visualizations.Add(new ScatterMapVisualization("Scatter", csvDataSourceItem)
.SetMap(Maps.NorthAmerica.UnitedStates.States.Illinois)
Expand Down
26 changes: 21 additions & 5 deletions e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,39 @@ internal class SqlServerDataSourceDashboards
{
internal static RdashDocument CreateDashboard()
{
var sqlServerDS = new MicrosoftSqlServerDataSource()
{
Title = "Northwind",
Subtitle = "Northwind Subtitle",
Host = @"Brian-Desktop\SQLEXPRESS",
Database = "Northwind",
};

var document = new RdashDocument("My Dashboard");

var sqlServerDataSourceItem = new MicrosoftSqlServerDataSourceItem("Customers")
var customersDsi = new MicrosoftSqlServerDataSourceItem("Customers Table", "Customers", sqlServerDS)
{
Subtitle = "SQL Server Data Source Item",
Host = @"Brian-Desktop\SQLEXPRESS",
Database = "Northwind",
Table = "Customers",
Fields = new List<IField>
{
new TextField("ContactName"),
new TextField("ContactTitle"),
new TextField("City")
}
};
document.Visualizations.Add(new GridVisualization("Customer List", customersDsi).SetColumns("ContactName", "ContactTitle", "City"));

document.Visualizations.Add(new GridVisualization("Customer List", sqlServerDataSourceItem).SetColumns("ContactName", "ContactTitle", "City"));
var employeesDsi = new MicrosoftSqlServerDataSourceItem("Employees Table", sqlServerDS)
{
Subtitle = "SQL Server Data Source Item",
Table = "Employees",
Fields = new List<IField>
{
new TextField("FirstName"),
new TextField("LastName"),
}
};
document.Visualizations.Add(new GridVisualization("Employee List", employeesDsi).SetColumns("FirstName", "LastName"));

return document;
}
Expand Down
12 changes: 6 additions & 6 deletions e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ private void RevealView_DataSourcesRequested(object sender, DataSourcesRequested
//excelDSI.Sheet = "Marketing";
//dsi.Add(excelDSI);

//var sqlDS = new RVSqlServerDataSource();
//sqlDS.Title = "SQL Server Data Source";
//sqlDS.Subtitle = "SQL Server DS Subtitle";
//sqlDS.Host = "Brian-Desktop\\SQLEXPRESS";
//sqlDS.Database = "Northwind"; //this is required
//ds.Add(sqlDS);
var sqlDS = new RVSqlServerDataSource();
sqlDS.Title = "SQL Server Data Source";
sqlDS.Subtitle = "SQL Server DS Subtitle";
sqlDS.Host = "Brian-Desktop\\SQLEXPRESS";
sqlDS.Database = "Northwind"; //this is required
ds.Add(sqlDS);

//var sqlDSI = new RVSqlServerDataSourceItem(sqlDS);
//sqlDSI.Title = "SQL Server Data Source Item";
Expand Down
4 changes: 2 additions & 2 deletions src/Reveal.Sdk.Dom.Tests/Data/DataSourceItemFactoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Create_ShouldReturnDataSourceItem_WithDefaultDataSource()
Assert.Equal(title, result.Title);
Assert.Null(result.Subtitle);
Assert.NotNull(result.DataSource);
Assert.IsType<DataSource>(result.DataSource);
Assert.IsType<MicrosoftSqlServerDataSource>(result.DataSource);
}

[Fact]
Expand Down Expand Up @@ -54,7 +54,7 @@ public void Create_ShouldReturnDataSourceItem_WithCustomDataSource()
Assert.Equal(title, result.Title);
Assert.Equal(subtitle, result.Subtitle);
Assert.NotNull(result.DataSource);
Assert.Same(dataSource, result.DataSource);
Assert.NotSame(dataSource, result.DataSource);
}

[Fact]
Expand Down
150 changes: 150 additions & 0 deletions src/Reveal.Sdk.Dom.Tests/Data/MicrosoftSqlServerDataSourceFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data
{
public class MicrosoftSqlServerDataSourceFixture
{
[Fact]
public void Constructor_Should_SetProviderToMicrosoftSqlServer()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();

// Act
var provider = dataSource.Provider;

// Assert
Assert.Equal(DataSourceProvider.MicrosoftSqlServer, provider);
}

[Fact]
public void Constructor_Should_SetServerAggregationDefaultToTrue()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();

// Act
var serverAggregationDefault = dataSource.Properties.GetValue<bool>("ServerAggregationDefault");

// Assert
Assert.True(serverAggregationDefault);
}

[Fact]
public void Constructor_Should_SetServerAggregationReadOnlyToFalse()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();

// Act
var serverAggregationReadOnly = dataSource.Properties.GetValue<bool>("ServerAggregationReadOnly");

// Assert
Assert.False(serverAggregationReadOnly);
}

[Fact]
public void Database_Should_GetAndSetDatabaseProperty()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();
var database = "TestDatabase";

// Act
dataSource.Database = database;
var result = dataSource.Database;

// Assert
Assert.Equal(database, result);
}

[Fact]
public void Host_Should_GetAndSetHostProperty()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();
var host = "TestHost";

// Act
dataSource.Host = host;
var result = dataSource.Host;

// Assert
Assert.Equal(host, result);
}

[Fact]
public void Port_Should_GetAndSetPortProperty()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();
var port = "1234";

// Act
dataSource.Port = port;
var result = dataSource.Port;

// Assert
Assert.Equal(port, result);
}

[Fact]
public void Schema_Should_GetAndSetSchemaProperty()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();
var schema = "TestSchema";

// Act
dataSource.Schema = schema;
var result = dataSource.Schema;

// Assert
Assert.Equal(schema, result);
}

[Fact]
public void Create_Should_CreateNewMicrosoftSqlServerDataSourceWithMatchingProperties()
{
// Arrange
var dataSource = new DataSource()
{
Id = "1",
Title = "Test Title",
Subtitle = "Test Subtitle"
};

// Act
var result = MicrosoftSqlServerDataSource.Create(dataSource);

// Assert
Assert.Equal(dataSource.Id, result.Id);
Assert.Equal(dataSource.Title, result.Title);
Assert.Equal(dataSource.Subtitle, result.Subtitle);
}

[Fact]
public void Constructor_Should_Set_ServerAggregationDefault_Property()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();

// Assert
Assert.True(dataSource.Properties.ContainsKey("ServerAggregationDefault"));
Assert.True(dataSource.Properties.GetValue<bool>("ServerAggregationDefault"));
}

[Fact]
public void Constructor_Should_Set_ServerAggregationReadOnly_Property()
{
// Arrange
var dataSource = new MicrosoftSqlServerDataSource();

// Assert
Assert.True(dataSource.Properties.ContainsKey("ServerAggregationReadOnly"));
Assert.False(dataSource.Properties.GetValue<bool>("ServerAggregationReadOnly"));
}
}
}
Loading

0 comments on commit 816d8b3

Please sign in to comment.