Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active November 22, 2023 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/114fbc40a89dbc65cfe9e04c2f4f8ef6 to your computer and use it in GitHub Desktop.
Save gistlyn/114fbc40a89dbc65cfe9e04c2f4f8ef6 to your computer and use it in GitHub Desktop.
.NET 6 ServiceStack Integration Test
<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>
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