-
Notifications
You must be signed in to change notification settings - Fork 0
added testing for things #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using NUnit.Framework; | ||
| using StoneAge.TestUtils; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace TestUtils.Tests; | ||
|
|
||
| public class HttpTests | ||
| { | ||
| [Test] | ||
| public void TestHttpClientBuilder_Create_ReturnsClientAndHandler() | ||
| { | ||
| // Arrange | ||
| var builder = new TestHttpClientBuilder(); | ||
|
|
||
| // Act | ||
| var (client, handler) = builder.Create(); | ||
|
|
||
| // Assert | ||
| Assert.That(client, Is.Not.Null); | ||
| Assert.That(handler, Is.Not.Null); | ||
| Assert.That(client.GetType(), Is.EqualTo(typeof(HttpClient))); | ||
| Assert.That(handler.GetType(), Is.EqualTo(typeof(TestHttpMessageHandler))); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestHttpClientBuilder_WithPayload_SetsPayload() | ||
| { | ||
| // Arrange | ||
| var expectedPayload = "{\"name\":\"test\"}"; | ||
| var builder = new TestHttpClientBuilder(); | ||
|
|
||
| // Act | ||
| var (client, _) = builder.With_Payload(expectedPayload).Create(); | ||
|
|
||
| // Assert | ||
| Assert.That(client, Is.Not.Null); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task TestHttpMessageHandler_SendAsync_ReturnsResponseWithPayload() | ||
| { | ||
| // Arrange | ||
| var expectedPayload = "{\"name\":\"test\"}"; | ||
| var builder = new TestHttpClientBuilder().With_Payload(expectedPayload); | ||
| var (client, handler) = builder.Create(); | ||
|
|
||
| // Act | ||
| var response = await client.GetAsync("https://example.com"); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
|
|
||
| // Assert | ||
| Assert.That(response.IsSuccessStatusCode, Is.True); | ||
| Assert.That(content, Is.EqualTo(expectedPayload)); | ||
| Assert.That(handler.RequestMessage, Is.Not.Null); | ||
| Assert.That(handler.RequestMessage.RequestUri?.Host, Is.EqualTo("example.com")); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using Microsoft.Extensions.Logging; | ||
| using NUnit.Framework; | ||
| using StoneAge.TestUtils; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace TestUtils.Tests; | ||
|
|
||
| public class MockLoggerTests | ||
| { | ||
| private MockLogger<MockLoggerTests> _logger; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| _logger = new MockLogger<MockLoggerTests>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Log_WhenCalled_StoresLogEntry() | ||
| { | ||
| // Arrange | ||
| var logLevel = LogLevel.Information; | ||
| var message = "Test log message"; | ||
|
|
||
| // Act | ||
| _logger.Log(logLevel, 0, message, null, (state, ex) => state.ToString()); | ||
|
|
||
| // Assert | ||
| Assert.That(_logger.LogEntries.ContainsKey(logLevel), Is.True); | ||
| Assert.That(_logger.LogEntries[logLevel], Contains.Item(message)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Fetch_Entries_For_WhenCalled_ReturnsEntriesForLevel() | ||
| { | ||
| // Arrange | ||
| var logLevel = LogLevel.Warning; | ||
| var message = "Warning message"; | ||
| _logger.Log(logLevel, 0, message, null, (state, ex) => state.ToString()); | ||
|
|
||
| // Act | ||
| List<string> entries = _logger.Fetch_Entries_For(logLevel); | ||
|
|
||
| // Assert | ||
| Assert.That(entries, Contains.Item(message)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsEnabled_Always_ReturnsTrue() | ||
| { | ||
| // Act & Assert | ||
| Assert.That(_logger.IsEnabled(LogLevel.Information), Is.True); | ||
| Assert.That(_logger.IsEnabled(LogLevel.Error), Is.True); | ||
| Assert.That(_logger.IsEnabled(LogLevel.Debug), Is.True); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using NUnit.Framework; | ||
| using StoneAge.TestUtils; | ||
|
|
||
| namespace TestUtils.Tests; | ||
|
|
||
| public class MockOptionsTests | ||
| { | ||
| private class TestOptions | ||
| { | ||
| public string? Name { get; set; } | ||
| public int Value { get; set; } | ||
| } | ||
|
|
||
| [Test] | ||
| public void Value_WhenAccessed_ReturnsProvidedValue() | ||
| { | ||
| // Arrange | ||
| var expectedOptions = new TestOptions { Name = "Test", Value = 42 }; | ||
| var mockOptions = new MockOptions<TestOptions>(expectedOptions); | ||
|
|
||
| // Act | ||
| var result = mockOptions.Value; | ||
|
|
||
| // Assert | ||
| Assert.That(result, Is.EqualTo(expectedOptions)); | ||
| Assert.That(result.Name, Is.EqualTo("Test")); | ||
| Assert.That(result.Value, Is.EqualTo(42)); | ||
| } | ||
| } | ||
|
|
||
| public class MockOptionsSnapshotTests | ||
| { | ||
| private class TestOptions | ||
| { | ||
| public string? Name { get; set; } | ||
| public int Value { get; set; } | ||
| } | ||
|
|
||
| [Test] | ||
| public void Value_WhenAccessed_ReturnsProvidedValue() | ||
| { | ||
| // Arrange | ||
| var expectedOptions = new TestOptions { Name = "Test", Value = 42 }; | ||
| var mockOptionsSnapshot = new MockOptionsSnapshot<TestOptions>(expectedOptions); | ||
|
|
||
| // Act | ||
| var result = mockOptionsSnapshot.Value; | ||
|
|
||
| // Assert | ||
| Assert.That(result, Is.EqualTo(expectedOptions)); | ||
| Assert.That(result.Name, Is.EqualTo("Test")); | ||
| Assert.That(result.Value, Is.EqualTo(42)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Get_WhenCalled_ThrowsNotImplementedException() | ||
| { | ||
| // Arrange | ||
| var options = new TestOptions(); | ||
| var mockOptionsSnapshot = new MockOptionsSnapshot<TestOptions>(options); | ||
|
|
||
| // Act & Assert | ||
| Assert.Throws<System.NotImplementedException>(() => mockOptionsSnapshot.Get("name")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector" Version="6.0.2" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
| <PackageReference Include="NUnit" Version="4.2.2" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="4.4.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="NUnit.Framework" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TestUtils\StoneAge.TestUtils.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,51 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 16 | ||
| VisualStudioVersion = 16.0.29009.5 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StoneAge.TestUtils", "TestUtils\StoneAge.TestUtils.csproj", "{5F82CAB0-84CF-43F2-8572-27A74D56DF20}" | ||
| 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 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {D0B5268A-049B-4892-96B6-A6F45F80032A} | ||
| EndGlobalSection | ||
| EndGlobal | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 16 | ||
| VisualStudioVersion = 16.0.29009.5 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StoneAge.TestUtils", "TestUtils\StoneAge.TestUtils.csproj", "{5F82CAB0-84CF-43F2-8572-27A74D56DF20}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils.Tests", "TestUtils.Tests\TestUtils.Tests.csproj", "{99F70BC2-53DC-46CE-A496-545EFF81D144}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Debug|x64 = Debug|x64 | ||
| Debug|x86 = Debug|x86 | ||
| Release|Any CPU = Release|Any CPU | ||
| Release|x64 = Release|x64 | ||
| Release|x86 = Release|x86 | ||
| 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}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Debug|x64.Build.0 = Debug|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Debug|x86.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 | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|x64.ActiveCfg = Release|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|x64.Build.0 = Release|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|x86.ActiveCfg = Release|Any CPU | ||
| {5F82CAB0-84CF-43F2-8572-27A74D56DF20}.Release|x86.Build.0 = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|x64.Build.0 = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Debug|x86.Build.0 = Debug|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|x64.ActiveCfg = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|x64.Build.0 = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|x86.ActiveCfg = Release|Any CPU | ||
| {99F70BC2-53DC-46CE-A496-545EFF81D144}.Release|x86.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {D0B5268A-049B-4892-96B6-A6F45F80032A} | ||
| EndGlobalSection | ||
| EndGlobal |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.