public void ShouldCReturnTheSameInstance() { var instance1 = ThreadSafeSingleton.GetInstance(); var instance2 = ThreadSafeSingleton.GetInstance(); instance1.Should().BeSameAs(instance2); }
public void ShouldCreateInstance() { var instance = ThreadSafeSingleton.GetInstance(); instance.Should().NotBeNull(); instance.Should().BeOfType <ThreadSafeSingleton>(); }
public int ProcessTo(int end) { int sum = 0; for (int i = _start; i <= end; ++i) { sum += i; } ThreadSafeSingleton.GetInstance().Log( "Processor обчислив деяке значення: " + sum); return(sum); }
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(); }
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(); }
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(); }