public void RunTests_should_generate_correct_test_results()
        {
            var handler = TestActionDispatcher.Create((TestExecutionContext c) => { });
            var results = RunTests(
                TestData.Table(
                    TestData.Create("a", "b"),
                    TestData.Create("x", "y")
                    ), handler.Invoke
                );

            var baseName = GetType() + "." + nameof(RunTests_should_generate_correct_test_results);

            Assert.HasCount(2, results.Children);
            Assert.Equal(TestStatus.Passed, results.Children[0].Status);
            Assert.Equal(TestStatus.Passed, results.Children[1].Status);

            // Tests could have been shuffled, but ensure both are present
            string bothTests = string.Join(
                "\n",
                results.Children[0].DisplayName,
                results.Children[1].DisplayName
                );

            Assert.Contains($"{baseName} dynamic A #0 (a,b)", bothTests);
            Assert.Contains($"{baseName} dynamic A #1 (x,y)", bothTests);
        }
Ejemplo n.º 2
0
        public void RethrowExceptions_will_cause_exceptions_to_be_rethrown()
        {
            var dispatcher = new TestActionDispatcher(FExceptionThrowingMethod);

            dispatcher.RethrowExceptions();

            Expect(() => dispatcher.Invoke()).ToThrow.Message.EqualTo("this throws");
        }
Ejemplo n.º 3
0
        public void After_will_be_called_after()
        {
            bool afterCalled = false;
            var  dispatcher  = new TestActionDispatcher(() => {});

            dispatcher.After(() => { afterCalled = true; });

            dispatcher.Invoke();
            Assert.True(afterCalled);
        }
Ejemplo n.º 4
0
        public void Before_will_be_called_first()
        {
            bool beforeCalled = false;
            var  dispatcher   = new TestActionDispatcher(() => {});

            dispatcher.Before(() => { beforeCalled = true; });

            dispatcher.Invoke();
            Assert.True(beforeCalled);
        }
Ejemplo n.º 5
0
        public void Dispose_causes_handler_not_to_be_called()
        {
            var doc  = new DomDocument();
            var attr = doc.AppendElement("hello").AppendAttribute("a");

            var evts     = new TestActionDispatcher <DomAttributeEvent>(_ => {});
            var observer = doc.ObserveAttributes(doc.DocumentElement, evts.Invoke);

            observer.Dispose();

            attr.Value = "changed";
            Assert.Equal(0, evts.CallCount);
        }
Ejemplo n.º 6
0
        public void ObserveChildNodes_callback_should_be_noop(MutationData data)
        {
            var doc = new DomDocument().LoadXml(@"
                <root><a/><b/><c/></root>
            ");

            var element = doc.DocumentElement;
            var evts    = new TestActionDispatcher <DomMutationEvent>(_ => {});

            doc.ObserveChildNodes(element, evts.Invoke);
            data.Action(element);

            Assert.Equal(0, evts.CallCount);
        }
Ejemplo n.º 7
0
        public void ObserveAttributes_should_invoke_optimized_registration()
        {
            var doc = new DomDocument();

            doc.AppendElement("hello").AppendElement("world");

            var evts     = new TestActionDispatcher <DomAttributeEvent>(_ => {});
            var observer = doc.ObserveAttributes(doc.DocumentElement, "l", evts.Invoke, DomScope.TargetAndDescendants);

            doc.QuerySelectorAll("*").Attribute("l", "k");
            Assert.Equal(2, evts.CallCount);
            Assert.Equal("hello", evts.ArgsForCall(0).Target.LocalName);
            Assert.Equal("world", evts.ArgsForCall(1).Target.LocalName);
            Assert.Equal("l", evts.ArgsForCall(1).LocalName);
        }
        public void RunTests_should_process_test_data()
        {
            var handler = TestActionDispatcher.Create((TestExecutionContext c) => {});
            var results = RunTests(
                TestData.Table(
                    TestData.Create("a", "b"),
                    TestData.Create("x", "y")
                    ), handler.Invoke
                );

            Assert.Equal(2, handler.CallCount);

            // Tests could have been shuffled, but ensure both are present
            var allArgs = handler.Calls.Select(c => string.Join(" ", c.Args.TestData)).ToList();

            Assert.Contains("a b", allArgs);
            Assert.Contains("x y", allArgs);
        }
Ejemplo n.º 9
0
        public void ObserveAttributes_callback_should_be_invoked_on_removing_an_attribute(Action <DomElement> callback)
        {
            var doc = new DomDocument().LoadXml(@"
                <root attr='root value' />
            ".Replace("'", "\""));

            var element = doc.QuerySelector("root");

            var evts = new TestActionDispatcher <DomAttributeEvent>(_ => {});

            doc.ObserveAttributes(element, evts.Invoke);

            callback(element);

            Assert.Equal(1, evts.CallCount);
            Assert.Equal("root value", evts.ArgsForCall(0).OldValue);
            Assert.Null(evts.ArgsForCall(0).Value);
            Assert.Equal("attr", evts.ArgsForCall(0).LocalName);
        }
Ejemplo n.º 10
0
        public void GetName_will_notify_mutation_events_when_name_content_changes()
        {
            var ele = new DomDocument().CreateElement("s");

            ele.NameContext = DomNameContext.Xml;
            ele.Attribute("a", "a").Attribute("A", "A")
            .Attribute("b", "b").Attribute("B", "B")
            .Attribute("c", "c").Attribute("C", "C");

            var evts     = new TestActionDispatcher <DomAttributeEvent>(_ => {});
            var observer = ele.OwnerDocument.ObserveAttributes(ele, evts.Invoke);

            ele.NameContext = DomNameContext.Html;

            // Should have generated several events indicating that attributes were
            Assert.Equal(3, evts.CallCount);
            Assert.Equal("A", evts.ArgsForCall(0).LocalName);
            Assert.Equal("B", evts.ArgsForCall(1).LocalName);
            Assert.Equal("C", evts.ArgsForCall(2).LocalName);
        }
Ejemplo n.º 11
0
        public void ObserveChildNodes_callback_should_be_invoked_on_mutation_nodes(MutationData data)
        {
            var doc = new DomDocument().LoadXml(@"
                <root><a/><b/><c/></root>
            ");

            var element  = doc.DocumentElement;
            var evts     = new TestActionDispatcher <DomMutationEvent>(_ => {});
            var expected = data.Event(element);

            doc.ObserveChildNodes(element, evts.Invoke);

            data.Action(element);
            var actuallyAddedNodes = data.Event(element).AddedNodes;

            Assert.Equal(1, evts.CallCount);
            Assert.Equal(actuallyAddedNodes.NodeNames(), evts.ArgsForCall(0).AddedNodes.NodeNames());
            Assert.Equal(expected.RemovedNodes.NodeNames(), evts.ArgsForCall(0).RemovedNodes.NodeNames());
            Assert.Same(expected.NextSiblingNode, evts.ArgsForCall(0).NextSiblingNode);
            Assert.Same(expected.PreviousSiblingNode, evts.ArgsForCall(0).PreviousSiblingNode);
        }
Ejemplo n.º 12
0
        public void Invoke_will_swallow_exceptions_by_default()
        {
            var dispatcher = new TestActionDispatcher(FExceptionThrowingMethod);

            Assert.DoesNotThrow(() => dispatcher.Invoke());
        }