public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new NinjectRegistration(), new NinjectResolving()); var c = new StandardKernel(); c = (StandardKernel)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { obj1 = c.Get <ITestC>(); obj2 = c.Get <ITestC>(); }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new DryIocRegistration(), new DryIocResolving()); var c = new Container(scopeContext: new ThreadScopeContext()); c = (Container)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { using (var s = c.OpenScope()) { obj1 = c.Resolve <ITestC>(); obj2 = c.Resolve <ITestC>(); } }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new LightInjectRegistration(), new LightInjectResolving()); var c = new ServiceContainer(); c = (ServiceContainer)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { using (c.BeginScope()) { obj1 = c.GetInstance <ITestC>(); obj2 = c.GetInstance <ITestC>(); } }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new StructureMapRegistration(), new StructureMapResolving()); var c = new Container(); c = (Container)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { obj1 = c.GetInstance <ITestC>(); obj2 = c.GetInstance <ITestC>(); }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new GraceRegistration(), new GraceResolving()); var c = new DependencyInjectionContainer(); c = (DependencyInjectionContainer)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { using (var scope = c.BeginLifetimeScope()) { obj1 = scope.Locate <ITestC>(); obj2 = scope.Locate <ITestC>(); } }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_SameThread_Success() { ITestCase testCase = new PerThreadTestCaseC(new NiquIoCFullRegistration(), new NiquIoCFullResolving()); var c = new Container(); c = (Container)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread = new Thread(() => { obj1 = c.Resolve <ITestC>(ResolveKind.FullEmitFunction); obj2 = c.Resolve <ITestC>(ResolveKind.FullEmitFunction); }); thread.Start(); thread.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, true, true); }
public void RegisterPerThread_DifferentThreads_Success() { ITestCase testCase = new PerThreadTestCaseC(new AutofacRegistration(), new AutofacResolving()); var cb = new ContainerBuilder(); var c = (IContainer)testCase.Register(cb, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread1 = new Thread(() => { using (var threadLifetime = c.BeginLifetimeScope()) { obj1 = threadLifetime.Resolve <ITestC>(); } }); var thread2 = new Thread(() => { using (var threadLifetime = c.BeginLifetimeScope()) { obj2 = threadLifetime.Resolve <ITestC>(); } }); thread1.Start(); thread1.Join(); thread2.Start(); thread2.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, false, false); }
public void RegisterPerThread_DifferentThreads_Success() { ITestCase testCase = new PerThreadTestCaseC(new NiquIoCPartialRegistration(), new NiquIoCPartialResolving()); var c = new Container(); c = (Container)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread1 = new Thread(() => { obj1 = c.Resolve <ITestC>(ResolveKind.PartialEmitFunction); }); var thread2 = new Thread(() => { obj2 = c.Resolve <ITestC>(ResolveKind.PartialEmitFunction); }); thread1.Start(); thread1.Join(); thread2.Start(); thread2.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, false, false); }
public static void Check(ITestC testC1, ITestC testC2, bool singleton, bool singletonLast) { Assert.AreEqual(testC1.Equals(testC2), singleton); Assert.AreEqual(testC1.TestC44.Equals(testC2.TestC44), singleton); Assert.AreEqual(testC1.TestC43.Equals(testC2.TestC43), singleton); Assert.AreEqual(testC1.TestC42.Equals(testC2.TestC42), singleton); Assert.AreEqual(testC1.TestC41.Equals(testC2.TestC41), singleton); Assert.AreEqual(testC1.TestC40.Equals(testC2.TestC40), singleton); Assert.AreEqual(testC1.TestC44.TestC34.Equals(testC2.TestC44.TestC34), singleton); Assert.AreEqual(testC1.TestC44.TestC33.Equals(testC2.TestC44.TestC33), singleton); Assert.AreEqual(testC1.TestC44.TestC32.Equals(testC2.TestC44.TestC32), singleton); Assert.AreEqual(testC1.TestC44.TestC31.Equals(testC2.TestC44.TestC31), singleton); Assert.AreEqual(testC1.TestC44.TestC30.Equals(testC2.TestC44.TestC30), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.Equals(testC2.TestC44.TestC34.TestC24), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC23.Equals(testC2.TestC44.TestC34.TestC23), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC22.Equals(testC2.TestC44.TestC34.TestC22), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC21.Equals(testC2.TestC44.TestC34.TestC21), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC20.Equals(testC2.TestC44.TestC34.TestC20), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.TestC14.Equals(testC2.TestC44.TestC34.TestC24.TestC14), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.TestC13.Equals(testC2.TestC44.TestC34.TestC24.TestC13), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.TestC12.Equals(testC2.TestC44.TestC34.TestC24.TestC12), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.TestC11.Equals(testC2.TestC44.TestC34.TestC24.TestC11), singleton); Assert.AreEqual(testC1.TestC44.TestC34.TestC24.TestC10.Equals(testC2.TestC44.TestC34.TestC24.TestC10), singleton); Assert.AreEqual( testC1.TestC44.TestC34.TestC24.TestC14.TestC04.Equals(testC2.TestC44.TestC34.TestC24.TestC14.TestC04), singletonLast); Assert.AreEqual( testC1.TestC44.TestC34.TestC24.TestC14.TestC03.Equals(testC2.TestC44.TestC34.TestC24.TestC14.TestC03), singletonLast); Assert.AreEqual( testC1.TestC44.TestC34.TestC24.TestC14.TestC02.Equals(testC2.TestC44.TestC34.TestC24.TestC14.TestC02), singletonLast); Assert.AreEqual( testC1.TestC44.TestC34.TestC24.TestC14.TestC01.Equals(testC2.TestC44.TestC34.TestC24.TestC14.TestC01), singletonLast); Assert.AreEqual( testC1.TestC44.TestC34.TestC24.TestC14.TestC00.Equals(testC2.TestC44.TestC34.TestC24.TestC14.TestC00), singletonLast); }
public void RegisterPerThread_DifferentThreads_Success() { ITestCase testCase = new PerThreadTestCaseC(new SimpleInjectorRegistration(), new SimpleInjectorResolving()); var c = new Container(); c = (Container)testCase.Register(c, RegistrationKind.PerThread); ITestC obj1 = null; ITestC obj2 = null; var thread1 = new Thread(() => { using (c.BeginLifetimeScope()) { obj1 = c.GetInstance <ITestC>(); } }); var thread2 = new Thread(() => { using (c.BeginLifetimeScope()) { obj2 = c.GetInstance <ITestC>(); } }); thread1.Start(); thread1.Join(); thread2.Start(); thread2.Join(); CheckHelper.Check(obj1, true, true); CheckHelper.Check(obj2, true, true); CheckHelper.Check(obj1, obj2, false, false); }
public static void Check(ITestC test, bool singleton) { Assert.IsNotNull(test); Assert.IsNotNull(test.TestCa10); Assert.IsNotNull(test.TestCb10); Assert.IsNotNull(test.TestCc10); Assert.IsNotNull(test.TestCa10.TestCa9); Assert.IsNotNull(test.TestCa10.TestCa8); Assert.IsNotNull(test.TestCa10.TestCa7); Assert.IsNotNull(test.TestCa10.TestCa6); Assert.IsNotNull(test.TestCa10.TestCa5); Assert.IsNotNull(test.TestCa10.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa7); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa6); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa5); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa0); if (singleton) { Assert.AreEqual(test.TestCa10.TestCa8, test.TestCa10.TestCa9.TestCa8); Assert.AreEqual(test.TestCa10.TestCa7, test.TestCa10.TestCa9.TestCa7); Assert.AreEqual(test.TestCa10.TestCa6, test.TestCa10.TestCa9.TestCa6); Assert.AreEqual(test.TestCa10.TestCa5, test.TestCa10.TestCa9.TestCa5); Assert.AreEqual(test.TestCa10.TestCa4, test.TestCa10.TestCa9.TestCa4); Assert.AreEqual(test.TestCa10.TestCa3, test.TestCa10.TestCa9.TestCa3); Assert.AreEqual(test.TestCa10.TestCa2, test.TestCa10.TestCa9.TestCa2); Assert.AreEqual(test.TestCa10.TestCa1, test.TestCa10.TestCa9.TestCa1); Assert.AreEqual(test.TestCa10.TestCa0, test.TestCa10.TestCa9.TestCa0); } else { Assert.AreNotEqual(test.TestCa10.TestCa8, test.TestCa10.TestCa9.TestCa8); Assert.AreNotEqual(test.TestCa10.TestCa7, test.TestCa10.TestCa9.TestCa7); Assert.AreNotEqual(test.TestCa10.TestCa6, test.TestCa10.TestCa9.TestCa6); Assert.AreNotEqual(test.TestCa10.TestCa5, test.TestCa10.TestCa9.TestCa5); Assert.AreNotEqual(test.TestCa10.TestCa4, test.TestCa10.TestCa9.TestCa4); Assert.AreNotEqual(test.TestCa10.TestCa3, test.TestCa10.TestCa9.TestCa3); Assert.AreNotEqual(test.TestCa10.TestCa2, test.TestCa10.TestCa9.TestCa2); Assert.AreNotEqual(test.TestCa10.TestCa1, test.TestCa10.TestCa9.TestCa1); Assert.AreNotEqual(test.TestCa10.TestCa0, test.TestCa10.TestCa9.TestCa0); } Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa6); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa5); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa5); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa2); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa2.TestCa1); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa2.TestCa0); Assert.IsNotNull(test.TestCa10.TestCa9.TestCa8.TestCa7.TestCa6.TestCa5.TestCa4.TestCa3.TestCa2.TestCa1.TestCa0); }
public static void Check(ITestC testC, bool singleton, bool singletonLast) { Assert.IsNotNull(testC); Assert.IsNotNull(testC.TestC44); Assert.IsNotNull(testC.TestC43); Assert.IsNotNull(testC.TestC42); Assert.IsNotNull(testC.TestC41); Assert.IsNotNull(testC.TestC40); Assert.IsNotNull(testC.TestC44.TestC34); Assert.IsNotNull(testC.TestC44.TestC33); Assert.IsNotNull(testC.TestC44.TestC32); Assert.IsNotNull(testC.TestC44.TestC31); Assert.IsNotNull(testC.TestC44.TestC30); if (singleton) { Assert.AreEqual(testC.TestC44.TestC34, testC.TestC43.TestC34); Assert.AreEqual(testC.TestC44.TestC33, testC.TestC43.TestC33); Assert.AreEqual(testC.TestC44.TestC32, testC.TestC43.TestC32); Assert.AreEqual(testC.TestC44.TestC31, testC.TestC43.TestC31); Assert.AreEqual(testC.TestC44.TestC30, testC.TestC43.TestC30); } else { Assert.AreNotEqual(testC.TestC44.TestC34, testC.TestC43.TestC34); Assert.AreNotEqual(testC.TestC44.TestC33, testC.TestC43.TestC33); Assert.AreNotEqual(testC.TestC44.TestC32, testC.TestC43.TestC32); Assert.AreNotEqual(testC.TestC44.TestC31, testC.TestC43.TestC31); Assert.AreNotEqual(testC.TestC44.TestC30, testC.TestC43.TestC30); } if (singletonLast) { Assert.AreEqual(testC.TestC44.TestC34.TestC24.TestC14.TestC04, testC.TestC43.TestC34.TestC24.TestC14.TestC04); } else { Assert.AreNotEqual(testC.TestC44.TestC34.TestC24.TestC14.TestC04, testC.TestC43.TestC34.TestC24.TestC14.TestC04); } Assert.IsNotNull(testC.TestC44.TestC34.TestC24); Assert.IsNotNull(testC.TestC44.TestC34.TestC23); Assert.IsNotNull(testC.TestC44.TestC34.TestC22); Assert.IsNotNull(testC.TestC44.TestC34.TestC21); Assert.IsNotNull(testC.TestC44.TestC34.TestC20); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC13); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC12); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC11); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC10); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14.TestC04); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14.TestC03); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14.TestC02); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14.TestC01); Assert.IsNotNull(testC.TestC44.TestC34.TestC24.TestC14.TestC00); }