コード例 #1
0
        public void getTwoInstanceWithoutParallerFirstCreateInstanceForOther()
        {
            WrongSingleton a = WrongSingleton.GetOn();
            WrongSingleton b = WrongSingleton.GetOn();

            Assert.IsTrue(object.ReferenceEquals(a, b));
        }
コード例 #2
0
 public void GetInstancesWithParallerCounterMoreThanOne()
 {
     Parallel.For(0, 100000, task =>
     {
         WrongSingleton.GetOn();
     });
     Assert.AreNotEqual(1, WrongSingleton.counter);
 }
コード例 #3
0
        public void RunTwoThreadsShouldMakeInstanceTwoTimes()
        {
            WrongSingleton b = null;
            WrongSingleton c = null;

            Parallel.Invoke(
                () => { b = WrongSingleton.GetOn(); },
                () => { c = WrongSingleton.GetOn(); }
                );
            Assert.AreNotSame(c, b);
            Assert.AreNotEqual(1, WrongSingleton.counter);
        }