-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f55744d
commit ee4595c
Showing
18 changed files
with
582 additions
and
618 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,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); | ||
} | ||
|
||
} | ||
} |
This file contains 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
This file contains 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,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)); | ||
} | ||
|
||
} |
Oops, something went wrong.