コード例 #1
0
        public void GetStringTest()
        {
            const int     n    = 5;
            Func <string> func = () => "Test string";
            var           lazy = LazyFactory <string> .CreateLazyMultipleThreaded(func);

            var threads = new Thread[n];
            var results = new string[n];

            for (int i = 0; i < n; ++i)
            {
                var localI = i;
                threads[i] = new Thread(() =>
                {
                    results[localI] = lazy.Get();
                });
            }

            foreach (var thread in threads)
            {
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.AreEqual("Test string", results[0]);
            for (int i = 0; i < n - 1; ++i)
            {
                Assert.IsTrue(results[i].Equals(results[i + 1]));
            }
        }
コード例 #2
0
        public void GetIntTest()
        {
            const int  n    = 10;
            Func <int> func = () => 11 - 38;
            var        lazy = LazyFactory <int> .CreateLazyMultipleThreaded(func);

            var threads = new Thread[n];
            var results = new int[n];

            for (int i = 0; i < n; ++i)
            {
                var localI = i;
                threads[i] = new Thread(() =>
                {
                    results[localI] = lazy.Get();
                });
            }

            foreach (var thread in threads)
            {
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.AreEqual(-27, results[0]);
            for (int i = 0; i < n - 1; ++i)
            {
                Assert.IsTrue(results[i].Equals(results[i + 1]));
            }
        }
コード例 #3
0
 public void FuncNullExceptionTest()
 {
     Assert.Throws <FuncNullException>(() => lazy = LazyFactory <string> .CreateLazySingleThreaded(null));
 }
コード例 #4
0
 public void Setup()
 {
     func = () => "test 123";
     lazy = LazyFactory <string> .CreateLazySingleThreaded(func);
 }
コード例 #5
0
 public void FuncNullExceptionTest()
 {
     Assert.Throws <FuncNullException>(() => LazyFactory <int> .CreateLazyMultipleThreaded(null));
 }
コード例 #6
0
        public void CreateLazyMultipleThreadedTest()
        {
            lazy = LazyFactory <bool> .CreateLazyMultipleThreaded(func);

            Assert.IsTrue(lazy != null);
        }