我目前正在尝试使用“Effort”框架(http://effort.codeplex.com/wikipage?title=Tutorials&referringTitle=Home)对实体框架的上下文类进行单元测试。
这是我的测试目前的样子:
[TestMethod]
public void GetUseraccountsForRealTest()
{
DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
SqlContext context = new SqlContext(connection);
context.TaskComment.Add(new TaskComment() { Id = 1, Message = "Test" });
}
最后一行不起作用。没发生什么事。
这是我的 SqlContext 类的外观:
public class SqlContext : DbContext
{
...
public IDbSet<TaskComment> TaskComment { get; set; }
...
//Constructor used by webserver
public SqlContext(string connectionString) : base(connectionString)
{
}
//Constructor used for unit testing
public SqlContext(DbConnection connection) : base(connection, true)
{
this.Configuration.LazyLoadingEnabled = false;
}
///
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
}
任何人都知道我该如何解决这个问题?没有任何“努力”的经验,也没有太多的文档。:-(