Пример #1
0
        /// <summary>
        /// Creates a message sink that populates the test model as test and annotation
        /// discovered messages are published.
        /// </summary>
        /// <param name="testModel">The test model to populate.</param>
        /// <returns>The message sink.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testModel"/> is null.</exception>
        public static IMessageSink CreateMessageSinkToPopulateTestModel(TestModel testModel)
        {
            if (testModel == null)
                throw new ArgumentNullException("testModel");

            return new MessageConsumer()
                .Handle<TestDiscoveredMessage>(message =>
                {
                    Test test = message.Test.ToTest();

                    if (message.ParentTestId != null)
                    {
                        Test parentTest = testModel.FindTest(message.ParentTestId);
                        if (parentTest == null)
                            throw new InvalidOperationException("The parent test is missing.");

                        parentTest.AddChild(test);
                    }
                    else
                    {
                        testModel.RootTest = test;
                    }
                })
                .Handle<AnnotationDiscoveredMessage>(message =>
                {
                    testModel.AddAnnotation(message.Annotation.ToAnnotation());
                });
        }