예제 #1
0
        public void CalculatePiTest()
        {
            MainViewModel target = new MainViewModel();

            MockNotificationVisualizer notifyVisualizer  = new MockNotificationVisualizer();
            MockMessageVisualizer      messageVisualizer = new MockMessageVisualizer {
                Response = UICommand.Yes
            };

            ServiceLocator.Instance.Add(typeof(INotificationVisualizer), notifyVisualizer);
            ServiceLocator.Instance.Add(typeof(IMessageVisualizer), messageVisualizer);

            SynchronizationContext     savedContext = SynchronizationContext.Current;
            MockSynchronizationContext mockContext  = new MockSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(mockContext);

            target.CalculatePi.Execute(null);
            Assert.IsTrue(notifyVisualizer.WaitForDispose(TimeSpan.FromSeconds(10), mockContext));
            Assert.AreEqual(Math.PI.ToString(), target.PiText);

            Assert.IsTrue(notifyVisualizer.LastBeginCall != null);
            Assert.IsTrue(notifyVisualizer.LastDisposeCall != null);
            Assert.IsTrue(notifyVisualizer.LastDisposeCall > notifyVisualizer.LastBeginCall);

            ServiceLocator.Instance.Remove(typeof(INotificationVisualizer));
            ServiceLocator.Instance.Remove(typeof(IMessageVisualizer));
            SynchronizationContext.SetSynchronizationContext(savedContext);
        }
예제 #2
0
        public void DoNot_CalculatePiTest()
        {
            MainViewModel target = new MainViewModel();

            MockNotificationVisualizer notifyVisualizer  = new MockNotificationVisualizer();
            MockMessageVisualizer      messageVisualizer = new MockMessageVisualizer {
                Response = UICommand.No
            };

            ServiceLocator.Instance.Add(typeof(INotificationVisualizer), notifyVisualizer);
            ServiceLocator.Instance.Add(typeof(IMessageVisualizer), messageVisualizer);

            target.PiText = string.Empty;
            target.CalculatePi.Execute(null);
            Assert.AreEqual(string.Empty, target.PiText);

            Assert.IsTrue(notifyVisualizer.LastBeginCall == null);
            Assert.IsTrue(notifyVisualizer.LastDisposeCall == null);

            ServiceLocator.Instance.Remove(typeof(INotificationVisualizer));
            ServiceLocator.Instance.Remove(typeof(IMessageVisualizer));
        }