我今天开始使用 ServiceStack。所以,如果我做错了什么,请告诉我。
我正在尝试将 Db 注入到我的服务类中,为此我正在使用此代码
[TestFixture]
public class UserServiceTests
{
private UserService service;
[SetUp]
public void SetUp()
{
var appHost = new BasicAppHost();
var dbFactory = new OrmLiteConnectionFactory(":memory:", false, SqliteDialect.Provider);
appHost.Container.Register<IDbConnectionFactory>(dbFactory);
service = new UserService();
service.SetAppHost(appHost);
}
[Test]
public void Calling_post_method_with_valid_User_saves_it_in_database()
{
var User = new User { Name = "Acme Limited" };
var id = service.Post(User);
Assert.AreEqual(1, id);
}
}
有两个问题:1)我遇到异常:
Could not load file or assembly 'System.Data.SQLite, Version=1.0.82.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
有没有简单的方法来解决这个问题?我们真的需要 SQLite 进行测试吗,是否有可用的 Fake 对象?
2) 编译器警告 - service.SetAppHost(appHost)。SetAppHost 已弃用。如何在不使用 SetAppHost 的情况下将 Db 注入我的服务类?
有任何想法吗?