MockFactory now creates fresh service provider and fresh in-memory db. fixes id increment issues when running tests in parallel. each test gets own db

This commit is contained in:
Sasha Pierson 2018-01-19 14:34:37 -08:00
Родитель 170bcca76b
Коммит 7d54e5d475
3 изменённых файлов: 16 добавлений и 5 удалений

2
domain

@ -1 +1 @@
Subproject commit 2179465ca563ece2224e3e486bd289407b3ee55a
Subproject commit 2871fa6d475c1f56f835e70c2aca7cbb5df0987f

Просмотреть файл

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PackageId>Microsoft.Sia.Connectors.Tickets</PackageId>
<Version>1.1.10-alpha</Version>
<Version>1.1.25-alpha</Version>
<Authors>Microsoft</Authors>
<Company>Microsoft</Company>
<Product>SRE Incident Assistant</Product>

Просмотреть файл

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace Sia.Gateway.Tests.TestDoubles
{
@ -27,9 +28,7 @@ namespace Sia.Gateway.Tests.TestDoubles
if(_contextBeingGenerated.TryAdd(instance, true))
{
var options = new DbContextOptionsBuilder<IncidentContext>()
.UseInMemoryDatabase(instance)
.Options;
var options = CreateFreshContextAndDb(instance);
context = new IncidentContext(options);
SeedData.Add(context);
_contextBeingGenerated.TryAdd(instance, false);
@ -42,5 +41,17 @@ namespace Sia.Gateway.Tests.TestDoubles
private static ConcurrentDictionary<string, bool> _contextBeingGenerated { get; set; } = new ConcurrentDictionary<string, bool>();
private static ConcurrentDictionary<string, IncidentContext> _contexts { get; set; } = new ConcurrentDictionary<string, IncidentContext>();
private static DbContextOptions<IncidentContext> CreateFreshContextAndDb(string instance)
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
var builder = new DbContextOptionsBuilder<IncidentContext>()
.UseInMemoryDatabase(instance)
.UseInternalServiceProvider(serviceProvider);
return builder.Options;
}
}
}