/// <summary>
 /// Needs to be called everythime the control is hidden
 /// </summary>
 private void Finish()
 {
     if (Runner != null)
     {
         Runner.Dispose();
         Runner = null;
     }
 }
 /// <summary>
 /// Needs to be called everytime the control is made visible
 /// </summary>
 private void Setup(IServiceProvider serviceProvider, ExpressionViewerControl view)
 {
     var sourceMonitor = new SourceMonitor(serviceProvider);
     var viewController = new ExpressionViewController(view);
     var viewGenerator = new ViewGenerator();
     Runner = new Runner(sourceMonitor, viewController, viewGenerator);
 }
        public void Runner_Object_IsDisposable()
        {
            var sourceMonitor = new Mock<ISourceMonitor>();
            var viewController = new Mock<IViewController>();
            var viewGenerator = new Mock<IViewGenerator>(MockBehavior.Loose);
            var runner = new Runner(sourceMonitor.Object, viewController.Object, viewGenerator.Object);

            Assert.IsTrue(runner is IDisposable);
        }
        public void Runner_SourceChanged_DrawView()
        {
            var sourceMonitor = new Mock<ISourceMonitor>(MockBehavior.Loose);
            var viewController = new Mock<IViewController>(MockBehavior.Loose);
            var solution = "solution.sln";
            var activeDocument = String.Empty;
            var cursorPosition = 0;
            var content = "content";
            var viewGenerator = new Mock<IViewGenerator>(MockBehavior.Loose);
            viewGenerator
                .Setup(generator => generator.GenerateViewAsync(solution, activeDocument, cursorPosition))
                .Returns(Task.FromResult(content));
            var runner = new Runner(sourceMonitor.Object, viewController.Object, viewGenerator.Object);

            sourceMonitor.Raise(mock => mock.SourceChanged += null, new SourceMonitorArgs(solution, activeDocument, cursorPosition));

            viewController.Verify(mock => mock.Draw(content), Times.Once());
        }
        public void Runner_CallingDisposeTwice_DoesntFail()
        {
            var sourceMonitor = new Mock<ISourceMonitor>();
            var viewController = new Mock<IViewController>();
            var viewGenerator = new Mock<IViewGenerator>(MockBehavior.Loose);
            var runner = new Runner(sourceMonitor.Object, viewController.Object, viewGenerator.Object);

            runner.Dispose();
            runner.Dispose();
        }