public void G_Safe_InstanceImplementation_WithLocks()
        {
            // Here we guarantee thread safety by using a thread safe implementation.
            // Care must be taken when modifying the implementation that we maintain the thread safety
            var results = new ConcurrentBag <int>();
            var opt     = new ParallelOptions {
                MaxDegreeOfParallelism = Iterations
            };

            ITwoPlusTwo implementation = new ThreadSafeInstanceTwoPlusTwo();

            Parallel.For(0, Iterations, opt, i =>
            {
                var result = implementation.CalculateTwoPlusTwo();
                results.Add(result);
            });

            Assert.IsEmpty(results.Where(r => r != RightAnswer));
        }
        public void A_SanityCheck()
        {
            ITwoPlusTwo implementation = new StaticTwoPlusTwo();
            var         result         = implementation.CalculateTwoPlusTwo();

            Assert.AreEqual(RightAnswer, result);

            implementation = SingletonTwoPlusTwo.Instance;
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new InstanceTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new ThreadSafeInstanceTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new LocalTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);
        }