Esempio n. 1
0
        public void СheckWithTheRace()
        {
            var lazy = LazyFactory.CreateMultiThreadLazy(() => DateTime.Now);

            const int length  = 10000;
            var       threads = new Thread[length];
            var       results = new DateTime[length];

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

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

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

            for (var i = 1; i < length; i++)
            {
                Assert.AreEqual(results[0], results[i]);
            }
        }
Esempio n. 2
0
        public void CheckWhetherSupplierCalledOnce_MultiThreadLazy()
        {
            var lazy   = LazyFactory.CreateMultiThreadLazy(() => DateTime.Now);
            var result = lazy.Get();

            Assert.AreEqual(result, lazy.Get());
            Assert.AreEqual(result, lazy.Get());
        }
Esempio n. 3
0
        public void IsItAllRightWithNull_MulriThreadLazy()
        {
            var lazy   = LazyFactory.CreateMultiThreadLazy <string>(() => null);
            var result = lazy.Get();

            Assert.AreEqual(result, null);
            Assert.AreEqual(result, lazy.Get());
        }
Esempio n. 4
0
        public void DoesItWorkAtAll_MultiThreadLazy()
        {
            var lazy = LazyFactory.CreateMultiThreadLazy(() => 48);

            Assert.AreEqual(48, lazy.Get());
        }