-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test project to minimal webservice template
- Loading branch information
1 parent
2dd3629
commit 74dddd9
Showing
6 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Templates/Webservice-Minimal/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<LangVersion>10.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
|
||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
|
||
<PackageReference Include="GenHTTP.Testing" Version="8.1.0" /> | ||
|
||
<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" /> | ||
|
||
</ItemGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
Templates/Webservice-Minimal/$safeprojectname$.Tests/BookServiceTests.cs
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using GenHTTP.Testing; | ||
|
||
namespace $safeprojectname$.Tests | ||
{ | ||
|
||
[TestClass] | ||
public class BookServiceTests | ||
{ | ||
|
||
[TestMethod] | ||
public async Task TestGetBooks() | ||
{ | ||
using var runner = TestHost.Run(Project.Setup()); | ||
|
||
using var response = await runner.GetResponseAsync("/books/"); | ||
|
||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using GenHTTP.Api.Content; | ||
|
||
using GenHTTP.Modules.Layouting; | ||
using GenHTTP.Modules.Security; | ||
using GenHTTP.Modules.Functional; | ||
|
||
namespace $safeprojectname$ | ||
{ | ||
|
||
record class Book(int ID, string Title); | ||
|
||
public static class Project | ||
{ | ||
|
||
public static IHandlerBuilder Setup() | ||
{ | ||
// run this project and fetch a list of book records via http://localhost:8080/books/ | ||
var books = new List<Book>() | ||
{ | ||
new Book(1, "Lord of the Rings") | ||
}; | ||
|
||
// see https://genhttp.org/documentation/content/functional | ||
var bookApi = Inline.Create() | ||
.Get(() => books) | ||
.Put((Book book) => books.Add(book)); | ||
|
||
return Layout.Create() | ||
.Add("books", bookApi) | ||
.Add(CorsPolicy.Permissive()); | ||
} | ||
|
||
} | ||
|
||
} |
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