我有这样的服务:
public class PlayerService : Service
{
public IPlayerAppService PlayerAppService { get; set; }
public PlayerService (IPlayerAppService service)
{
if (service == null)
throw new ArgumentException ("Service null");
PlayerAppService = service;
}
public object Post (PlayerDTO request)
{
var newPlayer = new PlayerResponse ()
{
Player = PlayerAppService.SendPlayerLocation(request.Position.Latitude, request.Position.Longitude)
};
return new HttpResult (newPlayer)
{
StatusCode = System.Net.HttpStatusCode.Created,
Headers =
{
{ HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(newPlayer.Player.Id.ToString()) }
}
};
}
}
我已经手动验证了定位和响应看起来是正确的,从我的这个服务的部署。 我想弄清楚如何单元测试这个虽然。 我写了一个测试是这样的:
[TestFixture]
public class PlayerServiceTests
{
AppHost appHost;
[TestFixtureSetUp]
public void TestFixtureSetUp ()
{
appHost = new AppHost ();
appHost.Init ();
appHost.Start ("http://localhost:1337/");
}
[TestFixtureTearDown]
public void TestFixtureTearDown ()
{
appHost.Dispose ();
appHost = null;
}
[Test]
public void NewPlayer_Should_Return201AndLocation ()
{
// Arrange
PlayerService service = new PlayerService (appHost.TryResolve<IPlayerAppService>());
// Act
HttpResult response = (HttpResult)service.Post (It.IsAny<PlayerDTO>());
// Assert
Assert.NotNull (response);
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
Assert.AreEqual(response.Response.ToDto<PlayerResponse>().Player.Id.ToString(), response.Headers.Where(x=> x.Key == HttpHeaders.Location).SingleOrDefault().Value);
}
}
当我的单元测试,虽然运行base.Request。 你有,我怎么可以从我的单元测试填充这个有什么建议?