Exemplo n.º 1
0
        private void SubscribeToLaunchState(Lifetime launchLifetime,
                                            IUnitTestSession session,
                                            IUnitTestLaunch unitTestLaunch)
        {
            var aborted = false;

            unitTestLaunch.Status.Change.Advise(
                launchLifetime,
                args =>
            {
                if (args.HasNew)
                {
                    switch (args.New)
                    {
                    case UnitTestLaunchStatus.Building:
                    case UnitTestLaunchStatus.Starting:
                    case UnitTestLaunchStatus.Running:
                        aborted = false;
                        break;

                    case UnitTestLaunchStatus.Stopping:
                        // This will happen if the build failed.
                        if (session.Launch.Value == null)
                        {
                            break;
                        }
                        // These need to be declared here because session.Launch.Value is null by
                        // the time the Dispatcher executes the action.
                        var relevantTestElements = session.Launch.Value.Elements.Where(e => !e.Children.Any());
                        var launchTime           = session.Launch.Value.StartedOn;
                        _threading.Dispatcher.BeginOrInvoke(
                            "KaVE::TestStopping",
                            () =>
                        {
                            ReadLockCookie.GuardedExecute(
                                () =>
                            {
                                var results = _resultManager.GetResults(relevantTestElements, session);

                                CreateAndFireTestRunEvent(launchTime, aborted, results);
                            });
                        });
                        break;

                    case UnitTestLaunchStatus.Aborting:
                        aborted = true;
                        break;
                    }
                }
            });
        }
        private void SubscribeToLaunchState(Lifetime launchLifetime, IUnitTestSession session,
                                            IProperty <UnitTestSessionState> state)
        {
            var aborted = false;

            state.Change.Advise(launchLifetime, stateArgs =>
            {
                if (stateArgs.HasNew)
                {
                    switch (stateArgs.New)
                    {
                    case UnitTestSessionState.Idle:
                    case UnitTestSessionState.Running:
                        break;

                    case UnitTestSessionState.Building:
                        aborted = false;
                        threading.Dispatcher.BeginOrInvoke("Clippy::TestBuilding", () => agent.Play("Processing"));
                        break;

                    case UnitTestSessionState.Starting:
                        if (!aborted)
                        {
                            threading.Dispatcher.BeginOrInvoke("Clippy::TestStarting", () => agent.Play("GetTechy"));
                        }
                        break;

                    case UnitTestSessionState.Stopping:
                        if (!aborted)
                        {
                            threading.Dispatcher.BeginOrInvoke("Clippy::TestStopping", () =>
                            {
                                string message = null;
                                var animation  = "Congratulate";
                                ReadLockCookie.GuardedExecute(() =>
                                {
                                    var results = resultsManager.GetResults(session.Elements, session);
                                    bool success;
                                    message = GetStatusMessage(results, out success);
                                    if (!success)
                                    {
                                        animation = "Wave";
                                    }
                                });

                                var balloonLifetimeDefinition = Lifetimes.Define(launchLifetime);

                                agent.ShowBalloon(balloonLifetimeDefinition.Lifetime, "Test run complete",
                                                  message, null, new[] { "Done" }, false,
                                                  balloonLifetime =>
                                {
                                    threading.TimedActions.Queue(balloonLifetimeDefinition.Lifetime,
                                                                 "Clippy::Balloon", balloonLifetimeDefinition.Terminate,
                                                                 TimeSpan.FromSeconds(5), TimedActionsHost.Recurrence.OneTime,
                                                                 Rgc.Guarded);
                                    agent.ButtonClicked.Advise(balloonLifetime, balloonLifetimeDefinition.Terminate);
                                });
                                agent.Play(animation);
                            });
                        }
                        break;

                    case UnitTestSessionState.Aborting:
                        aborted = true;
                        threading.Dispatcher.BeginOrInvoke("Clippy::TestAborting", () => agent.Play("Wave"));
                        break;
                    }
                }
            });
        }