Skip to content

Commit

Permalink
Update for GenHTTP 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Nov 18, 2024
1 parent f55744d commit ee4595c
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 618 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Idea
.idea/

# User-specific files
*.rsuser
*.suo
Expand Down
12 changes: 6 additions & 6 deletions MockH.Tests/MockH.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>

<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>

<LangVersion>10.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

Expand All @@ -15,12 +15,12 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Modules.DirectoryBrowsing" Version="8.5.0" />
<PackageReference Include="GenHTTP.Modules.DirectoryBrowsing" Version="9.0.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />

<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />

<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
53 changes: 25 additions & 28 deletions MockH.Tests/RedirectTests.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;

namespace MockH.Tests
namespace MockH.Tests;

[TestClass]
public class RedirectTests : ServerTest
{

[TestClass]
public class RedirectTests : ServerTest
[TestMethod]
public async Task RulesCanRedirectTemporarily()
{
await using var server = await MockServer.RunAsync
(
On.Get().Redirect("https://www.google.de")
);

[TestMethod]
public async Task RulesCanRedirectTemporarily()
{
using var server = MockServer.Run
(
On.Get().Redirect("https://www.google.de")
);

using var response = await GetAsync(server);

Assert.AreEqual(HttpStatusCode.TemporaryRedirect, response.StatusCode);
Assert.AreEqual(new Uri("https://www.google.de"), response.Headers.Location);
}
using var response = await GetAsync(server);

[TestMethod]
public async Task RulesCanRedirectPermanently()
{
using var server = MockServer.Run
(
On.Get().Redirect("https://www.google.de", temporary: false)
);
Assert.AreEqual(HttpStatusCode.TemporaryRedirect, response.StatusCode);
Assert.AreEqual(new Uri("https://www.google.de"), response.Headers.Location);
}

using var response = await GetAsync(server);
[TestMethod]
public async Task RulesCanRedirectPermanently()
{
await using var server = await MockServer.RunAsync
(
On.Get().Redirect("https://www.google.de", temporary: false)
);

Assert.AreEqual(HttpStatusCode.Moved, response.StatusCode);
Assert.AreEqual(new Uri("https://www.google.de"), response.Headers.Location);
}
using var response = await GetAsync(server);

Assert.AreEqual(HttpStatusCode.Moved, response.StatusCode);
Assert.AreEqual(new Uri("https://www.google.de"), response.Headers.Location);
}

}
}
29 changes: 13 additions & 16 deletions MockH.Tests/RespondTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;

namespace MockH.Tests
namespace MockH.Tests;

[TestClass]
public class RespondTests : ServerTest
{

[TestClass]
public class RespondTests : ServerTest
[TestMethod]
public async Task BasicResponse()
{
await using var server = await MockServer.RunAsync
(
On.Get().Respond(ResponseStatus.InternalServerError)
);

[TestMethod]
public async Task BasicResponse()
{
using var server = MockServer.Run
(
On.Get().Respond(ResponseStatus.InternalServerError)
);

using var response = await GetAsync(server);

Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
}
using var response = await GetAsync(server);

Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
}

}
}
47 changes: 22 additions & 25 deletions MockH.Tests/ReturnTests.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MockH.Tests
{
namespace MockH.Tests;

[TestClass]
public class ReturnTests : ServerTest
{
[TestClass]
public class ReturnTests : ServerTest
{

#region Supporting data structures

public record Data(string Value);
public record Data(string Value);

#endregion

[TestMethod]
public async Task RulesCanReturnPrimitiveTypes()
{
using var server = MockServer.Run
(
On.Get().Return(42)
);

Assert.AreEqual("42", await GetStringAsync(server));
}
[TestMethod]
public async Task RulesCanReturnPrimitiveTypes()
{
await using var server = await MockServer.RunAsync
(
On.Get().Return(42)
);

[TestMethod]
public async Task RulesCanReturnComplexTypes()
{
using var server = MockServer.Run
(
On.Get().Return(new Data("Hello World"))
);
Assert.AreEqual("42", await GetStringAsync(server));
}

Assert.AreEqual("{\"value\":\"Hello World\"}", await GetStringAsync(server));
}
[TestMethod]
public async Task RulesCanReturnComplexTypes()
{
await using var server = await MockServer.RunAsync
(
On.Get().Return(new Data("Hello World"))
);

Assert.AreEqual("{\"value\":\"Hello World\"}", await GetStringAsync(server));
}

}
Loading

0 comments on commit ee4595c

Please sign in to comment.