Skip to content

Instantly share code, notes, and snippets.

Created February 15, 2013 00:49
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 anonymous/4957788 to your computer and use it in GitHub Desktop.
Save anonymous/4957788 to your computer and use it in GitHub Desktop.
Attempts to get unit tests working in ServiceStack
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
namespace MyAPI.ServiceInterface
{
[Route("/HelloWorld/Greeting/{FirstName}/{LastName}", "GET")]
[Route("/HelloWorld/Greeting/{FirstName}", "GET")]
public class HelloWorldName : IReturn<HelloWorldGreeting>
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class HelloWorldGreeting
{
public string Greeting { get; set; }
}
public class HelloWorldService : Service
{
public HelloWorldGreeting Get(HelloWorldName request)
{
var answer = new HelloWorldGreeting
{
Greeting = "Hello " + request.FirstName + " " + request.LastName
};
return answer;
}
}
}
using System;
using System.Collections.Generic;
using NUnit.Framework;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.ServiceHost;
using ServiceStack.Logging;
using ServiceStack.Logging.Support.Logging;
using MyAPI.ServiceInterface;
/*
* Most of this is copied from: https://gist.github.com/waynebrantley/4698629
*/
namespace MyAPI.Tests
{
[TestFixture]
public class HelloWorldTest : AppHostBase
{
private ILog log;
public HelloWorldTest() : base("Unit Tests", typeof(HelloWorldService).Assembly)
{
LogManager.LogFactory = new DebugLogFactory();
log = LogManager.GetLogger(GetType());
Instance = null;
}
public override void Configure(Funq.Container container) { }
[TestCase("John", "Smith", "Hello John Smith")]
public void TestCase(string firstname, string lastname, string answer)
{
var request = new HelloWorldName { FirstName = firstname, LastName = lastname };
/*
* Here is where an exception is thrown, stating "Unable to resolve service 'HelloWorldName',
* though HelloWorldName is actually a request DTO.
*/
var response = ExecuteService(request, EndpointAttributes.None);
Assert.That(response.Greeting, Is.EqualTo(answer));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment