コード例 #1
0
        public void TestCurrentThread()
        {
            var ic = GetMock <IInternalContainer>();

            ic.Expect(c => c.CreateNewLog()).Return(null);
            var            context = new InjectionContext(ic);
            IContextHolder holder  = new ContextHolder(context, Thread.CurrentThread.ManagedThreadId);

            var ic2 = GetMock <IInternalContainer>();

            Assert.AreSame(context, holder.GetContext(ic2));
            holder.KillContext();
            CheckGet(holder);
        }
コード例 #2
0
        public void TestCurrentThread()
        {
            var internalContainerMock = GetMock <IInternalContainer>();

            internalContainerMock.Setup(c => c.CreateNewLog()).Returns((IGroboContainerLog)null);
            var            context = new InjectionContext(internalContainerMock.Object);
            IContextHolder holder  = new ContextHolder(context, Thread.CurrentThread.ManagedThreadId);

            var internalContainerMock2 = GetMock <IInternalContainer>();

            Assert.AreSame(context, holder.GetContext(internalContainerMock2.Object));
            holder.KillContext();
            CheckGet(holder);
        }
コード例 #3
0
        public void TestAnotherThread()
        {
            var threadId = Thread.CurrentThread.ManagedThreadId;
            var internalContainerMock = GetMock <IInternalContainer>();

            internalContainerMock.Setup(c => c.CreateNewLog()).Returns((IGroboContainerLog)null);
            IContextHolder holder = new ContextHolder(new InjectionContext(internalContainerMock.Object), threadId);
            var            task   = Task.Run(() =>
            {
                Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId);
                CheckGet(holder);
            });

            task.Wait(TimeSpan.FromSeconds(1));
            holder.KillContext();
            CheckGet(holder);
        }
コード例 #4
0
        public void TestAnotherThread()
        {
            var threadId = Thread.CurrentThread.ManagedThreadId;
            var ic       = GetMock <IInternalContainer>();

            ic.Expect(c => c.CreateNewLog()).Return(null);
            IContextHolder holder = new ContextHolder(new InjectionContext(ic), threadId);
            Action         check  = () =>
            {
                Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId);
                CheckGet(holder);
            };
            var result = check.BeginInvoke(null, null);

            Assert.That(result.AsyncWaitHandle.WaitOne(1000), "поток завис");
            holder.KillContext();
            CheckGet(holder);
        }