Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions StoneAge.TestUtils.Tests/MockLoggerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using StoneAge.TestUtils;
using Xunit;

namespace StoneAge.TestUtils.Tests
{
public class MockLoggerTests
{
[Fact]
public void Log_AddsEntry_ForGivenLogLevel()
{
var logger = new MockLogger<string>();
logger.Log(LogLevel.Information, new EventId(), "Test message", null, (s, e) => s);

Assert.Contains("Test message", logger.LogEntries[LogLevel.Information]);
}

[Fact]
public void IsEnabled_AlwaysReturnsTrue()
{
var logger = new MockLogger<string>();
Assert.True(logger.IsEnabled(LogLevel.Debug));
Assert.True(logger.IsEnabled(LogLevel.Warning));
}

[Fact]
public void Fetch_Entries_For_ReturnsEntries()
{
var logger = new MockLogger<string>();
logger.Log(LogLevel.Error, new EventId(), "Error logged", null, (s, e) => s);

var entries = logger.Fetch_Entries_For(LogLevel.Error);
Assert.Single(entries);
Assert.Equal("Error logged", entries.First());
}

[Fact]
public void BeginScope_ThrowsNotImplementedException()
{
var logger = new MockLogger<string>();
Assert.Throws<NotImplementedException>(() => logger.BeginScope("scope"));
}
}
}
33 changes: 33 additions & 0 deletions StoneAge.TestUtils.Tests/MockOptionsSnapshotTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using StoneAge.TestUtils;
using Xunit;

namespace StoneAge.TestUtils.Tests
{
public class MockOptionsSnapshotTests
{
private class Config
{
public int Value { get; set; }
}

[Fact]
public void Value_ReturnsInjectedInstance()
{
var config = new Config { Value = 123 };
var snapshot = new MockOptionsSnapshot<Config>(config);

Assert.Equal(123, snapshot.Value.Value);
Assert.Same(config, snapshot.Value);
}

[Fact]
public void Get_ThrowsNotImplementedException()
{
var config = new Config();
var snapshot = new MockOptionsSnapshot<Config>(config);

Assert.Throws<NotImplementedException>(() => snapshot.Get("any"));
}
}
}
23 changes: 23 additions & 0 deletions StoneAge.TestUtils.Tests/MockOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using StoneAge.TestUtils;
using Xunit;

namespace StoneAge.TestUtils.Tests
{
public class MockOptionsTests
{
private class Settings
{
public string Name { get; set; }
}

[Fact]
public void Value_ReturnsInjectedInstance()
{
var settings = new Settings { Name = "Test" };
var options = new MockOptions<Settings>(settings);

Assert.Equal("Test", options.Value.Name);
Assert.Same(settings, options.Value);
}
}
}
18 changes: 18 additions & 0 deletions StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
Comment on lines +9 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify package versions for currency and security.

Ensure the test package versions are current and free from known vulnerabilities.


🌐 Web query:

What are the latest versions of Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio NuGet packages for .NET 6.0 projects?

💡 Result:

For .NET 6.0 projects, the latest stable versions of the specified NuGet packages are:

  • Microsoft.NET.Test.Sdk: 17.13.0
  • xunit: 2.9.3
  • xunit.runner.visualstudio: 2.8.2

These versions are compatible with .NET 6.0 and are recommended for use in your testing projects.

To include these packages in your project, you can add the following to your .csproj file:

<ItemGroup>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
  <PackageReference Include="xunit" Version="2.9.3" />
  <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

Ensure that your project file targets the correct framework:

<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

After updating your project file, restore the packages using the following command:

dotnet restore

This will download and install the specified versions of the packages, making them available for your testing project.


🏁 Script executed:

#!/bin/bash
# Verify the target framework in the test project
grep -R "<TargetFramework>" -n StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj || echo "No <TargetFramework> tag found in the project file."

Length of output: 137


Update test project package versions to latest stable releases

The test project targets net6.0 (verified), but currently references older package versions. Please update the following in StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj:

• Microsoft.NET.Test.Sdk: 17.6.317.13.0
• xunit: 2.4.22.9.3
• xunit.runner.visualstudio: 2.4.52.8.2

Proposed diff:

<ItemGroup>
-  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
+  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
-  <PackageReference Include="xunit" Version="2.4.2" />
+  <PackageReference Include="xunit" Version="2.9.3" />
-  <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
+  <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

After updating, run:

dotnet restore

to install the new package versions.

🤖 Prompt for AI Agents
In StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj around lines 9 to
11, update the package versions to the latest stable releases compatible with
.NET 6.0. Change Microsoft.NET.Test.Sdk from 17.6.3 to 17.13.0, xunit from 2.4.2
to 2.9.3, and xunit.runner.visualstudio from 2.4.5 to 2.8.2. After modifying
these versions, run 'dotnet restore' to download and install the updated
packages.

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TestUtils\StoneAge.TestUtils.csproj" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions StoneAge.TestUtils.Tests/TestHttpClientBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Net.Http;
using System.Threading.Tasks;
using StoneAge.TestUtils;
using Xunit;

namespace StoneAge.TestUtils.Tests
{
public class TestHttpClientBuilderTests
{
[Fact]
public async Task Create_ReturnsClient_ThatReturnsPayload()
{
var builder = new TestHttpClientBuilder().With_Payload("{\"foo\":\"bar\"}");
var (client, handler) = builder.Create();

var response = await client.GetAsync("http://test");
var content = await response.Content.ReadAsStringAsync();

Assert.Equal("{\"foo\":\"bar\"}", content);
Assert.NotNull(handler.RequestMessage);
Assert.Equal("http://test/", handler.RequestMessage.RequestUri.ToString());
}

[Fact]
public async Task Create_ReturnsClient_WithDefaultPayload()
{
var builder = new TestHttpClientBuilder();
var (client, handler) = builder.Create();

var response = await client.GetAsync("http://test");
var content = await response.Content.ReadAsStringAsync();

Assert.Equal("{}", content);
}
}
}
54 changes: 54 additions & 0 deletions StoneAge.TestUtils.Tests/TestHttpMessageHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Net.Http;
using System.Threading.Tasks;
using StoneAge.TestUtils;
using Xunit;

namespace StoneAge.TestUtils.Tests
{
public class TestHttpMessageHandlerTests
{
[Fact]
public async Task SendAsync_ReturnsSpecifiedPayloadsInOrder()
{
var handler = new TestHttpMessageHandler()
.With_Payload("first")
.With_Payload("second");

var client = new HttpClient(handler);

var resp1 = await client.GetAsync("http://one");
var resp2 = await client.GetAsync("http://two");

var content1 = await resp1.Content.ReadAsStringAsync();
var content2 = await resp2.Content.ReadAsStringAsync();

Assert.Equal("first", content1);
Assert.Equal("second", content2);
}

[Fact]
public async Task SendAsync_ReturnsDefaultPayload_WhenNoneSpecified()
{
var handler = new TestHttpMessageHandler();
var client = new HttpClient(handler);

var resp = await client.GetAsync("http://none");
var content = await resp.Content.ReadAsStringAsync();

Assert.Equal("{}", content);
}

[Fact]
public async Task SendAsync_Sets_RequestMessage()
{
var handler = new TestHttpMessageHandler().With_Payload("payload");
var client = new HttpClient(handler);

var req = new HttpRequestMessage(HttpMethod.Get, "http://foo");
await client.SendAsync(req);

Assert.NotNull(handler.RequestMessage);
Assert.Equal("http://foo/", handler.RequestMessage.RequestUri.ToString());
}
}
}
21 changes: 14 additions & 7 deletions TestUtils.sln
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
# Visual Studio Version 17
VisualStudioVersion = 17.6.33804.203
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StoneAge.TestUtils", "TestUtils\StoneAge.TestUtils.csproj", "{5F82CAB0-84CF-43F2-8572-27A74D56DF20}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoneAge.TestUtils", "TestUtils\StoneAge.TestUtils.csproj", "{C1E0C5AA-8D84-4D5B-90A6-7B091938E6C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoneAge.TestUtils.Tests", "StoneAge.TestUtils.Tests\StoneAge.TestUtils.Tests.csproj", "{D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|Any CPU.Build.0 = Release|Any CPU
{C1E0C5AA-8D84-4D5B-90A6-7B091938E6C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1E0C5AA-8D84-4D5B-90A6-7B091938E6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1E0C5AA-8D84-4D5B-90A6-7B091938E6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1E0C5AA-8D84-4D5B-90A6-7B091938E6C5}.Release|Any CPU.Build.0 = Release|Any CPU
{D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobalSection
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove the extra EndGlobalSection statement.

There's an extra EndGlobalSection statement that doesn't correspond to any opening GlobalSection. This could cause parsing issues in Visual Studio.

Apply this diff to fix the structural issue:

-EndGlobalSection

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In TestUtils.sln at line 25, there is an extra EndGlobalSection statement
without a matching opening GlobalSection. Remove this extra EndGlobalSection
line to fix the structural issue and prevent parsing errors in Visual Studio.

GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
Expand Down
Loading