Skip to content

Commit 2e11cf2

Browse files
author
Per Kops
committed
feat: adding unit-tests for KepwareConfigurationClientConnectivity.IsValidConnectivityName and KepwareConfigurationClientIotGateWayAgent.IsValidIotGatewayName
1 parent 85244f8 commit 2e11cf2

5 files changed

+112
-1
lines changed

Atc.Kepware.sln

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{DAC1423F-D
1414
EndProject
1515
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Kepware.Configuration.CLI", "src\Atc.Kepware.Configuration.CLI\Atc.Kepware.Configuration.CLI.csproj", "{268932F7-56E9-4B76-B488-1F398C71F7DE}"
1616
EndProject
17-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Kepware.Configuration.Contracts", "src\Atc.Kepware.Configuration.Contracts\Atc.Kepware.Configuration.Contracts.csproj", "{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}"
17+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Kepware.Configuration.Contracts", "src\Atc.Kepware.Configuration.Contracts\Atc.Kepware.Configuration.Contracts.csproj", "{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}"
18+
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{34BF79A8-5519-4C9C-94E6-8DBEE2EB2D64}"
20+
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Kepware.Configuration.Tests", "test\Atc.Kepware.Configuration.Tests\Atc.Kepware.Configuration.Tests.csproj", "{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}"
1822
EndProject
1923
Global
2024
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -34,6 +38,10 @@ Global
3438
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
3539
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
3640
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Release|Any CPU.Build.0 = Release|Any CPU
3745
EndGlobalSection
3846
GlobalSection(SolutionProperties) = preSolution
3947
HideSolutionNode = FALSE
@@ -42,6 +50,7 @@ Global
4250
{4856D04B-2DA5-4398-90C2-CF13B8FA6191} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
4351
{268932F7-56E9-4B76-B488-1F398C71F7DE} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
4452
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
53+
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156} = {34BF79A8-5519-4C9C-94E6-8DBEE2EB2D64}
4554
EndGlobalSection
4655
GlobalSection(ExtensibilityGlobals) = postSolution
4756
SolutionGuid = {04120463-05C5-417B-8D7A-2D7D35B71A07}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<IsTestProject>true</IsTestProject>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
12+
<PackageReference Include="xunit" Version="2.8.1" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
<PackageReference Include="coverlet.collector" Version="6.0.2">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\src\Atc.Kepware.Configuration\Atc.Kepware.Configuration.csproj" />
25+
</ItemGroup>
26+
27+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using System.Reflection;
2+
global using Atc.Kepware.Configuration.Services;
3+
global using Microsoft.Extensions.Logging.Abstractions;
4+
global using Xunit;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Atc.Kepware.Configuration.Tests;
2+
3+
public sealed class KepwareConfigurationClientConnectivityTests
4+
{
5+
[Theory]
6+
[InlineData("ValidChannelName", null, null, null, true)]
7+
[InlineData("Invalid.ChannelName", null, null, null, false)]
8+
[InlineData(" InvalidChannelName", null, null, null, false)]
9+
[InlineData("_ValidChannelName", null, null, null, false)]
10+
[InlineData("ValidChannelName", "ValidDeviceName", null, null, true)]
11+
[InlineData("ValidChannelName", "Invalid.DeviceName", null, null, false)]
12+
[InlineData("ValidChannelName", " InvalidDeviceName", null, null, false)]
13+
[InlineData("ValidChannelName", "_ValidDeviceName", null, null, false)]
14+
[InlineData("ValidChannelName", "ValidDeviceName", "ValidTagGroupName", null, true)]
15+
[InlineData("ValidChannelName", "ValidDeviceName", "Invalid.TagGroupName", null, false)]
16+
[InlineData("ValidChannelName", "ValidDeviceName", " InvalidTagGroupName", null, false)]
17+
[InlineData("ValidChannelName", "ValidDeviceName", "_ValidTagGroupName", null, false)]
18+
[InlineData("ValidChannelName", "ValidDeviceName", "ValidTagGroupName", new[] { "ValidTag1", "ValidTag2" }, true)]
19+
[InlineData("ValidChannelName", "ValidDeviceName", "ValidTagGroupName", new[] { "ValidTag1", "Invalid.Tag2" }, false)]
20+
[InlineData("ValidChannelName", "ValidDeviceName", "ValidTagGroupName", new[] { "ValidTag1", " InvalidTag2" }, false)]
21+
[InlineData("ValidChannelName", "ValidDeviceName", "ValidTagGroupName", new[] { "ValidTag1", "_InvalidTag2" }, false)]
22+
public void IsValidConnectivityName(
23+
string channelName,
24+
string? deviceName,
25+
string? tagGroupNameOrTagName,
26+
string[]? tagGroupStructure,
27+
bool expectedIsValid)
28+
{
29+
// Arrange
30+
using var client = new KepwareConfigurationClient(NullLoggerFactory.Instance);
31+
var methodInfo = typeof(KepwareConfigurationClient).GetMethod("IsValidConnectivityName", BindingFlags.NonPublic | BindingFlags.Static);
32+
33+
// Act
34+
var parameters = new object[] { channelName, deviceName, tagGroupNameOrTagName, tagGroupStructure, null };
35+
var result = (bool?)methodInfo!.Invoke(client, parameters) ?? false;
36+
37+
// Assert
38+
Assert.Equal(expectedIsValid, result);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Atc.Kepware.Configuration.Tests;
2+
3+
public sealed class KepwareConfigurationClientIotGateWayAgentTests
4+
{
5+
[Theory]
6+
[InlineData("ValidClientName", null, true)]
7+
[InlineData("Invalid.ClientName", null, false)]
8+
[InlineData(" InvalidClientName", null, false)]
9+
[InlineData("_ValidClientName", null, false)]
10+
[InlineData("ValidClientName", "ValidItemName", true)]
11+
[InlineData("ValidClientName", "Invalid.ItemName", false)]
12+
[InlineData("ValidClientName", " InvalidItemName", false)]
13+
[InlineData("ValidClientName", "_InvalidItemName", false)]
14+
15+
public void IsValidIotGatewayName(
16+
string clientName,
17+
string? iotItemName,
18+
bool expectedIsValid)
19+
{
20+
// Arrange
21+
using var client = new KepwareConfigurationClient(NullLoggerFactory.Instance);
22+
var methodInfo = typeof(KepwareConfigurationClient).GetMethod("IsValidIotGatewayName", BindingFlags.NonPublic | BindingFlags.Static);
23+
24+
// Act
25+
var parameters = new object[] { clientName, iotItemName, null };
26+
var result = (bool?)methodInfo!.Invoke(client, parameters) ?? false;
27+
28+
// Assert
29+
Assert.Equal(expectedIsValid, result);
30+
}
31+
}

0 commit comments

Comments
 (0)