由于我已经将RC Core从RC1更新为RC2,测试正在传递我的本地VS2015,但不会传递给TFS Build(VSTest)。
对于测试失败,我正在使用内存测试提供程序,如下所示:
/// <summary>
/// Initializes the in-memory database, as recommended by the EF Core
/// documentation.
/// </summary>
private DbContextOptions CreateNewContextOptions()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
var builder = new DbContextOptionsBuilder();
builder.UseInMemoryDatabase()
.UseInternalServiceProvider(serviceProvider);
return builder.Options;
}
[Test]
public void TestMethod()
{
//Arrange
var contextOptions = CreateNewContextOptions();
var dataMapper = new DAL.DataMappers.BuurtcampagneDataMapper(contextOptions);
//Act
dataMapper.Add(_buurtcampagne);
var count = dataMapper.FindAll();
//Assert
Assert.AreEqual(1, count);
}
数据访问如下:
ctor blabla..
private DbContextOptions _options;
public IEnumerable<Buurtcampagne> FindAll()
{
using (var context = new BuurkrachtContext(_options))
{
var query = context.Buurtcampagnes
.ToList();
return query;
}
}
public void Add(Buurtcampagne buurtcampagne)
{
using (var context = new BuurkrachtContext(_options))
{
context.Buurtcampagnes.Add(buurtcampagne);
context.SaveChanges();
}
}
错误堆栈跟踪如下:
System.AppDomainUnloadedException : Attempted to access an unloaded AppDomain.
at System.Runtime.Remoting.ObjectHandle.Unwrap()
at Microsoft.Extensions.Caching.Memory.CacheEntryHelper.get_Scopes()
at Microsoft.Extensions.Caching.Memory.CacheEntryHelper.EnterScope(CacheEntry entry)
at Microsoft.Extensions.Caching.Memory.CacheEntry..ctor(Object key, Action`1 notifyCacheEntryDisposed, Action`1 notifyCacheOfExpiration)
at Microsoft.Extensions.Caching.Memory.MemoryCache.CreateEntry(Object key)
at Microsoft.Extensions.Caching.Memory.CacheExtensions.Set[TItem](IMemoryCache cache, Object key, TItem value)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Remotion.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at InfoSupport.BSBuurkracht.DAL.DataMappers.BuurtcampagneDataMapper.FindAll() in D:\4\_work\2\s\BSBuurkracht\InfoSupport.BSBuurkracht.DAL\DataMappers\BuurtcampagneDataMapper.cs:line 62
at InfoSupport.BSBuurkracht.DALTests.EFCoreDataMapperTests.BuurtcampagneDataMapperTests.TestMethod() in D:\4\_work\2\s\BSBuurkracht\InfoSupport.BSBuurkracht.DALTests\EFCoreDataMapperTests\BuurtcampagneDataMapperTests.cs:line 49
谁能帮帮我?