Exemplo n.º 1
0
        public void CurrentIsAvailableOnlyWithinScopeIfNoFallbackSet()
        {
            var threadStatic = new ThreadStatic<string>();
            using (threadStatic.Use("abc"))
                Assert.AreEqual("abc", threadStatic.Current);

            Assert.IsFalse(threadStatic.HasCurrent);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void CurrentIsAvailableOnlyWithinScopeIfNoFallbackSet()
        {
            var threadStatic = new ThreadStatic <string>();

            using (threadStatic.Use("abc"))
                Assert.AreEqual("abc", threadStatic.Current);
            Assert.IsFalse(threadStatic.HasCurrent);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void NewThreadStaticVariableHasNoCurrentValue()
        {
            var threadStatic = new ThreadStatic <string>();

            Assert.IsFalse(threadStatic.HasCurrent);
            Assert.Throws <ThreadStatic <string> .NoValueAvailable>(
                () => Assert.IsNotNull(threadStatic.Current));
        }
Exemplo n.º 6
0
 private static void TestMidScope(ThreadStatic <int> threadStatic)
 {
     using (threadStatic.Use(2))
     {
         Assert.AreEqual(2, threadStatic.Current);
         TestInnerScope(threadStatic);
         Assert.AreEqual(2, threadStatic.Current);
     }
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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);
     }
 }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            IExample background = new BackgroundThreads();
            // background.Run();

            IExample parametrized = new ParametrizedThread();
            // parametrized.Run();

            IExample threadStatic = new ThreadStatic();

            // threadStatic.Run();

            // new ThreadPoolExample().Run();
            new ParallelExample().Run();
        }
Exemplo n.º 14
0
 private static void TestInnerScope(ThreadStatic<int> threadStatic)
 {
     using (threadStatic.Use(3))
         Assert.AreEqual(3, threadStatic.Current);
 }
Exemplo n.º 15
0
 public void NewThreadStaticVariableHasNoCurrentValue()
 {
     var threadStatic = new ThreadStatic<string>();
     Assert.IsFalse(threadStatic.HasCurrent);
     Assert.Throws<ThreadStatic<string>.NoValueAvailable>(
         () => Assert.IsNotNull(threadStatic.Current));
 }
Exemplo n.º 16
0
 public void NewThreadStaticVariableHasADefaultValue()
 {
     var threadStatic = new ThreadStatic<int>();
     Assert.AreEqual(0, threadStatic.CurrentOrDefault);
 }
Exemplo n.º 17
0
 private static void TestInnerScope(ThreadStatic <int> threadStatic)
 {
     using (threadStatic.Use(3))
         Assert.AreEqual(3, threadStatic.Current);
 }
Exemplo n.º 18
0
        public void NewThreadStaticVariableHasADefaultValue()
        {
            var threadStatic = new ThreadStatic <int>();

            Assert.AreEqual(0, threadStatic.CurrentOrDefault);
        }
Exemplo n.º 19
0
 private static void TestMidScope(ThreadStatic<int> threadStatic)
 {
     using (threadStatic.Use(2))
     {
         Assert.AreEqual(2, threadStatic.Current);
         TestInnerScope(threadStatic);
         Assert.AreEqual(2, threadStatic.Current);
     }
 }