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); }
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); }
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); }
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); }