Last active
November 22, 2023 03:36
-
-
Save gistlyn/114fbc40a89dbc65cfe9e04c2f4f8ef6 to your computer and use it in GitHub Desktop.
.NET 6 ServiceStack Integration Test
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFrameworks>net8.0</TargetFrameworks> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="NUnit" Version="3.13.*" /> | |
<PackageReference Include="NUnit3TestAdapter" Version="4.1.*" /> | |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" /> | |
<PackageReference Include="ServiceStack" Version="8.*" /> | |
</ItemGroup> | |
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' "> | |
<PackageReference Include="ServiceStack.Kestrel" Version="8.*" /> | |
</ItemGroup> | |
</Project> |
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
using NUnit.Framework; | |
using Funq; | |
using ServiceStack; | |
public class Hello : IReturn<StringResponse> | |
{ | |
public string Name { get; set; } | |
} | |
class MyServices : Service | |
{ | |
public object Any(Hello request) => | |
new StringResponse { Result = $"Hello, {request.Name}!" }; | |
} | |
public class AppHost : AppSelfHostBase | |
{ | |
public AppHost() : base("MyApp Tests", typeof(MyServices).Assembly) {} | |
public override void Configure(Container container) | |
{ | |
} | |
} | |
[TestFixture] | |
public class MyAppTests | |
{ | |
const string BaseUrl = "http://localhost:2000/"; | |
ServiceStackHost appHost; | |
[OneTimeSetUp] | |
public void OneTimeSetUp() => appHost = new AppHost() | |
.Init() | |
.Start(BaseUrl); | |
[OneTimeTearDown] | |
public void OneTimeTearDown() => appHost.Dispose(); | |
[Test] | |
public void Can_call_Hello() | |
{ | |
var client = new JsonServiceClient(BaseUrl); | |
var response = client.Get(new Hello { Name = "Test" }); | |
Assert.That(response.Result, Is.EqualTo($"Hello, Test!")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment