我一直在遵循各种示例来运行我的服务,并且通过 IIS,我现在看到了一个列出我的服务的元数据页面。但我也希望能够以自托管模式运行服务以进行自动化测试。我已经将这些ServiceModel
类分离到一个单独的程序集中,而不是Service
类,以便在没有我的服务的情况下更轻松地分发 ServiceModel 库。
这是 DTO 声明的一个示例:
[Api("GET or DELETE a single folder by id. Use POST to create a new Folder and PUT or PATCH to update it")]
[Route("/folders", "POST, PUT, PATCH")]
[Route("/folders/{Id}")]
public class Folder : IHasGuidId
{
这是开始的FolderService
:
public class FolderService : Service
{
public FolderResponse Get(Folder folder)
{
将此 AppHost 与 IIS 一起使用,我FolderService
在/metadata
.
internal class AtlasAppHost : AppHostBase
{
public AtlasAppHost() : base("API v3.0", typeof(FolderService).Assembly)
{
}
public override void Configure(Container container)
{
container.Adapter = new StructureMapContainerAdapter();
AtlasInit(Config);
}
internal void AtlasInit(EndpointHostConfig config)
{
JsConfig.ExcludeTypeInfo = true;
JsConfig.DateHandler = JsonDateHandler.ISO8601;
JsConfig.EmitCamelCaseNames = true;
config.EnableFeatures = Feature.All.Remove(Feature.Jsv | Feature.Soap | Feature.Csv);
}
}
但是,在IntegrationTestBase
下面,当我暂停调试器时,我看不到我的FolderService
under /metadata
,并且请求总是返回NotFound
[TestFixture]
public class ApiIntegrationTestBase
{
private TestAppHost _appHost;
protected const string TestServiceUrl = "http://localhost:9755/";
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
_appHost = new TestAppHost();
_appHost.Init();
_appHost.Start(TestServiceUrl);
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
_appHost.Dispose();
}
public class TestAppHost : AppHostHttpListenerBase
{
public TestAppHost()
: base("Test App Host", typeof(FolderService).Assembly)
{
}
public override void Configure(Container container)
{
var atlasAppHost = new AtlasAppHost();
atlasAppHost.Configure(container);
atlasAppHost.AtlasInit(Config);
Routes.AddFromAssembly(typeof (FolderService).Assembly);
}
}
}
FolderService
为了让我出现在自托管测试程序集中,我是否缺少一些东西?
谢谢!