ServiceStack 单元测试 - serviceStack 响应对象未初始化

ServiceStack Unit test- serviceStack Response object is not initializing

我已经使用Nunit 框架为ServiceStack api 编写了单元测试。 代码如下

public class AppHost : AppHostBase
{
    public AppHost()
        : base("SearchService", typeof(SearchService).Assembly)
    {

    }
}

服务class如下

public class SearchService:Service
{
   public SearchResponse Get(SearchRequest request)
   { 
     // to stuff
     Response.StatusCode = (int)HttpStatusCode.OK;
     return SearchReponse;
   }
}

单元测试class如下

 [TestFixture]
public class SearchServiceTests
{
    private readonly ServiceStackHost appHost;

    public SearchServiceTests()
    {
        appHost = new BasicAppHost(typeof(SearchService).Assembly)
        {
        }.Init();

    }
     [TestFixtureTearDown]
    public void TestFixtureTearDown()
    {
        appHost.Dispose();
    }


    [Test]

    public void TestMethod1()
    {
        var service = appHost.Container.Resolve<SearchService>();

        var r= service.Get(new SearchRequest());

       Assert.That(r, Is.Not.Null);

    }
    }

我收到 Response 对象的空引用异常。当我使用任何客户端(邮递员或休息客户端)访问服务器时,响应对象正在初始化但通过单元测试响应对象没有被初始化,谁能告诉我为什么会这样? 提前致谢。

需要模拟请求对象。以便服务层初始化响应对象。

以下代码更改对我有用。

   var service = appHost.Container.Resolve<SearchService>();
        service.Request = new MockHttpRequest(); 

然后进行服务方法调用。