private static DatabaseInitializerResolver CreateResolver(IDatabaseInitializer <FakeContext1> initializer = null) { var resolver = new DatabaseInitializerResolver(); resolver.SetInitializer(typeof(FakeContext1), initializer ?? new Mock <IDatabaseInitializer <FakeContext1> >().Object); resolver.SetInitializer(typeof(FakeContext2), new Mock <IDatabaseInitializer <FakeContext2> >().Object); return(resolver); }
public void GetService_can_be_accessed_from_multiple_threads_concurrently() { for (var i = 0; i < 30; i++) { var bag = new ConcurrentBag <IDatabaseInitializer <FakeContext1> >(); var resolver = new DatabaseInitializerResolver(); var initializer = new Mock <IDatabaseInitializer <FakeContext1> >().Object; ExecuteInParallel( () => { resolver.SetInitializer(typeof(FakeContext1), initializer); bag.Add(resolver.GetService <IDatabaseInitializer <FakeContext1> >()); }); Assert.Equal(20, bag.Count); Assert.True(bag.All(c => initializer == c)); } }
public void GetService_can_be_accessed_from_multiple_threads_concurrently() { for (var i = 0; i < 30; i++) { var bag = new ConcurrentBag<IDatabaseInitializer<FakeContext1>>(); var resolver = new DatabaseInitializerResolver(); var initializer = new Mock<IDatabaseInitializer<FakeContext1>>().Object; ExecuteInParallel( () => { resolver.SetInitializer(typeof(FakeContext1), initializer); bag.Add(resolver.GetService<IDatabaseInitializer<FakeContext1>>()); }); Assert.Equal(20, bag.Count); Assert.True(bag.All(c => initializer == c)); } }
private static DatabaseInitializerResolver CreateResolver(IDatabaseInitializer<FakeContext1> initializer = null) { var resolver = new DatabaseInitializerResolver(); resolver.SetInitializer(typeof(FakeContext1), initializer ?? new Mock<IDatabaseInitializer<FakeContext1>>().Object); resolver.SetInitializer(typeof(FakeContext2), new Mock<IDatabaseInitializer<FakeContext2>>().Object); return resolver; }