What do I need to configure in the AppHost to test AutoQuery?
[Route("/regions", "GET")]
[AutoApply(Behavior.AuditQuery)]
public class QueryRegions : QueryDb<Region>
{
public long[] Ids { get; set; }
}
public class TestAppHost : AppSelfHostBase
{
public TestAppHost() : base("Region REST Example",
typeof(Skyler.AppHost).Assembly,
typeof(Skyler.ServiceInterface.MyServices).Assembly) { }
public override void Configure(Container container)
{
var config = container.Resolve<IConfiguration>();
var connectionString = config.GetConnectionString("DefaultConnection")
?? "Server=localhost;User Id=postgres;Password=XXXXX;Database=SkylerDB;Pooling=true;MinPoolSize=0;MaxPoolSize=200";
PostgreSqlDialect.Provider.NamingStrategy = new OrmLiteNamingStrategyBase();
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(
connectionString, PostgreSqlDialect.Provider));
}
}
[TestFixture]
public class TestRegionRestExample
{
const string BaseUri = "https://localhost:5001/";
ServiceStackHost appHost;
[OneTimeSetUp]
public void TestFixtureSetUp()
{
appHost = new RegionAppHost()
.Init()
.Start(BaseUri);
}
[OneTimeTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
[Test]
public void Run_QueryRegions1_REST_Example()
{
var client = new JsonServiceClient("https://localhost:5001/");
var response = client.Get(new QueryRegions());
Assert.That(response.Results.Count, Is.GreaterThan(0));
}
[Test]
public void Run_QueryRegions2_REST_Example()
{
var client = new JsonServiceClient("https://localhost:5001/api");
var response = client.Get(new QueryRegions());
Assert.That(response.Results.Count, Is.GreaterThan(0));
}
[Test]
public void Run_QueryRegions3_REST_Example()
{
QueryResponse<Region> response = "https://localhost:5001/api/QueryRegions"
.GetJsonFromUrl()
.FromJson<QueryResponse<Region>>();
}
}
Calling QueryRegions1 returns a “Not found”,
QueryRegions2 “The operation does not exist for this service”
QueryRegions2 “Response status code does not indicate success: 405 (Method Not Allowed)”