Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for RestData source; WebServiceDataSource and items #94

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
}
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"));
}
}
}
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"));
}
}
}
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 src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs
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"));
}
}
}
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"));
}
}
}