Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Wilms committed Feb 4, 2025
1 parent c4f012e commit 974bb8f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
13 changes: 3 additions & 10 deletions src/Nexus/Extensions/Sources/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@

namespace Nexus.Sources;

internal record SampleSettings(
string HelloWorldMessage
);

[ExtensionDescription(
"Provides catalogs with sample data.",
"https://github.com/nexus-main/nexus",
"https://github.com/nexus-main/nexus/blob/master/src/Nexus/Extensions/Sources/Sample.cs")]
internal class Sample : IDataSource<SampleSettings?>
internal class Sample : IDataSource<object?>
{
public static readonly Guid PipelineId = new("c2c724ab-9002-4879-9cd9-2147844bee96");

Expand Down Expand Up @@ -95,16 +91,13 @@ internal class Sample : IDataSource<SampleSettings?>

public const string RemotePassword = "1234";

private DataSourceContext<SampleSettings?> Context { get; set; } = default!;
private DataSourceContext<object?> Context { get; set; } = default!;

public Task SetContextAsync(
DataSourceContext<SampleSettings?> context,
DataSourceContext<object?> context,
ILogger logger,
CancellationToken cancellationToken)
{
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" && context.SourceConfiguration is not null)
logger.LogWarning(context.SourceConfiguration.HelloWorldMessage);

Context = context;

return Task.CompletedTask;
Expand Down
6 changes: 3 additions & 3 deletions src/Nexus/Services/CatalogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ internal class CatalogManager(
IServiceProvider serviceProvider,
IExtensionHive<IDataSource> sourcesExtensionHive,
IPipelineService pipelineService,
ILogger<CatalogManager> logger) : ICatalogManager
ILogger<CatalogManager> logger
) : ICatalogManager
{
record CatalogPrototype(
CatalogRegistration Registration,
Expand Down Expand Up @@ -66,8 +67,7 @@ public async Task<CatalogContainer[]> GetCatalogContainersAsync(
new(
Type: typeof(Sample).FullName!,
ResourceLocator: default,
Configuration: JsonSerializer
.SerializeToElement(new SampleSettings("Hello from Sample!"))
Configuration: JsonSerializer.SerializeToElement<object?>(default)
)
]
))
Expand Down
5 changes: 3 additions & 2 deletions tests/Nexus.Tests/DataSource/DataSourceControllerFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
// Copyright (c) [2024] [nexus-main]

using System.Text.Json;
using Nexus.Core.V1;
using Nexus.Extensibility;
using Nexus.Sources;
Expand All @@ -21,13 +22,13 @@ public class DataSourceControllerFixture
(
Type: typeof(Sample).FullName!,
ResourceLocator: default,
Configuration: default
Configuration: JsonSerializer.SerializeToElement<object?>(default)
);

internal DataSourceRegistration Registration2 { get; } = new DataSourceRegistration
(
Type: typeof(TestSource).FullName!,
ResourceLocator: default,
Configuration: default
Configuration: JsonSerializer.SerializeToElement<TestSourceSettings?>(null)
);
}
2 changes: 1 addition & 1 deletion tests/Nexus.Tests/DataSource/DataSourceControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public async Task CanReadCached()
var registration = new DataSourceRegistration(
"a",
new Uri("http://xyz"),
default,
JsonSerializer.SerializeToElement<object?>(default),
default
);

Expand Down
16 changes: 8 additions & 8 deletions tests/Nexus.Tests/DataSource/SampleDataSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class SampleDataSourceTests
public async Task ProvidesCatalog()
{
// arrange
var dataSource = new Sample() as IDataSource<SampleSettings>;
var dataSource = new Sample() as IDataSource<object?>;

var context = new DataSourceContext<SampleSettings>(
var context = new DataSourceContext<object?>(
ResourceLocator: default,
SourceConfiguration: default!,
RequestConfiguration: default
Expand Down Expand Up @@ -49,9 +49,9 @@ public async Task ProvidesCatalog()
[Fact]
public async Task CanProvideTimeRange()
{
var dataSource = new Sample() as IDataSource<SampleSettings>;
var dataSource = new Sample() as IDataSource<object?>;

var context = new DataSourceContext<SampleSettings>(
var context = new DataSourceContext<object?>(
ResourceLocator: default,
SourceConfiguration: default!,
RequestConfiguration: default
Expand All @@ -68,9 +68,9 @@ public async Task CanProvideTimeRange()
[Fact]
public async Task CanProvideAvailability()
{
var dataSource = new Sample() as IDataSource<SampleSettings>;
var dataSource = new Sample() as IDataSource<object?>;

var context = new DataSourceContext<SampleSettings>(
var context = new DataSourceContext<object?>(
ResourceLocator: default,
SourceConfiguration: default!,
RequestConfiguration: default
Expand All @@ -89,9 +89,9 @@ public async Task CanProvideAvailability()
[Fact]
public async Task CanReadFullDay()
{
var dataSource = new Sample() as IDataSource<SampleSettings>;
var dataSource = new Sample() as IDataSource<object?>;

var context = new DataSourceContext<SampleSettings>(
var context = new DataSourceContext<object?>(
ResourceLocator: default,
SourceConfiguration: default!,
RequestConfiguration: default
Expand Down
6 changes: 4 additions & 2 deletions tests/Nexus.Tests/Services/DataControllerServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public async Task CanCreateAndInitializeDataSourceController()
var registration = new DataSourceRegistration(
Type: default!,
new Uri("A", UriKind.Relative),
Configuration: default);
Configuration: JsonSerializer.SerializeToElement<object?>(null)
);

var pipeline = new DataSourcePipeline([registration]);

Expand Down Expand Up @@ -80,7 +81,8 @@ public async Task CanCreateAndInitializeDataSourceController()
default!,
default!,
Options.Create(new DataOptions()),
loggerFactory);
loggerFactory
);

// Act
var actual = await dataControllerService.GetDataSourceControllerAsync(pipeline, CancellationToken.None);
Expand Down

0 comments on commit 974bb8f

Please sign in to comment.