From 7d54e5d4753bc0da4f730f758ff2ea3d00cc44dc Mon Sep 17 00:00:00 2001 From: Sasha Pierson Date: Fri, 19 Jan 2018 14:34:37 -0800 Subject: [PATCH] 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 --- domain | 2 +- .../Sia.Connectors.Tickets.csproj | 2 +- .../TestDoubles/MockFactory.cs | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/domain b/domain index 2179465..2871fa6 160000 --- a/domain +++ b/domain @@ -1 +1 @@ -Subproject commit 2179465ca563ece2224e3e486bd289407b3ee55a +Subproject commit 2871fa6d475c1f56f835e70c2aca7cbb5df0987f diff --git a/src/Sia.Connectors.Tickets/Sia.Connectors.Tickets.csproj b/src/Sia.Connectors.Tickets/Sia.Connectors.Tickets.csproj index 47f3262..988de97 100644 --- a/src/Sia.Connectors.Tickets/Sia.Connectors.Tickets.csproj +++ b/src/Sia.Connectors.Tickets/Sia.Connectors.Tickets.csproj @@ -3,7 +3,7 @@ netcoreapp2.0 Microsoft.Sia.Connectors.Tickets - 1.1.10-alpha + 1.1.25-alpha Microsoft Microsoft SRE Incident Assistant diff --git a/test/Sia.Gateway.Tests/TestDoubles/MockFactory.cs b/test/Sia.Gateway.Tests/TestDoubles/MockFactory.cs index 5e11a1b..11698d8 100644 --- a/test/Sia.Gateway.Tests/TestDoubles/MockFactory.cs +++ b/test/Sia.Gateway.Tests/TestDoubles/MockFactory.cs @@ -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() - .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 _contextBeingGenerated { get; set; } = new ConcurrentDictionary(); private static ConcurrentDictionary _contexts { get; set; } = new ConcurrentDictionary(); + + private static DbContextOptions CreateFreshContextAndDb(string instance) + { + var serviceProvider = new ServiceCollection() + .AddEntityFrameworkInMemoryDatabase() + .BuildServiceProvider(); + var builder = new DbContextOptionsBuilder() + .UseInMemoryDatabase(instance) + .UseInternalServiceProvider(serviceProvider); + return builder.Options; + } } + }