feat: add JoeAppEngine OPC UA nodes, fix DCL auto-reconnect and quality push
- Add JoeAppEngine folder to OPC UA nodes.json (BTCS, AlarmCntsBySeverity, Scheduler/ScanTime) - Fix DataConnectionActor: capture Self in PreStart for use from non-actor threads, preventing Self.Tell failure in Disconnected event handler - Implement InstanceActor.HandleConnectionQualityChanged to mark attributes Bad on disconnect - Fix LmxFakeProxy TagMapper to serialize arrays as JSON instead of "System.Int32[]" - Allow DataType and DataSourceReference updates in TemplateService.UpdateAttributeAsync - Update test_infra_opcua.md with JoeAppEngine documentation
This commit is contained in:
90
tests/ScadaLink.CLI.Tests/CliConfigTests.cs
Normal file
90
tests/ScadaLink.CLI.Tests/CliConfigTests.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using ScadaLink.CLI;
|
||||
|
||||
namespace ScadaLink.CLI.Tests;
|
||||
|
||||
public class CliConfigTests
|
||||
{
|
||||
[Fact]
|
||||
public void Load_DefaultValues_WhenNoConfigExists()
|
||||
{
|
||||
// Clear environment variables that might affect the test
|
||||
var origContact = Environment.GetEnvironmentVariable("SCADALINK_CONTACT_POINTS");
|
||||
var origLdap = Environment.GetEnvironmentVariable("SCADALINK_LDAP_SERVER");
|
||||
var origFormat = Environment.GetEnvironmentVariable("SCADALINK_FORMAT");
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_CONTACT_POINTS", null);
|
||||
Environment.SetEnvironmentVariable("SCADALINK_LDAP_SERVER", null);
|
||||
Environment.SetEnvironmentVariable("SCADALINK_FORMAT", null);
|
||||
|
||||
var config = CliConfig.Load();
|
||||
|
||||
Assert.Equal(636, config.LdapPort);
|
||||
Assert.True(config.LdapUseTls);
|
||||
Assert.Equal("json", config.DefaultFormat);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_CONTACT_POINTS", origContact);
|
||||
Environment.SetEnvironmentVariable("SCADALINK_LDAP_SERVER", origLdap);
|
||||
Environment.SetEnvironmentVariable("SCADALINK_FORMAT", origFormat);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_ContactPoints_FromEnvironment()
|
||||
{
|
||||
var orig = Environment.GetEnvironmentVariable("SCADALINK_CONTACT_POINTS");
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_CONTACT_POINTS", "host1:8080,host2:8080");
|
||||
|
||||
var config = CliConfig.Load();
|
||||
|
||||
Assert.Equal(2, config.ContactPoints.Count);
|
||||
Assert.Equal("host1:8080", config.ContactPoints[0]);
|
||||
Assert.Equal("host2:8080", config.ContactPoints[1]);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_CONTACT_POINTS", orig);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_LdapServer_FromEnvironment()
|
||||
{
|
||||
var orig = Environment.GetEnvironmentVariable("SCADALINK_LDAP_SERVER");
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_LDAP_SERVER", "ldap.example.com");
|
||||
|
||||
var config = CliConfig.Load();
|
||||
|
||||
Assert.Equal("ldap.example.com", config.LdapServer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_LDAP_SERVER", orig);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_Format_FromEnvironment()
|
||||
{
|
||||
var orig = Environment.GetEnvironmentVariable("SCADALINK_FORMAT");
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_FORMAT", "table");
|
||||
|
||||
var config = CliConfig.Load();
|
||||
|
||||
Assert.Equal("table", config.DefaultFormat);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("SCADALINK_FORMAT", orig);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
tests/ScadaLink.CLI.Tests/CommandHelpersTests.cs
Normal file
131
tests/ScadaLink.CLI.Tests/CommandHelpersTests.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using ScadaLink.CLI.Commands;
|
||||
using ScadaLink.Commons.Messages.Management;
|
||||
|
||||
namespace ScadaLink.CLI.Tests;
|
||||
|
||||
public class CommandHelpersTests
|
||||
{
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementSuccess_JsonFormat_ReturnsZero()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var response = new ManagementSuccess("corr-1", "{\"id\":1,\"name\":\"test\"}");
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "json");
|
||||
|
||||
Assert.Equal(0, exitCode);
|
||||
Assert.Contains("{\"id\":1,\"name\":\"test\"}", writer.ToString());
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementSuccess_TableFormat_ArrayData_ReturnsZero()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var json = "[{\"Id\":1,\"Name\":\"Alpha\"},{\"Id\":2,\"Name\":\"Beta\"}]";
|
||||
var response = new ManagementSuccess("corr-1", json);
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
||||
|
||||
Assert.Equal(0, exitCode);
|
||||
var output = writer.ToString();
|
||||
Assert.Contains("Id", output);
|
||||
Assert.Contains("Name", output);
|
||||
Assert.Contains("Alpha", output);
|
||||
Assert.Contains("Beta", output);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementSuccess_TableFormat_ObjectData_ReturnsZero()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var json = "{\"Id\":1,\"Name\":\"Alpha\",\"Status\":\"Active\"}";
|
||||
var response = new ManagementSuccess("corr-1", json);
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
||||
|
||||
Assert.Equal(0, exitCode);
|
||||
var output = writer.ToString();
|
||||
Assert.Contains("Property", output);
|
||||
Assert.Contains("Value", output);
|
||||
Assert.Contains("Id", output);
|
||||
Assert.Contains("Alpha", output);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementSuccess_TableFormat_EmptyArray_ShowsNoResults()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var response = new ManagementSuccess("corr-1", "[]");
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "table");
|
||||
|
||||
Assert.Equal(0, exitCode);
|
||||
Assert.Contains("(no results)", writer.ToString());
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementError_ReturnsOne()
|
||||
{
|
||||
var errWriter = new StringWriter();
|
||||
Console.SetError(errWriter);
|
||||
|
||||
var response = new ManagementError("corr-1", "Something failed", "FAIL_CODE");
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "json");
|
||||
|
||||
Assert.Equal(1, exitCode);
|
||||
Assert.Contains("Something failed", errWriter.ToString());
|
||||
|
||||
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_ManagementUnauthorized_ReturnsTwo()
|
||||
{
|
||||
var errWriter = new StringWriter();
|
||||
Console.SetError(errWriter);
|
||||
|
||||
var response = new ManagementUnauthorized("corr-1", "Access denied");
|
||||
var exitCode = CommandHelpers.HandleResponse(response, "json");
|
||||
|
||||
Assert.Equal(2, exitCode);
|
||||
Assert.Contains("Access denied", errWriter.ToString());
|
||||
|
||||
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleResponse_UnexpectedType_ReturnsOne()
|
||||
{
|
||||
var errWriter = new StringWriter();
|
||||
Console.SetError(errWriter);
|
||||
|
||||
var exitCode = CommandHelpers.HandleResponse("unexpected", "json");
|
||||
|
||||
Assert.Equal(1, exitCode);
|
||||
Assert.Contains("Unexpected response type", errWriter.ToString());
|
||||
|
||||
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NewCorrelationId_ReturnsNonEmpty32CharHex()
|
||||
{
|
||||
var id = CommandHelpers.NewCorrelationId();
|
||||
|
||||
Assert.NotNull(id);
|
||||
Assert.Equal(32, id.Length);
|
||||
Assert.True(id.All(c => "0123456789abcdef".Contains(c)));
|
||||
}
|
||||
}
|
||||
102
tests/ScadaLink.CLI.Tests/OutputFormatterTests.cs
Normal file
102
tests/ScadaLink.CLI.Tests/OutputFormatterTests.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using ScadaLink.CLI;
|
||||
|
||||
namespace ScadaLink.CLI.Tests;
|
||||
|
||||
public class OutputFormatterTests
|
||||
{
|
||||
[Fact]
|
||||
public void WriteJson_WritesIndentedJson()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
OutputFormatter.WriteJson(new { Name = "test", Value = 42 });
|
||||
|
||||
var output = writer.ToString().Trim();
|
||||
Assert.Contains("\"name\"", output);
|
||||
Assert.Contains("\"value\": 42", output);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteError_WritesToStdErr()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetError(writer);
|
||||
|
||||
OutputFormatter.WriteError("something went wrong", "ERR_CODE");
|
||||
|
||||
var output = writer.ToString().Trim();
|
||||
Assert.Contains("something went wrong", output);
|
||||
Assert.Contains("ERR_CODE", output);
|
||||
|
||||
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteTable_RendersHeadersAndRows()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var headers = new[] { "Id", "Name", "Status" };
|
||||
var rows = new List<string[]>
|
||||
{
|
||||
new[] { "1", "Alpha", "Active" },
|
||||
new[] { "2", "Beta", "Inactive" }
|
||||
};
|
||||
|
||||
OutputFormatter.WriteTable(rows, headers);
|
||||
|
||||
var output = writer.ToString();
|
||||
Assert.Contains("Id", output);
|
||||
Assert.Contains("Name", output);
|
||||
Assert.Contains("Status", output);
|
||||
Assert.Contains("Alpha", output);
|
||||
Assert.Contains("Beta", output);
|
||||
Assert.Contains("Inactive", output);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteTable_EmptyRows_ShowsHeadersOnly()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var headers = new[] { "Id", "Name" };
|
||||
OutputFormatter.WriteTable(Array.Empty<string[]>(), headers);
|
||||
|
||||
var output = writer.ToString();
|
||||
Assert.Contains("Id", output);
|
||||
Assert.Contains("Name", output);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteTable_ColumnWidthsAdjustToContent()
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
Console.SetOut(writer);
|
||||
|
||||
var headers = new[] { "X", "LongColumnName" };
|
||||
var rows = new List<string[]>
|
||||
{
|
||||
new[] { "ShortValue", "Y" }
|
||||
};
|
||||
|
||||
OutputFormatter.WriteTable(rows, headers);
|
||||
|
||||
var lines = writer.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
||||
// Header line: "X" should be padded to at least "ShortValue" width
|
||||
Assert.True(lines.Length >= 2);
|
||||
// The "X" column header should be padded wider than 1 character
|
||||
var headerLine = lines[0];
|
||||
Assert.True(headerLine.IndexOf("LongColumnName") > 1);
|
||||
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
}
|
||||
}
|
||||
28
tests/ScadaLink.CLI.Tests/ScadaLink.CLI.Tests.csproj
Normal file
28
tests/ScadaLink.CLI.Tests/ScadaLink.CLI.Tests.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/ScadaLink.CLI/ScadaLink.CLI.csproj" />
|
||||
<ProjectReference Include="../../src/ScadaLink.Commons/ScadaLink.Commons.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
83
tests/ScadaLink.CentralUI.Tests/ComponentRenderingTests.cs
Normal file
83
tests/ScadaLink.CentralUI.Tests/ComponentRenderingTests.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ScadaLink.CentralUI.Components.Pages;
|
||||
|
||||
namespace ScadaLink.CentralUI.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// bUnit rendering tests for CentralUI Blazor components.
|
||||
/// Verifies that pages render their expected markup structure.
|
||||
/// </summary>
|
||||
public class ComponentRenderingTests : BunitContext
|
||||
{
|
||||
[Fact]
|
||||
public void LoginPage_RendersForm_WithUsernameAndPasswordFields()
|
||||
{
|
||||
var cut = Render<Login>();
|
||||
|
||||
// Verify the form action
|
||||
var form = cut.Find("form");
|
||||
Assert.Equal("/auth/login", form.GetAttribute("action"));
|
||||
|
||||
// Verify username field
|
||||
var usernameInput = cut.Find("input#username");
|
||||
Assert.Equal("text", usernameInput.GetAttribute("type"));
|
||||
Assert.Equal("username", usernameInput.GetAttribute("name"));
|
||||
|
||||
// Verify password field
|
||||
var passwordInput = cut.Find("input#password");
|
||||
Assert.Equal("password", passwordInput.GetAttribute("type"));
|
||||
Assert.Equal("password", passwordInput.GetAttribute("name"));
|
||||
|
||||
// Verify submit button
|
||||
var submitButton = cut.Find("button[type='submit']");
|
||||
Assert.Contains("Sign In", submitButton.TextContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoginPage_WithoutError_DoesNotRenderAlert()
|
||||
{
|
||||
var cut = Render<Login>();
|
||||
|
||||
Assert.Throws<Bunit.ElementNotFoundException>(() => cut.Find("div.alert.alert-danger"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dashboard_RequiresAuthorizeAttribute()
|
||||
{
|
||||
var authorizeAttrs = typeof(Dashboard)
|
||||
.GetCustomAttributes(typeof(AuthorizeAttribute), true);
|
||||
Assert.NotEmpty(authorizeAttrs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateEditor_RequiresDesignPolicy()
|
||||
{
|
||||
var authorizeAttrs = typeof(ScadaLink.CentralUI.Components.Pages.Design.Templates)
|
||||
.GetCustomAttributes(typeof(AuthorizeAttribute), true);
|
||||
Assert.NotEmpty(authorizeAttrs);
|
||||
|
||||
var attr = (AuthorizeAttribute)authorizeAttrs[0];
|
||||
Assert.Equal("RequireDesign", attr.Policy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoginPage_RendersLdapCredentialHint()
|
||||
{
|
||||
var cut = Render<Login>();
|
||||
|
||||
Assert.Contains("LDAP credentials", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoginPage_RendersScadaLinkTitle()
|
||||
{
|
||||
var cut = Render<Login>();
|
||||
|
||||
var title = cut.Find("h4.card-title");
|
||||
Assert.Equal("ScadaLink", title.TextContent);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="bunit" Version="2.0.33-preview" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
@@ -19,6 +21,10 @@
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/ScadaLink.CentralUI/ScadaLink.CentralUI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
namespace ScadaLink.ClusterInfrastructure.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for ClusterOptions default values and property setters.
|
||||
/// </summary>
|
||||
public class ClusterOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultValues_AreCorrect()
|
||||
{
|
||||
var options = new ClusterOptions();
|
||||
|
||||
Assert.Equal("keep-oldest", options.SplitBrainResolverStrategy);
|
||||
Assert.Equal(TimeSpan.FromSeconds(15), options.StableAfter);
|
||||
Assert.Equal(TimeSpan.FromSeconds(2), options.HeartbeatInterval);
|
||||
Assert.Equal(TimeSpan.FromSeconds(10), options.FailureDetectionThreshold);
|
||||
Assert.Equal(1, options.MinNrOfMembers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SeedNodes_DefaultsToEmptyList()
|
||||
{
|
||||
var options = new ClusterOptions();
|
||||
|
||||
Assert.NotNull(options.SeedNodes);
|
||||
Assert.Empty(options.SeedNodes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Properties_CanBeSetToCustomValues()
|
||||
{
|
||||
var options = new ClusterOptions
|
||||
{
|
||||
SeedNodes = new List<string> { "akka.tcp://system@node1:2551", "akka.tcp://system@node2:2551" },
|
||||
SplitBrainResolverStrategy = "keep-majority",
|
||||
StableAfter = TimeSpan.FromSeconds(30),
|
||||
HeartbeatInterval = TimeSpan.FromSeconds(5),
|
||||
FailureDetectionThreshold = TimeSpan.FromSeconds(20),
|
||||
MinNrOfMembers = 2
|
||||
};
|
||||
|
||||
Assert.Equal(2, options.SeedNodes.Count);
|
||||
Assert.Contains("akka.tcp://system@node1:2551", options.SeedNodes);
|
||||
Assert.Contains("akka.tcp://system@node2:2551", options.SeedNodes);
|
||||
Assert.Equal("keep-majority", options.SplitBrainResolverStrategy);
|
||||
Assert.Equal(TimeSpan.FromSeconds(30), options.StableAfter);
|
||||
Assert.Equal(TimeSpan.FromSeconds(5), options.HeartbeatInterval);
|
||||
Assert.Equal(TimeSpan.FromSeconds(20), options.FailureDetectionThreshold);
|
||||
Assert.Equal(2, options.MinNrOfMembers);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace ScadaLink.ClusterInfrastructure.Tests;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class LmxProxyDataConnectionTests
|
||||
{
|
||||
_mockClient = Substitute.For<ILmxProxyClient>();
|
||||
_mockFactory = Substitute.For<ILmxProxyClientFactory>();
|
||||
_mockFactory.Create(Arg.Any<string>(), Arg.Any<int>(), Arg.Any<string?>()).Returns(_mockClient);
|
||||
_mockFactory.Create(Arg.Any<string>(), Arg.Any<int>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<bool>()).Returns(_mockClient);
|
||||
_adapter = new LmxProxyDataConnection(_mockFactory, NullLogger<LmxProxyDataConnection>.Instance);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class LmxProxyDataConnectionTests
|
||||
});
|
||||
|
||||
Assert.Equal(ConnectionHealth.Connected, _adapter.Status);
|
||||
_mockFactory.Received(1).Create("myhost", 5001, null);
|
||||
_mockFactory.Received(1).Create("myhost", 5001, null, 0, false);
|
||||
await _mockClient.Received(1).ConnectAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class LmxProxyDataConnectionTests
|
||||
["ApiKey"] = "my-secret-key"
|
||||
});
|
||||
|
||||
_mockFactory.Received(1).Create("server", 50051, "my-secret-key");
|
||||
_mockFactory.Received(1).Create("server", 50051, "my-secret-key", 0, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -67,7 +67,7 @@ public class LmxProxyDataConnectionTests
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>());
|
||||
|
||||
_mockFactory.Received(1).Create("localhost", 50051, null);
|
||||
_mockFactory.Received(1).Create("localhost", 50051, null, 0, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -201,7 +201,7 @@ public class LmxProxyDataConnectionTests
|
||||
{
|
||||
await ConnectAdapter();
|
||||
var mockSub = Substitute.For<ILmxSubscription>();
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<CancellationToken>())
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<Action?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(mockSub);
|
||||
|
||||
var subId = await _adapter.SubscribeAsync("Tag1", (_, _) => { });
|
||||
@@ -209,7 +209,7 @@ public class LmxProxyDataConnectionTests
|
||||
Assert.NotNull(subId);
|
||||
Assert.NotEmpty(subId);
|
||||
await _mockClient.Received(1).SubscribeAsync(
|
||||
Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<CancellationToken>());
|
||||
Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<Action?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -217,7 +217,7 @@ public class LmxProxyDataConnectionTests
|
||||
{
|
||||
await ConnectAdapter();
|
||||
var mockSub = Substitute.For<ILmxSubscription>();
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<CancellationToken>())
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<Action?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(mockSub);
|
||||
|
||||
var subId = await _adapter.SubscribeAsync("Tag1", (_, _) => { });
|
||||
@@ -240,7 +240,7 @@ public class LmxProxyDataConnectionTests
|
||||
{
|
||||
await ConnectAdapter();
|
||||
var mockSub = Substitute.For<ILmxSubscription>();
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<CancellationToken>())
|
||||
_mockClient.SubscribeAsync(Arg.Any<IEnumerable<string>>(), Arg.Any<Action<string, LmxVtq>>(), Arg.Any<Action?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(mockSub);
|
||||
await _adapter.SubscribeAsync("Tag1", (_, _) => { });
|
||||
|
||||
@@ -277,4 +277,46 @@ public class LmxProxyDataConnectionTests
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
_adapter.SubscribeAsync("tag1", (_, _) => { }));
|
||||
}
|
||||
|
||||
// --- Configuration Parsing ---
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_ParsesSamplingInterval()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["Host"] = "server",
|
||||
["Port"] = "50051",
|
||||
["SamplingIntervalMs"] = "500"
|
||||
});
|
||||
|
||||
_mockFactory.Received(1).Create("server", 50051, null, 500, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_ParsesUseTls()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["Host"] = "server",
|
||||
["Port"] = "50051",
|
||||
["UseTls"] = "true"
|
||||
});
|
||||
|
||||
_mockFactory.Received(1).Create("server", 50051, null, 0, true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_DefaultsSamplingAndTls()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>());
|
||||
|
||||
_mockFactory.Received(1).Create("localhost", 50051, null, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class OpcUaDataConnectionTests
|
||||
});
|
||||
|
||||
Assert.Equal(ConnectionHealth.Connected, _adapter.Status);
|
||||
await _mockClient.Received(1).ConnectAsync("opc.tcp://localhost:4840", Arg.Any<CancellationToken>());
|
||||
await _mockClient.Received(1).ConnectAsync("opc.tcp://localhost:4840", Arg.Any<OpcUaConnectionOptions?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,4 +149,123 @@ public class OpcUaDataConnectionTests
|
||||
|
||||
Assert.Equal(ConnectionHealth.Disconnected, _adapter.Status);
|
||||
}
|
||||
|
||||
// --- Configuration Parsing ---
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_ParsesAllConfigurationKeys()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["EndpointUrl"] = "opc.tcp://myserver:4840",
|
||||
["SessionTimeoutMs"] = "120000",
|
||||
["OperationTimeoutMs"] = "30000",
|
||||
["PublishingIntervalMs"] = "500",
|
||||
["KeepAliveCount"] = "5",
|
||||
["LifetimeCount"] = "15",
|
||||
["MaxNotificationsPerPublish"] = "200",
|
||||
["SamplingIntervalMs"] = "250",
|
||||
["QueueSize"] = "20",
|
||||
["SecurityMode"] = "SignAndEncrypt",
|
||||
["AutoAcceptUntrustedCerts"] = "false"
|
||||
});
|
||||
|
||||
await _mockClient.Received(1).ConnectAsync(
|
||||
"opc.tcp://myserver:4840",
|
||||
Arg.Is<OpcUaConnectionOptions?>(o =>
|
||||
o != null &&
|
||||
o.SessionTimeoutMs == 120000 &&
|
||||
o.OperationTimeoutMs == 30000 &&
|
||||
o.PublishingIntervalMs == 500 &&
|
||||
o.KeepAliveCount == 5 &&
|
||||
o.LifetimeCount == 15 &&
|
||||
o.MaxNotificationsPerPublish == 200 &&
|
||||
o.SamplingIntervalMs == 250 &&
|
||||
o.QueueSize == 20 &&
|
||||
o.SecurityMode == "SignAndEncrypt" &&
|
||||
o.AutoAcceptUntrustedCerts == false),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_UsesDefaults_WhenKeysNotProvided()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>());
|
||||
|
||||
await _mockClient.Received(1).ConnectAsync(
|
||||
"opc.tcp://localhost:4840",
|
||||
Arg.Is<OpcUaConnectionOptions?>(o =>
|
||||
o != null &&
|
||||
o.SessionTimeoutMs == 60000 &&
|
||||
o.OperationTimeoutMs == 15000 &&
|
||||
o.PublishingIntervalMs == 1000 &&
|
||||
o.KeepAliveCount == 10 &&
|
||||
o.LifetimeCount == 30 &&
|
||||
o.MaxNotificationsPerPublish == 100 &&
|
||||
o.SamplingIntervalMs == 1000 &&
|
||||
o.QueueSize == 10 &&
|
||||
o.SecurityMode == "None" &&
|
||||
o.AutoAcceptUntrustedCerts == true),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_IgnoresInvalidNumericValues()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["SessionTimeoutMs"] = "notanumber",
|
||||
["OperationTimeoutMs"] = "",
|
||||
["PublishingIntervalMs"] = "abc",
|
||||
["QueueSize"] = "12.5"
|
||||
});
|
||||
|
||||
await _mockClient.Received(1).ConnectAsync(
|
||||
Arg.Any<string>(),
|
||||
Arg.Is<OpcUaConnectionOptions?>(o =>
|
||||
o != null &&
|
||||
o.SessionTimeoutMs == 60000 &&
|
||||
o.OperationTimeoutMs == 15000 &&
|
||||
o.PublishingIntervalMs == 1000 &&
|
||||
o.QueueSize == 10),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_ParsesSecurityMode()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["SecurityMode"] = "Sign"
|
||||
});
|
||||
|
||||
await _mockClient.Received(1).ConnectAsync(
|
||||
Arg.Any<string>(),
|
||||
Arg.Is<OpcUaConnectionOptions?>(o => o != null && o.SecurityMode == "Sign"),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Connect_ParsesAutoAcceptCerts()
|
||||
{
|
||||
_mockClient.IsConnected.Returns(true);
|
||||
|
||||
await _adapter.ConnectAsync(new Dictionary<string, string>
|
||||
{
|
||||
["AutoAcceptUntrustedCerts"] = "false"
|
||||
});
|
||||
|
||||
await _mockClient.Received(1).ConnectAsync(
|
||||
Arg.Any<string>(),
|
||||
Arg.Is<OpcUaConnectionOptions?>(o => o != null && o.AutoAcceptUntrustedCerts == false),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class HealthReportSenderTests
|
||||
{
|
||||
var transport = new FakeTransport();
|
||||
var collector = new SiteHealthCollector();
|
||||
collector.SetActiveNode(true);
|
||||
var options = Options.Create(new HealthMonitoringOptions
|
||||
{
|
||||
ReportInterval = TimeSpan.FromMilliseconds(50)
|
||||
@@ -61,6 +62,7 @@ public class HealthReportSenderTests
|
||||
{
|
||||
var transport = new FakeTransport();
|
||||
var collector = new SiteHealthCollector();
|
||||
collector.SetActiveNode(true);
|
||||
var options = Options.Create(new HealthMonitoringOptions
|
||||
{
|
||||
ReportInterval = TimeSpan.FromMilliseconds(50)
|
||||
@@ -91,6 +93,7 @@ public class HealthReportSenderTests
|
||||
{
|
||||
var transport = new FakeTransport();
|
||||
var collector = new SiteHealthCollector();
|
||||
collector.SetActiveNode(true);
|
||||
var options = Options.Create(new HealthMonitoringOptions
|
||||
{
|
||||
ReportInterval = TimeSpan.FromMilliseconds(50)
|
||||
|
||||
@@ -17,7 +17,7 @@ public class InboundScriptExecutorTests
|
||||
|
||||
public InboundScriptExecutorTests()
|
||||
{
|
||||
_executor = new InboundScriptExecutor(NullLogger<InboundScriptExecutor>.Instance);
|
||||
_executor = new InboundScriptExecutor(NullLogger<InboundScriptExecutor>.Instance, Substitute.For<IServiceProvider>());
|
||||
var locator = Substitute.For<IInstanceLocator>();
|
||||
var commService = Substitute.For<CommunicationService>(
|
||||
Microsoft.Extensions.Options.Options.Create(new CommunicationOptions()),
|
||||
@@ -47,9 +47,10 @@ public class InboundScriptExecutorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnregisteredHandler_ReturnsFailure()
|
||||
public async Task UnregisteredHandler_InvalidScript_ReturnsCompilationFailure()
|
||||
{
|
||||
var method = new ApiMethod("unknown", "return 1;") { Id = 1, TimeoutSeconds = 10 };
|
||||
// Use an invalid script that cannot be compiled by Roslyn
|
||||
var method = new ApiMethod("unknown", "%%% invalid C# %%%") { Id = 1, TimeoutSeconds = 10 };
|
||||
|
||||
var result = await _executor.ExecuteAsync(
|
||||
method,
|
||||
@@ -58,7 +59,22 @@ public class InboundScriptExecutorTests
|
||||
TimeSpan.FromSeconds(10));
|
||||
|
||||
Assert.False(result.Success);
|
||||
Assert.Contains("not compiled", result.ErrorMessage);
|
||||
Assert.Contains("Script compilation failed", result.ErrorMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnregisteredHandler_ValidScript_LazyCompiles()
|
||||
{
|
||||
// Valid script that is not pre-registered triggers lazy compilation
|
||||
var method = new ApiMethod("lazy", "return 1;") { Id = 1, TimeoutSeconds = 10 };
|
||||
|
||||
var result = await _executor.ExecuteAsync(
|
||||
method,
|
||||
new Dictionary<string, object?>(),
|
||||
_route,
|
||||
TimeSpan.FromSeconds(10));
|
||||
|
||||
Assert.True(result.Success);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -3,6 +3,7 @@ using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
using ScadaLink.Commons.Entities.Notifications;
|
||||
using ScadaLink.Commons.Interfaces.Repositories;
|
||||
using ScadaLink.StoreAndForward;
|
||||
|
||||
namespace ScadaLink.NotificationService.Tests;
|
||||
|
||||
@@ -145,4 +146,50 @@ public class NotificationDeliveryServiceTests
|
||||
Assert.False(result.Success);
|
||||
Assert.Contains("store-and-forward not available", result.ErrorMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Send_UsesBccDelivery_AllRecipientsInBcc()
|
||||
{
|
||||
SetupHappyPath();
|
||||
IEnumerable<string>? capturedBcc = null;
|
||||
_smtpClient.SendAsync(
|
||||
Arg.Any<string>(),
|
||||
Arg.Do<IEnumerable<string>>(bcc => capturedBcc = bcc),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var service = CreateService();
|
||||
await service.SendAsync("ops-team", "Alert", "Body");
|
||||
|
||||
Assert.NotNull(capturedBcc);
|
||||
var bccList = capturedBcc!.ToList();
|
||||
Assert.Equal(2, bccList.Count);
|
||||
Assert.Contains("alice@example.com", bccList);
|
||||
Assert.Contains("bob@example.com", bccList);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Send_TransientError_WithStoreAndForward_BuffersMessage()
|
||||
{
|
||||
SetupHappyPath();
|
||||
_smtpClient.SendAsync(Arg.Any<string>(), Arg.Any<IEnumerable<string>>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Throws(new TimeoutException("Connection timed out"));
|
||||
|
||||
var dbName = $"file:sf_test_{Guid.NewGuid():N}?mode=memory&cache=shared";
|
||||
var storage = new StoreAndForward.StoreAndForwardStorage(
|
||||
$"Data Source={dbName}", NullLogger<StoreAndForward.StoreAndForwardStorage>.Instance);
|
||||
await storage.InitializeAsync();
|
||||
|
||||
var sfOptions = new StoreAndForward.StoreAndForwardOptions();
|
||||
var sfService = new StoreAndForward.StoreAndForwardService(
|
||||
storage, sfOptions, NullLogger<StoreAndForward.StoreAndForwardService>.Instance);
|
||||
|
||||
var service = CreateService(sf: sfService);
|
||||
var result = await service.SendAsync("ops-team", "Alert", "Body");
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.True(result.WasBuffered);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
|
||||
namespace ScadaLink.NotificationService.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for OAuth2 token flow — token acquisition, caching, and credential parsing.
|
||||
/// </summary>
|
||||
public class OAuth2TokenServiceTests
|
||||
{
|
||||
private static HttpClient CreateMockHttpClient(HttpStatusCode statusCode, string responseJson)
|
||||
{
|
||||
var handler = new MockHttpMessageHandler(statusCode, responseJson);
|
||||
return new HttpClient(handler);
|
||||
}
|
||||
|
||||
private static IHttpClientFactory CreateMockFactory(HttpClient client)
|
||||
{
|
||||
var factory = Substitute.For<IHttpClientFactory>();
|
||||
factory.CreateClient(Arg.Any<string>()).Returns(client);
|
||||
return factory;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTokenAsync_ReturnsAccessToken_FromTokenEndpoint()
|
||||
{
|
||||
var tokenResponse = JsonSerializer.Serialize(new
|
||||
{
|
||||
access_token = "mock-access-token-12345",
|
||||
expires_in = 3600,
|
||||
token_type = "Bearer"
|
||||
});
|
||||
|
||||
var client = CreateMockHttpClient(HttpStatusCode.OK, tokenResponse);
|
||||
var factory = CreateMockFactory(client);
|
||||
var service = new OAuth2TokenService(factory, NullLogger<OAuth2TokenService>.Instance);
|
||||
|
||||
var token = await service.GetTokenAsync("tenant123:client456:secret789");
|
||||
|
||||
Assert.Equal("mock-access-token-12345", token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTokenAsync_CachesToken_OnSubsequentCalls()
|
||||
{
|
||||
var tokenResponse = JsonSerializer.Serialize(new
|
||||
{
|
||||
access_token = "cached-token",
|
||||
expires_in = 3600,
|
||||
token_type = "Bearer"
|
||||
});
|
||||
|
||||
var handler = new CountingHttpMessageHandler(HttpStatusCode.OK, tokenResponse);
|
||||
var client = new HttpClient(handler);
|
||||
var factory = CreateMockFactory(client);
|
||||
var service = new OAuth2TokenService(factory, NullLogger<OAuth2TokenService>.Instance);
|
||||
|
||||
var token1 = await service.GetTokenAsync("tenant:client:secret");
|
||||
var token2 = await service.GetTokenAsync("tenant:client:secret");
|
||||
|
||||
Assert.Equal("cached-token", token1);
|
||||
Assert.Equal("cached-token", token2);
|
||||
Assert.Equal(1, handler.CallCount); // Only one HTTP call should be made
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTokenAsync_InvalidCredentialFormat_ThrowsInvalidOperationException()
|
||||
{
|
||||
var client = CreateMockHttpClient(HttpStatusCode.OK, "{}");
|
||||
var factory = CreateMockFactory(client);
|
||||
var service = new OAuth2TokenService(factory, NullLogger<OAuth2TokenService>.Instance);
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => service.GetTokenAsync("invalid-no-colons"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTokenAsync_HttpFailure_ThrowsHttpRequestException()
|
||||
{
|
||||
var client = CreateMockHttpClient(HttpStatusCode.Unauthorized, "Unauthorized");
|
||||
var factory = CreateMockFactory(client);
|
||||
var service = new OAuth2TokenService(factory, NullLogger<OAuth2TokenService>.Instance);
|
||||
|
||||
await Assert.ThrowsAsync<HttpRequestException>(
|
||||
() => service.GetTokenAsync("tenant:client:secret"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple mock HTTP handler that returns a fixed response.
|
||||
/// </summary>
|
||||
private class MockHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
private readonly HttpStatusCode _statusCode;
|
||||
private readonly string _responseContent;
|
||||
|
||||
public MockHttpMessageHandler(HttpStatusCode statusCode, string responseContent)
|
||||
{
|
||||
_statusCode = statusCode;
|
||||
_responseContent = responseContent;
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new HttpResponseMessage(_statusCode)
|
||||
{
|
||||
Content = new StringContent(_responseContent)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mock HTTP handler that counts invocations.
|
||||
/// </summary>
|
||||
private class CountingHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
private readonly HttpStatusCode _statusCode;
|
||||
private readonly string _responseContent;
|
||||
public int CallCount { get; private set; }
|
||||
|
||||
public CountingHttpMessageHandler(HttpStatusCode statusCode, string responseContent)
|
||||
{
|
||||
_statusCode = statusCode;
|
||||
_responseContent = responseContent;
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
CallCount++;
|
||||
return Task.FromResult(new HttpResponseMessage(_statusCode)
|
||||
{
|
||||
Content = new StringContent(_responseContent)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/ScadaLink.NotificationService/ScadaLink.NotificationService.csproj" />
|
||||
<ProjectReference Include="../../src/ScadaLink.Commons/ScadaLink.Commons.csproj" />
|
||||
<ProjectReference Include="../../src/ScadaLink.StoreAndForward/ScadaLink.StoreAndForward.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user