-
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 #94 from RevealBi/unit-test/web-service-datasource
Add unit tests for RestData source; WebServiceDataSource and items
- Loading branch information
Showing
6 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/ODataDataSourceItemFixture.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,72 @@ | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems | ||
{ | ||
public class ODataDataSourceItemFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetsTitleAndDataSource_WhenConstructed() | ||
{ | ||
// Arrange | ||
string title = "Test Item"; | ||
var dataSource = new ODataDataSource(); | ||
|
||
// Act | ||
var item = new ODataDataSourceItem(title, dataSource); | ||
|
||
// Assert | ||
Assert.Equal(title, item.Title); | ||
Assert.Equal(dataSource, item.DataSource); | ||
} | ||
|
||
[Theory] | ||
[InlineData("SampleEntity")] | ||
[InlineData(null)] | ||
public void EntityType_SetsAndGetsValue_WithDifferentInputs(string entityType) | ||
{ | ||
// Arrange | ||
var item = new ODataDataSourceItem("Test Item", new ODataDataSource()); | ||
|
||
// Act | ||
item.EntityType = entityType; | ||
|
||
// Assert | ||
Assert.Equal(entityType, item.EntityType); | ||
Assert.Equal(entityType, item.Properties.GetValue<string>("EntityType")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Namespace.FunctionName")] | ||
[InlineData(null)] | ||
public void FunctionQName_SetsAndGetsValue_WithDifferentInputs(string functionQName) | ||
{ | ||
// Arrange | ||
var item = new ODataDataSourceItem("Test Item", new ODataDataSource()); | ||
|
||
// Act | ||
item.FunctionQName = functionQName; | ||
|
||
// Assert | ||
Assert.Equal(functionQName, item.FunctionQName); | ||
Assert.Equal(functionQName, item.Properties.GetValue<string>("FunctionQName")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com/api/entity")] | ||
[InlineData(null)] | ||
public void Url_SetsAndGetsValue_WithDifferentInputs(string url) | ||
{ | ||
// Arrange | ||
var item = new ODataDataSourceItem("Test Item", new ODataDataSource()); | ||
|
||
// Act | ||
item.Url = url; | ||
|
||
// Assert | ||
Assert.Equal(url, item.Url); | ||
Assert.Equal(url, item.Properties.GetValue<string>("Url")); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/WebServiceDataSourceItemFixture.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,38 @@ | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems | ||
{ | ||
public class WebServiceDataSourceItemFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetsTitleAndDataSource_WhenConstructed() | ||
{ | ||
// Arrange | ||
string title = "Test Item"; | ||
var dataSource = new WebServiceDataSource(); | ||
var item = new WebServiceDataSourceItem(title, dataSource); | ||
|
||
// Assert | ||
Assert.Equal(title, item.Title); | ||
Assert.Equal(dataSource, item.DataSource); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com/api")] | ||
[InlineData(null)] | ||
public void Url_SetsAndGetsValue_WithDifferentInputs(string url) | ||
{ | ||
// Arrange | ||
var item = new WebServiceDataSourceItem("Test Item", new WebServiceDataSource()); | ||
|
||
// Act | ||
item.Url = url; | ||
|
||
// Assert | ||
Assert.Equal(url, item.Url); | ||
Assert.Equal(url, item.Properties.GetValue<string>("Url")); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Reveal.Sdk.Dom.Tests/Data/DataSources/HttpAnalysisServicesDataSourceFixture.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,35 @@ | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSources | ||
{ | ||
public class HttpAnalysisServicesDataSourceFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetsModeToHttp_WhenConstructed() | ||
{ | ||
// Act | ||
var dataSource = new HttpAnalysisServicesDataSource(); | ||
|
||
// Assert | ||
Assert.Equal("HTTP", dataSource.Properties.GetValue<string>("Mode")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com/analysis")] | ||
[InlineData(null)] | ||
public void Url_SetsAndGetsValue_WithDifferentInputs(string url) | ||
{ | ||
// Arrange | ||
var dataSource = new HttpAnalysisServicesDataSource(); | ||
|
||
// Act | ||
dataSource.Url = url; | ||
|
||
// Assert | ||
Assert.Equal(url, dataSource.Url); | ||
Assert.Equal(url, dataSource.Properties.GetValue<string>("Url")); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Reveal.Sdk.Dom.Tests/Data/DataSources/ODataDataSourceFixture.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,35 @@ | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSources | ||
{ | ||
public class ODataDataSourceFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetsProviderToOData_WhenConstructed() | ||
{ | ||
// Act | ||
var dataSource = new ODataDataSource(); | ||
|
||
// Assert | ||
Assert.Equal(DataSourceProvider.OData, dataSource.Provider); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void UsePreemptiveAuthentication_SetsAndGetsValue_WithDifferentInputs(bool usePreemptiveAuthentication) | ||
{ | ||
// Arrange | ||
var dataSource = new ODataDataSource(); | ||
|
||
// Act | ||
dataSource.UsePreemptiveAuthentication = usePreemptiveAuthentication; | ||
|
||
// Assert | ||
Assert.Equal(usePreemptiveAuthentication, dataSource.UsePreemptiveAuthentication); | ||
Assert.Equal(usePreemptiveAuthentication, dataSource.Properties.GetValue<bool>("UsePreemptiveAuthentication")); | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.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,108 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSources | ||
{ | ||
public class RestDataSourceFixture | ||
{ | ||
public static IEnumerable<object[]> HeadersTestData => | ||
new List<object[]> | ||
{ | ||
new object[] { new List<string> { "Authorization: Bearer token", "Content-Type: application/json" } }, | ||
new object[] { null } | ||
}; | ||
|
||
[Fact] | ||
public void Constructor_SetsProviderToREST_WhenConstructed() | ||
{ | ||
// Arrange & Act | ||
var dataSource = new RestDataSource(); | ||
|
||
// Assert | ||
Assert.Equal(DataSourceProvider.REST, dataSource.Provider); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com/api/data")] | ||
[InlineData(null)] | ||
public void Url_SetsAndGetsValue_WithDifferentInputs(string url) | ||
{ | ||
// Arrange | ||
var dataSource = new RestDataSource(); | ||
|
||
// Act | ||
dataSource.Url = url; | ||
|
||
// Assert | ||
Assert.Equal(url, dataSource.Url); | ||
Assert.Equal(url, dataSource.Properties.GetValue<string>("URL")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("application/json")] | ||
[InlineData(null)] | ||
public void ContentType_SetsAndGetsValue_WithDifferentInputs(string contentType) | ||
{ | ||
// Arrange | ||
var dataSource = new RestDataSource(); | ||
|
||
// Act | ||
dataSource.ContentType = contentType; | ||
|
||
// Assert | ||
Assert.Equal(contentType, dataSource.ContentType); | ||
Assert.Equal(contentType, dataSource.Properties.GetValue<string>("ContentType")); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void UseAnonymousAuthentication_SetsAndGetsValue_WithDifferentInputs(bool value) | ||
{ | ||
// Arrange | ||
var dataSource = new RestDataSource(); | ||
|
||
// Act | ||
dataSource.UseAnonymousAuthentication = value; | ||
|
||
// Assert | ||
Assert.Equal(value, dataSource.UseAnonymousAuthentication); | ||
Assert.Equal(value, dataSource.Properties.GetValue<bool>("UseAnonymousAuthentication")); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(HeadersTestData))] | ||
public void Headers_SetsAndGetsValue_WithDifferentInputs(string[] headers) | ||
{ | ||
// Arrange | ||
var dataSource = new RestDataSource(); | ||
var expectedHeaders = headers?.ToList(); | ||
|
||
// Act | ||
dataSource.Headers = expectedHeaders; | ||
|
||
// Assert | ||
Assert.Equal(expectedHeaders, dataSource.Headers); | ||
Assert.Equal(expectedHeaders, dataSource.Properties.GetValue<List<string>>("Headers")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("GET")] | ||
[InlineData(null)] | ||
public void Method_SetsAndGetsValue_WithDifferentInputs(string method) | ||
{ | ||
// Arrange | ||
var dataSource = new RestDataSource(); | ||
|
||
// Act | ||
dataSource.Method = method; | ||
|
||
// Assert | ||
Assert.Equal(method, dataSource.Method); | ||
Assert.Equal(method, dataSource.Properties.GetValue<string>("Method")); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Reveal.Sdk.Dom.Tests/Data/DataSources/WebServiceDataSourceFixture.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,51 @@ | ||
using Reveal.Sdk.Dom.Core.Extensions; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data.DataSources | ||
{ | ||
public class WebServiceDataSourceFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetsProviderToWebService_WhenConstructed() | ||
{ | ||
// Act | ||
var dataSource = new WebServiceDataSource(); | ||
|
||
// Assert | ||
Assert.Equal(DataSourceProvider.WebService, dataSource.Provider); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com/api")] | ||
[InlineData(null)] | ||
public void Url_SetsAndGetsValue_WithDifferentInputs(string url) | ||
{ | ||
// Arrange | ||
var dataSource = new WebServiceDataSource(); | ||
|
||
// Act | ||
dataSource.Url = url; | ||
|
||
// Assert | ||
Assert.Equal(url, dataSource.Url); | ||
Assert.Equal(url, dataSource.Properties.GetValue<string>("URL")); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void UseAnonymousAuthentication_SetsAndGetsValue_WithDifferentInputs(bool value) | ||
{ | ||
// Arrange | ||
var dataSource = new WebServiceDataSource(); | ||
|
||
// Act | ||
dataSource.UseAnonymousAuthentication = value; | ||
|
||
// Assert | ||
Assert.Equal(value, dataSource.UseAnonymousAuthentication); | ||
Assert.Equal(value, dataSource.Properties.GetValue<bool>("UseAnonymousAuthentication")); | ||
} | ||
} | ||
} |