コード例 #1
0
        internal void Preview(IScenarioWriter writer)
        {
            _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));
                }

                writer.BlankLine();

                writer.WriteLine("Assertions");

                using (writer.Indent())
                {
                    _steps.Each(x => x.PreviewAssert(writer));
                }
            }
        }
コード例 #2
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()));
                }
            }
        }
コード例 #3
0
        internal void Preview(IScenarioWriter writer)
        {
            _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));
                }

                writer.BlankLine();

                writer.WriteLine("Assertions");

                using (writer.Indent())
                {
                    _steps.Each(x => x.PreviewAssert(writer));
                }
            }
        }
コード例 #4
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()));
                }
            }
        }