Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed May 24, 2024
1 parent b462533 commit 507b0f4
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />
<PackageReference Include="Grpc.Tools" Version="2.60.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 6 additions & 0 deletions src/WireMock.Net.Aspire/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]

// Needed for Moq in the UnitTest project
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
134 changes: 134 additions & 0 deletions test/WireMock.Net.Tests/Aspire/WireMockServerArgumentsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#if NET8_0_OR_GREATER
using Aspire.Hosting;
using FluentAssertions;
using Xunit;

namespace WireMock.Net.Tests.Aspire;

public class WireMockServerArgumentsTests
{
[Fact]
public void DefaultValues_ShouldBeSetCorrectly()
{
// Arrange & Act
var args = new WireMockServerArguments();

// Assert
args.Port.Should().Be(WireMockServerArguments.DefaultPort);
args.AdminUsername.Should().BeNull();
args.AdminPassword.Should().BeNull();
args.ReadStaticMappings.Should().BeFalse();
args.WithWatchStaticMappings.Should().BeFalse();
args.MappingsPath.Should().BeNull();
}

[Fact]
public void HasBasicAuthentication_ShouldReturnTrue_WhenUsernameAndPasswordAreProvided()
{
// Arrange
var args = new WireMockServerArguments
{
AdminUsername = "admin",
AdminPassword = "password"
};

// Act & Assert
args.HasBasicAuthentication.Should().BeTrue();
}

[Fact]
public void HasBasicAuthentication_ShouldReturnFalse_WhenEitherUsernameOrPasswordIsNotProvided()
{
// Arrange
var argsWithUsernameOnly = new WireMockServerArguments { AdminUsername = "admin" };
var argsWithPasswordOnly = new WireMockServerArguments { AdminPassword = "password" };

// Act & Assert
argsWithUsernameOnly.HasBasicAuthentication.Should().BeFalse();
argsWithPasswordOnly.HasBasicAuthentication.Should().BeFalse();
}

[Fact]
public void GetArgs_WhenReadStaticMappingsIsTrue_ShouldContainReadStaticMappingsTrue()
{
// Arrange
var args = new WireMockServerArguments
{
ReadStaticMappings = true
};

// Act
var commandLineArgs = args.GetArgs();

// Assert
commandLineArgs.Should().ContainInOrder("--ReadStaticMappings", "true");
}

[Fact]
public void GetArgs_WhenReadStaticMappingsIsFalse_ShouldNotContainReadStaticMappingsTrue()
{
// Arrange
var args = new WireMockServerArguments
{
ReadStaticMappings = false
};

// Act
var commandLineArgs = args.GetArgs();

// Assert
commandLineArgs.Should().NotContain("--ReadStaticMappings", "true");
}

[Fact]
public void GetArgs_WhenWithWatchStaticMappingsIsTrue_ShouldContainWatchStaticMappingsTrue()
{
// Arrange
var args = new WireMockServerArguments
{
WithWatchStaticMappings = true,
ReadStaticMappings = false // This needs to be false to check the independent effect of WithWatchStaticMappings
};

// Act
var commandLineArgs = args.GetArgs();

// Assert
commandLineArgs.Should().ContainInOrder("--ReadStaticMappings", "true", "--WatchStaticMappings", "true", "--WatchStaticMappingsInSubdirectories", "true");
}

[Fact]
public void GetArgs_WhenWithWatchStaticMappingsIsFalse_ShouldNotContainWatchStaticMappingsTrue()
{
// Arrange
var args = new WireMockServerArguments
{
WithWatchStaticMappings = false
};

// Act
var commandLineArgs = args.GetArgs();

// Assert
commandLineArgs.Should().NotContain("--WatchStaticMappings", "true").And.NotContain("--WatchStaticMappingsInSubdirectories", "true");
}

[Fact]
public void GetArgs_ShouldIncludeAuthenticationDetails_WhenAuthenticationIsRequired()
{
// Arrange
var args = new WireMockServerArguments
{
AdminUsername = "admin",
AdminPassword = "password"
};

// Act
var commandLineArgs = args.GetArgs();

// Assert
commandLineArgs.Should().Contain("--AdminUserName", "admin");
commandLineArgs.Should().Contain("--AdminPassword", "password");
}
}
#endif
7 changes: 5 additions & 2 deletions test/WireMock.Net.Tests/WireMock.Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="RestEase" Version="1.5.7" />
Expand Down Expand Up @@ -109,7 +108,7 @@
<PackageReference Include="JsonConverter.System.Text.Json" Version="0.5.0" />

<PackageReference Include="Google.Protobuf" Version="3.25.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />
<PackageReference Include="Grpc.Tools" Version="2.60.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -122,6 +121,10 @@
<ProjectReference Include="..\..\src\WireMock.Net.Testcontainers\WireMock.Net.Testcontainers.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<ProjectReference Include="..\..\src\WireMock.Net.Aspire\WireMock.Net.Aspire.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="OpenApiParser\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit 507b0f4

Please sign in to comment.