forked from ServiceStack/ServiceStack.Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHostBase.cs
More file actions
78 lines (66 loc) · 1.97 KB
/
TestHostBase.cs
File metadata and controls
78 lines (66 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using Funq;
using NUnit.Framework;
using ServiceStack.Configuration;
using ServiceStack.Data;
using ServiceStack.Examples.ServiceInterface;
using ServiceStack.Examples.ServiceInterface.Support;
using ServiceStack.Host;
using ServiceStack.Logging;
using ServiceStack.OrmLite;
using ServiceStack.Testing;
namespace ServiceStack.Examples.Tests
{
[TestFixture]
public class TestHostBase
{
protected const string InMemoryDb = ":memory:";
private static ILog log;
public readonly ServiceStackHost appHost;
public TestHostBase()
{
LogManager.LogFactory = new ConsoleLogFactory();
log = LogManager.GetLogger(GetType());
appHost = new BasicAppHost(typeof(GetFactorialService).Assembly) {
ConfigureContainer = Configure
}.Init();
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
protected IDbConnectionFactory ConnectionFactory
{
get
{
return appHost.Container.Resolve<IDbConnectionFactory>();
}
}
public void Configure(Container container)
{
container.Register<IAppSettings>(c => new AppSettings());
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(
InMemoryDb,
SqliteDialect.Provider));
ConfigureDatabase.Init(container.Resolve<IDbConnectionFactory>());
log.InfoFormat("TestAppHost Created: " + DateTime.Now);
}
/// <summary>
/// Process a webservice in-memory
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="request"></param>
/// <returns></returns>
public TResponse Send<TResponse>(object request)
{
return Send<TResponse>(request, RequestAttributes.None);
}
public TResponse Send<TResponse>(object request, RequestAttributes endpointAttrs)
{
return (TResponse)appHost.ServiceController.Execute(request,
new BasicRequest(request, endpointAttrs));
}
}
}