-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from RevealBi/localfile
added local excel file data source item
- Loading branch information
Showing
7 changed files
with
217 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/Reveal.Sdk.Dom.Tests/Data/ExcelFileDataSourceItemFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Reveal.Sdk.Dom.Core.Constants; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data | ||
{ | ||
public class ExcelFileDataSourceItemFixture | ||
{ | ||
[Fact] | ||
public void Constructor_WithTitleAndDataSource_ShouldSetProperties() | ||
{ | ||
// Arrange | ||
string title = "Test Excel File"; | ||
DataSource dataSource = new DataSource(); | ||
|
||
// Act | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem(title, dataSource); | ||
|
||
// Assert | ||
Assert.Equal(title, excelFile.Title); | ||
Assert.Equal(title, excelFile.ResourceItem.Title); | ||
Assert.Equal(dataSource, excelFile.DataSource); | ||
Assert.Equal(DataSourceIds.Excel, excelFile.DataSource.Id); | ||
Assert.Equal(DataSourceProvider.MicrosoftExcel, excelFile.DataSource.Provider); | ||
Assert.Equal(DataSourceProvider.LocalFile, excelFile.ResourceItemDataSource.Provider); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItemDataSource.Id); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItem.DataSourceId); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithTitle_ShouldSetProperties() | ||
{ | ||
// Arrange | ||
string title = "Test Excel File"; | ||
|
||
// Act | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem(title); | ||
|
||
// Assert | ||
Assert.Equal(title, excelFile.Title); | ||
Assert.Equal(title, excelFile.ResourceItem.Title); | ||
Assert.NotNull(excelFile.DataSource); | ||
Assert.Equal(DataSourceIds.Excel, excelFile.DataSource.Id); | ||
Assert.Equal(DataSourceProvider.MicrosoftExcel, excelFile.DataSource.Provider); | ||
Assert.Equal(DataSourceProvider.LocalFile, excelFile.ResourceItemDataSource.Provider); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItemDataSource.Id); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItem.DataSourceId); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithTitleAndPath_ShouldSetProperties() | ||
{ | ||
// Arrange | ||
string title = "Test Excel File"; | ||
string path = "test.xlsx"; | ||
|
||
// Act | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem(title, path); | ||
|
||
// Assert | ||
Assert.Equal(title, excelFile.Title); | ||
Assert.Equal(title, excelFile.ResourceItem.Title); | ||
Assert.NotNull(excelFile.DataSource); | ||
Assert.Equal(DataSourceIds.Excel, excelFile.DataSource.Id); | ||
Assert.Equal(DataSourceProvider.MicrosoftExcel, excelFile.DataSource.Provider); | ||
Assert.Equal($"local:{path}", excelFile.Path); | ||
Assert.Equal(DataSourceProvider.LocalFile, excelFile.ResourceItemDataSource.Provider); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItemDataSource.Id); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItem.DataSourceId); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithTitlePathAndSheet_ShouldSetProperties() | ||
{ | ||
// Arrange | ||
string title = "Test Excel File"; | ||
string path = "test.xlsx"; | ||
string sheet = "Sheet1"; | ||
|
||
// Act | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem(title, path, sheet); | ||
|
||
// Assert | ||
Assert.Equal(title, excelFile.Title); | ||
Assert.Equal(title, excelFile.ResourceItem.Title); | ||
Assert.NotNull(excelFile.DataSource); | ||
Assert.Equal(DataSourceIds.Excel, excelFile.DataSource.Id); | ||
Assert.Equal(DataSourceProvider.MicrosoftExcel, excelFile.DataSource.Provider); | ||
Assert.Equal($"local:{path}", excelFile.Path); | ||
Assert.Equal(sheet, excelFile.Sheet); | ||
Assert.Equal(DataSourceProvider.LocalFile, excelFile.ResourceItemDataSource.Provider); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItemDataSource.Id); | ||
Assert.Equal(DataSourceIds.LOCALFILE, excelFile.ResourceItem.DataSourceId); | ||
} | ||
|
||
[Fact] | ||
public void Path_GetAndSet_ShouldSetLocalPath() | ||
{ | ||
// Arrange | ||
string path = "test.xlsx"; | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem("Test Excel File"); | ||
|
||
// Act | ||
excelFile.Path = path; | ||
|
||
// Assert | ||
Assert.Equal($"local:{path}", excelFile.Path); | ||
} | ||
|
||
[Fact] | ||
public void Sheet_GetAndSet_ShouldSetSheet() | ||
{ | ||
// Arrange | ||
string sheet = "Sheet1"; | ||
ExcelFileDataSourceItem excelFile = new ExcelFileDataSourceItem("Test Excel File"); | ||
|
||
// Act | ||
excelFile.Sheet = sheet; | ||
|
||
// Assert | ||
Assert.Equal(sheet, excelFile.Sheet); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Reveal.Sdk.Dom/Data/DataSourceItems/ExcelFileDataSourceItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Newtonsoft.Json; | ||
using Reveal.Sdk.Dom.Core.Constants; | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
|
||
namespace Reveal.Sdk.Dom.Data | ||
{ | ||
//todo: we may need a base class named LocalFileDataSourceItem which has shared properties between different file types | ||
//todo: need to add more Excel specific properties | ||
public class ExcelFileDataSourceItem : DataSourceItem | ||
{ | ||
public ExcelFileDataSourceItem(string title) : | ||
this(title, new DataSource()) | ||
{ } | ||
|
||
public ExcelFileDataSourceItem(string title, string path) : | ||
this(title, path, null) | ||
{ } | ||
|
||
public ExcelFileDataSourceItem(string title, string path, string sheet) : | ||
this(title, new DataSource()) | ||
{ | ||
Path = path; | ||
Sheet = sheet; | ||
} | ||
|
||
public ExcelFileDataSourceItem(string title, DataSource dataSource) : | ||
base(title, dataSource) | ||
{ | ||
InitializeResourceItem(title); | ||
} | ||
|
||
[JsonIgnore] | ||
public string Path | ||
{ | ||
get { return ResourceItem.Properties.GetValue<string>("URI"); } | ||
set { ResourceItem.Properties.SetItem("URI", $"local:{value}"); } | ||
} | ||
|
||
[JsonIgnore] | ||
public string Sheet | ||
{ | ||
get { return Properties.GetValue<string>("Sheet"); } | ||
set { Properties.SetItem("Sheet", value); } | ||
} | ||
|
||
protected override void InitializeDataSource(DataSource dataSource, string title) | ||
{ | ||
base.InitializeDataSource(dataSource, title); | ||
UpdateDataSourceId(DataSourceIds.Excel); | ||
DataSource.Provider = DataSourceProvider.MicrosoftExcel; | ||
} | ||
|
||
private void InitializeResourceItem(string title) | ||
{ | ||
ResourceItemDataSource = new DataSource { Provider = DataSourceProvider.LocalFile, Id = DataSourceIds.LOCALFILE }; | ||
ResourceItem = new DataSourceItem | ||
{ | ||
DataSource = ResourceItemDataSource, | ||
DataSourceId = ResourceItemDataSource.Id, | ||
Title = title | ||
}; | ||
|
||
ResourceItemDataSource = ResourceItemDataSource; | ||
ResourceItem = ResourceItem; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters