internal void Describe(IScenarioWriter writer)
        {
            if (!_registry.IsValueCreated)
            {
                return;
            }

            writer.WriteLine(Name);
            var channels = _runtime.Factory.Get <ChannelGraph>();

            using (writer.Indent())
            {
                channels.Where(x => x.Incoming)
                .Each(x => writer.WriteLine("Listens to {0} with ", x.Uri, x.Scheduler));

                //writer.BlankLine();

                channels.Where(x => x.Rules.Any()).Each(x => {
                    writer.WriteLine("Publishes to {0}", x.Key);

                    using (writer.Indent())
                    {
                        x.Rules.Each(rule => writer.Bullet(rule.Describe()));
                    }
                });

                var handlers = _runtime.Factory.Get <HandlerGraph>();
                var inputs   = handlers.Select(x => x.InputType()).Where(x => x != typeof(object[]));
                if (inputs.Any())
                {
                    writer.WriteLine("Handles " + inputs.Select(x => x.Name).Join(", "));
                }

                _info.Each(x => writer.WriteLine(x));

                writer.BlankLine();
            }
        }
        internal void Execute(IScenarioWriter writer)
        {
            TraceListener[] listeners = new TraceListener[Debug.Listeners.Count];

            Debug.Listeners.CopyTo(listeners, 0);
            Debug.Listeners.Clear();

            FubuTransport.SetupForInMemoryTesting();

            InMemoryQueueManager.ClearAll();
            TestMessageRecorder.Clear();
            MessageHistory.ClearAll();

            _configurations.Each(x => x.SpinUp());

            writer.WriteTitle(Title);

            using (writer.Indent())
            {
                writeArrangement(writer);

                writer.WriteLine("Actions");

                using (writer.Indent())
                {
                    _steps.Each(x => {
                        x.PreviewAct(writer);
                        try
                        {
                            x.Act(writer);
                        }
                        catch (Exception e)
                        {
                            writer.Exception(e);
                        }
                    });

                }

                var success = Wait.Until(() => {
                    return !MessageHistory.Outstanding().Any();
                }, timeoutInMilliseconds:60000);

                Debug.Listeners.AddRange(listeners);

                if (success)
                {
                    writer.WriteLine("Messages are all accounted for");
                }
                else
                {
                    writer.WriteLine("Messages are outstanding:");
                    MessageHistory.Outstanding().Each(x => Debug.WriteLine(x));
                }

                writer.BlankLine();

                _configurations.Each(x => x.SafeDispose());

                writer.WriteLine("Assertions");

                using (writer.Indent())
                {
                    _steps.Each(x => {
                        x.PreviewAssert(writer);
                        x.Assert(writer);
                    });
                }

                writer.BlankLine();

                if (TestMessageRecorder.AllProcessed.Any())
                {
                    writer.WriteLine("Messages Received");
                    TestMessageRecorder.AllProcessed.Each(x => {
                        writer.Bullet("{0} received by {1}", x.Message.GetType().Name, x.Message.Source);
                    });
                }
                else
                {
                    writer.WriteLine("No messages were received!");
                }

                var unexpectedMessages = TestMessageRecorder.AllProcessed.Where(x => !_steps.Any(step => step.MatchesSentMessage(x.Message)))
                                   .ToArray();

                if (unexpectedMessages.Any())
                {
                    writer.BlankLine();
                    writer.WriteLine("Found unexpected messages");
                    unexpectedMessages.Each(x => writer.Failure(x.ToString()));
                }
            }
        }
Example #3
0
        internal void Execute(IScenarioWriter writer)
        {
            TraceListener[] listeners = new TraceListener[Debug.Listeners.Count];

            Debug.Listeners.CopyTo(listeners, 0);
            Debug.Listeners.Clear();

            FubuTransport.SetupForInMemoryTesting();

            InMemoryQueueManager.ClearAll();
            TestMessageRecorder.Clear();
            MessageHistory.ClearAll();

            _configurations.Each(x => x.SpinUp());

            writer.WriteTitle(Title);

            using (writer.Indent())
            {
                writeArrangement(writer);

                writer.WriteLine("Actions");

                using (writer.Indent())
                {
                    _steps.Each(x => {
                        x.PreviewAct(writer);
                        try
                        {
                            x.Act(writer);
                        }
                        catch (Exception e)
                        {
                            writer.Exception(e);
                        }
                    });
                }

                var success = Wait.Until(() => {
                    return(!MessageHistory.Outstanding().Any());
                }, timeoutInMilliseconds: 60000);

                Debug.Listeners.AddRange(listeners);

                if (success)
                {
                    writer.WriteLine("Messages are all accounted for");
                }
                else
                {
                    writer.WriteLine("Messages are outstanding:");
                    MessageHistory.Outstanding().Each(x => Debug.WriteLine(x));
                }

                writer.BlankLine();

                _configurations.Each(x => x.SafeDispose());

                writer.WriteLine("Assertions");

                using (writer.Indent())
                {
                    _steps.Each(x => {
                        x.PreviewAssert(writer);
                        x.Assert(writer);
                    });
                }


                writer.BlankLine();


                if (TestMessageRecorder.AllProcessed.Any())
                {
                    writer.WriteLine("Messages Received");
                    TestMessageRecorder.AllProcessed.Each(x => {
                        writer.Bullet("{0} received by {1}", x.Message.GetType().Name, x.Message.Source);
                    });
                }
                else
                {
                    writer.WriteLine("No messages were received!");
                }

                var unexpectedMessages = TestMessageRecorder.AllProcessed.Where(x => !_steps.Any(step => step.MatchesSentMessage(x.Message)))
                                         .ToArray();

                if (unexpectedMessages.Any())
                {
                    writer.BlankLine();
                    writer.WriteLine("Found unexpected messages");
                    unexpectedMessages.Each(x => writer.Failure(x.ToString()));
                }
            }
        }