39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using ZB.MOM.WW.SPHistorianClient;
|
|
|
|
namespace ZB.MOM.WW.SPHistorianClient.Tests;
|
|
|
|
public class DependencyInjectionTests
|
|
{
|
|
[Fact]
|
|
public async Task AddZbSpHistorianClient_resolves_client_and_options()
|
|
{
|
|
var services = new ServiceCollection();
|
|
var options = new HistorianClientOptions { Host = "localhost" };
|
|
|
|
services.AddZbSpHistorianClient(options);
|
|
|
|
// HistorianClient is IAsyncDisposable-only, so the container must be disposed
|
|
// asynchronously (a synchronous `using` throws InvalidOperationException).
|
|
await using var sp = services.BuildServiceProvider();
|
|
Assert.Same(options, sp.GetRequiredService<HistorianClientOptions>());
|
|
Assert.NotNull(sp.GetRequiredService<HistorianClient>());
|
|
}
|
|
|
|
[Fact]
|
|
public void AddZbSpHistorianClient_throws_when_host_missing()
|
|
{
|
|
var services = new ServiceCollection();
|
|
var options = new HistorianClientOptions { Host = "" };
|
|
|
|
Assert.Throws<ArgumentException>(() => services.AddZbSpHistorianClient(options));
|
|
}
|
|
|
|
[Fact]
|
|
public void AddZbSpHistorianClient_throws_on_null_options()
|
|
{
|
|
var services = new ServiceCollection();
|
|
Assert.Throws<ArgumentNullException>(() => services.AddZbSpHistorianClient(null!));
|
|
}
|
|
}
|