2017-10-11 42 views
0

我使用EntityFramework Reverse POCO Generator具有标志EF反向POCO发电机单元测试

AddUnitTestingDbContext = true; // Will add a FakeDbContext and FakeDbSet for easy unit testing 

它创建FakeDbContextFakeDbSet进行单元测试,但里面FakeDbContext一些方法未实现。

public System.Data.Entity.Infrastructure.DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class 
    { 
     throw new System.NotImplementedException(); 
    } 
    public System.Data.Entity.Infrastructure.DbEntityEntry Entry(object entity) 
    { 
     throw new System.NotImplementedException(); 
    } 
    public System.Collections.Generic.IEnumerable<System.Data.Entity.Validation.DbEntityValidationResult> GetValidationErrors() 
    { 
     throw new System.NotImplementedException(); 
    } 
    public System.Data.Entity.DbSet Set(System.Type entityType) 
    { 
     throw new System.NotImplementedException(); 
    } 
    public System.Data.Entity.DbSet<TEntity> Set<TEntity>() where TEntity : class 
    { 
     throw new System.NotImplementedException(); 
    } 
    public override string ToString() 
    { 
     throw new System.NotImplementedException(); 
    } 

什么是覆盖它们或实现它们,这样我可以用我的单元测试这些调用的正确方法。

谢谢你的时间。

+0

我将离开假上下文作为“一次性”的产生和定制。 –

+0

我该怎么做? – Farukh

+0

移出环境。然后填写原始空白。 –

回答

0

我想通了。您可以在EF.Reverse.POCO.ttinclude文件中编写代码,该文件将被重新生成。打开该文件并找到功能设置()然后你可以写这样的东西来获得所需的功能。希望这会对某人有所帮助。

public System.Data.Entity.DbSet<TEntity> Set<TEntity>() where TEntity : 
class 
    { 
<# 
foreach (Table tbl in from t in tables.Where(t => !t.IsMapping && 
t.HasPrimaryKey).OrderBy(x => x.NameHumanCase) select t) 
{ 
#> 


     if(typeof(TEntity) == typeof(<#=tbl.NameHumanCaseWithSuffix #>)) 
     { 
      return <#=Inflector.MakePlural(tbl.NameHumanCase) #> as 
System.Data.Entity.DbSet<TEntity>; 
     } 

<# } #> 

     throw new System.NotImplementedException("Doesn't have this table type!"); 
    }