示例#1
0
        public void ShouldCReturnTheSameInstance()
        {
            var instance1 = ThreadSafeSingleton.GetInstance();
            var instance2 = ThreadSafeSingleton.GetInstance();

            instance1.Should().BeSameAs(instance2);
        }
示例#2
0
        public void ShouldCreateInstance()
        {
            var instance = ThreadSafeSingleton.GetInstance();

            instance.Should().NotBeNull();
            instance.Should().BeOfType <ThreadSafeSingleton>();
        }
示例#3
0
            public int ProcessTo(int end)
            {
                int sum = 0;

                for (int i = _start; i <= end; ++i)
                {
                    sum += i;
                }
                ThreadSafeSingleton.GetInstance().Log(
                    "Processor обчислив деяке значення: " + sum);
                return(sum);
            }
示例#4
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            ThreadSafeSingleton logger    = ThreadSafeSingleton.GetInstance();
            Processor           processor = new Processor(1);

            logger.Log("Почалася робота...");
            processor.ProcessTo(5);
            logger.Log("Робота завершилася...");

            Console.ReadKey();
        }
示例#5
0
        public void ThreadSafeSingletonTest()
        {
            var process1 = new Thread(() => { ThreadSafeSingleton.GetInstance("FOO"); });

            var process2 = new Thread(() =>
            {
                ThreadSafeSingleton.GetInstance("BAR").Value.Should().Be("FOO");
                ;
            });

            process1.Start();
            process2.Start();

            process1.Join();
            process2.Join();
        }
示例#6
0
 public Processor(int start)
 {
     _start = start;
     ThreadSafeSingleton.GetInstance().Log("Processor створено.");
 }
 public void RunExample()
 {
     var singleton           = Singleton.GetInstance();
     var threadSafeSingleton = ThreadSafeSingleton.GetInstance();
     var lazySingleton       = LazySingleton.GetInstance();
 }