public void DisposingMidScopeJumpsToOuterScope()
 {
     var threadStatic = new ThreadStatic<int>();
     threadStatic.Use(1);
     var midScope = threadStatic.Use(2);
     threadStatic.Use(3);
     Assert.AreEqual(3, threadStatic.Current);
     midScope.Dispose();
     Assert.AreEqual(1, threadStatic.Current);
 }
 public void DisposingInnerScopeTwiceHasNoEffect()
 {
     var threadStatic = new ThreadStatic<int>();
     threadStatic.Use(1);
     var innerScope = threadStatic.Use(2);
     Assert.AreEqual(2, threadStatic.Current);
     innerScope.Dispose();
     innerScope.Dispose();
     Assert.AreEqual(1, threadStatic.Current);
 }
Exemple #3
0
        public void DisposingMidScopeJumpsToOuterScope()
        {
            var threadStatic = new ThreadStatic <int>();

            threadStatic.Use(1);
            var midScope = threadStatic.Use(2);

            threadStatic.Use(3);
            Assert.AreEqual(3, threadStatic.Current);
            midScope.Dispose();
            Assert.AreEqual(1, threadStatic.Current);
        }
Exemple #4
0
        public void DisposingInnerScopeTwiceHasNoEffect()
        {
            var threadStatic = new ThreadStatic <int>();

            threadStatic.Use(1);
            var innerScope = threadStatic.Use(2);

            Assert.AreEqual(2, threadStatic.Current);
            innerScope.Dispose();
            innerScope.Dispose();
            Assert.AreEqual(1, threadStatic.Current);
        }
Exemple #5
0
        private void RegisterToCurrentThread()
        {
            if (!RegisteredLoggers.HasCurrent)
            {
                RegisteredLoggers.Use(new List <Logger>());
            }
            var thisType = GetType();

            foreach (Logger logger in RegisteredLoggers.Current)
            {
                if (logger.GetType() == thisType)
                {
                    if (thisType.Name.StartsWith("Mock") || thisType.Name.StartsWith("TextFile"))
                    {
                        RemoveExistingLoggerFromPreviousFailingTest();
                    }
                    else
                    {
                        throw new LoggerWasAlreadyAttached();
                    }
                    break;
                }
            }
            RegisteredLoggers.Current.Add(this);
        }
        public void CurrentIsAvailableOusideScopeIfFallbackSet()
        {
            var threadStatic = new ThreadStatic<Randomizer>(new PseudoRandom());
            using (threadStatic.Use(new FixedRandom()))
                Assert.IsTrue(threadStatic.Current is FixedRandom);

            Assert.IsTrue(threadStatic.Current is PseudoRandom);
        }
        public void CurrentIsAvailableOnlyWithinScopeIfNoFallbackSet()
        {
            var threadStatic = new ThreadStatic<string>();
            using (threadStatic.Use("abc"))
                Assert.AreEqual("abc", threadStatic.Current);

            Assert.IsFalse(threadStatic.HasCurrent);
        }
Exemple #8
0
        public void CurrentIsAvailableOutsideScopeIfFallbackSet()
        {
            var threadStatic = new ThreadStatic <Randomizer>(new PseudoRandom());

            using (threadStatic.Use(new FixedRandom()))
                Assert.IsTrue(threadStatic.Current is FixedRandom);
            Assert.IsTrue(threadStatic.Current is PseudoRandom);
        }
Exemple #9
0
        public void CurrentIsAvailableOnlyWithinScopeIfNoFallbackSet()
        {
            var threadStatic = new ThreadStatic <string>();

            using (threadStatic.Use("abc"))
                Assert.AreEqual("abc", threadStatic.Current);
            Assert.IsFalse(threadStatic.HasCurrent);
        }
Exemple #10
0
 private static void TestMidScope(ThreadStatic <int> threadStatic)
 {
     using (threadStatic.Use(2))
     {
         Assert.AreEqual(2, threadStatic.Current);
         TestInnerScope(threadStatic);
         Assert.AreEqual(2, threadStatic.Current);
     }
 }
 public void MultipleScopesPushAndPopCorrectly()
 {
     var threadStatic = new ThreadStatic<int>();
     using (threadStatic.Use(1))
     {
         Assert.AreEqual(1, threadStatic.Current);
         TestMidScope(threadStatic);
         Assert.AreEqual(1, threadStatic.Current);
     }
 }
Exemple #12
0
        public void MultipleScopesPushAndPopCorrectly()
        {
            var threadStatic = new ThreadStatic <int>();

            using (threadStatic.Use(1))
            {
                Assert.AreEqual(1, threadStatic.Current);
                TestMidScope(threadStatic);
                Assert.AreEqual(1, threadStatic.Current);
            }
        }
 private static void TestMidScope(ThreadStatic<int> threadStatic)
 {
     using (threadStatic.Use(2))
     {
         Assert.AreEqual(2, threadStatic.Current);
         TestInnerScope(threadStatic);
         Assert.AreEqual(2, threadStatic.Current);
     }
 }
 private static void TestInnerScope(ThreadStatic<int> threadStatic)
 {
     using (threadStatic.Use(3))
         Assert.AreEqual(3, threadStatic.Current);
 }
Exemple #15
0
 public static IDisposable Use(Randomizer randomizer)
 {
     return(ThreadStaticRandomizer.Use(randomizer));
 }
Exemple #16
0
 private static void TestInnerScope(ThreadStatic <int> threadStatic)
 {
     using (threadStatic.Use(3))
         Assert.AreEqual(3, threadStatic.Current);
 }