简体   繁体   中英

Unit testing with Effort

I'm currently trying to unit test an context class of the Entity Framework with the "Effort" framework ( http://effort.codeplex.com/wikipage?title=Tutorials&referringTitle=Home ).

This is how my test currently looks:

[TestMethod]
public void GetUseraccountsForRealTest()
{
    DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
    SqlContext context = new SqlContext(connection);

    context.TaskComment.Add(new TaskComment() { Id = 1, Message = "Test" });
}

The last line isn't working. Nothing happens.

This is how my SqlContext class looks:

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>();   
    }
}

Anyone got an idea how I can solve this problem? Don't have any experience with "Effort" and there's not too much documentation. :-(

Solved the problem on my own. I didn't use IDbSet in my context, butt just DbSet which lead to some difficulties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM