Exemplo n.º 1
0
        public void prune_expired_listeners_based_on_the_expired_property()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            var listener5 = new ExpiringListener {IsExpired = true};
            var listener6 = new ExpiringListener {IsExpired = true};
            var listener7 = new ExpiringListener {IsExpired = false};

            events.AddListeners(listener1, listener2, listener3, listener4, listener5, listener6, listener7);

            events.PruneExpiredListeners(DateTime.Now);

            // non-expiring listeners should be untouched
            events.Listeners.ShouldContain(listener1);
            events.Listeners.ShouldContain(listener2);
            events.Listeners.ShouldContain(listener3);
            events.Listeners.ShouldContain(listener4);

            // expired expiring listeners should be removed
            events.Listeners.ShouldNotContain(listener5);
            events.Listeners.ShouldNotContain(listener6);

            // not-expired expiring listener should not be removed
            events.Listeners.ShouldContain(listener7);
        }
Exemplo n.º 2
0
        public void send_message_to_all_listeners_for_a_message_type()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            var message1 = new Message1();
            var message2 = new Message2();

            events.SendMessage(message1);
            events.SendMessage(message2);

            Wait.Until(
                () =>
                    listener1.LastMessage != null && listener2.LastMessage != null && listener3.LastMessage != null &&
                    listener4.LastMessage != null);

            listener1.LastMessage.ShouldBeTheSameAs(message1);
            listener2.LastMessage.ShouldBeTheSameAs(message1);
            listener3.LastMessage.ShouldBeTheSameAs(message1);

            listener4.LastMessage.ShouldBeTheSameAs(message2);
        }
 public void SetUp()
 {
     theLogger   = new NulloLogger();
     theListener = new StubListener();
     theSession  = new StubSession();
     theManager  = new ClarifySessionManager(new[] { theListener, theListener }, theLogger);
 }
Exemplo n.º 4
0
        public void ShouldFailWithClearExplanationWhenParameterCountsAreMismatched()
        {
            var listener = new StubListener();

            var convention = new SelfTestConvention();

            convention.Parameters(Inputs(
                                      new object[] { },
                                      new object[] { 0 },
                                      new object[] { 0, 1 },
                                      new object[] { 0, 1, 2 },
                                      new object[] { 0, 1, 2, 3 }));

            convention.Execute(listener, typeof(ParameterizedTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg(0) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg(0, 1) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg(0, 1, 2) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg(0, 1, 2, 3) failed: Parameter count mismatch.",

                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(0) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(0, 1) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(0, 1, 2) failed: Expected sum of 2 but was 1.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(0, 1, 2, 3) failed: Parameter count mismatch.",

                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs(0) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs(0, 1) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs(0, 1, 2) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs(0, 1, 2, 3) failed: Parameter count mismatch.");
        }
Exemplo n.º 5
0
        public void listeners_can_fail_one_at_a_time()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);
            events.AddListener(new ErrorCausingHandler());

            var message1 = new Message1();
            var message2 = new Message2();

            events.SendMessage(message1);
            events.SendMessage(message2);

            Wait.Until(
                () =>
                    listener1.LastMessage != null && listener2.LastMessage != null && listener3.LastMessage != null &&
                    listener4.LastMessage != null);

            listener1.LastMessage.ShouldBeTheSameAs(message1);
            listener2.LastMessage.ShouldBeTheSameAs(message1);
            listener3.LastMessage.ShouldBeTheSameAs(message1);

            listener4.LastMessage.ShouldBeTheSameAs(message2);
        }
Exemplo n.º 6
0
        public void ShouldResolveGenericTypeParameters()
        {
            var listener = new StubListener();

            var convention = new SelfTestConvention();

            convention.Parameters(ParametersFromAttributes);

            convention.Execute(listener, typeof(GenericTestClass));
            listener.Entries.ShouldEqual(
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.GenericMethodWithIncorrectParameterCountProvided<System.Object>(123, 123) failed: Parameter count mismatch.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.GenericMethodWithNoInputsProvided<System.Object> failed: This parameterized test could not be executed, because no input values were available.",

                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.MultipleGenericArgumentsMultipleParameters<System.Int32, System.Object>(123, null, 456, System.Int32, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.MultipleGenericArgumentsMultipleParameters<System.Int32, System.String>(123, \"stringArg1\", 456, System.Int32, System.String) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.MultipleGenericArgumentsMultipleParameters<System.String, System.Object>(\"stringArg\", null, null, System.String, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.MultipleGenericArgumentsMultipleParameters<System.String, System.Object>(\"stringArg1\", null, \"stringArg2\", System.String, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.MultipleGenericArgumentsMultipleParameters<System.String, System.String>(null, \"stringArg1\", \"stringArg2\", System.String, System.String) passed.",

                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgument<System.Int32>(123, System.Int32) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgument<System.Object>(null, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgument<System.String>(\"stringArg\", System.String) passed.",

                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.Int32>(123, 456, System.Int32) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.Object>(\"stringArg\", 123, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.Object>(123, \"stringArg\", System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.Object>(123, null, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.Object>(null, null, System.Object) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.String>(\"stringArg\", null, System.String) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.String>(\"stringArg1\", \"stringArg2\", System.String) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+GenericTestClass.SingleGenericArgumentMultipleParameters<System.String>(null, \"stringArg\", System.String) passed.");
        }
Exemplo n.º 7
0
        public void listeners_can_fail_one_at_a_time()
        {
            var listener1 = new StubListener <Message1>();
            var listener2 = new StubListener <Message1>();
            var listener3 = new StubListener <Message1>();
            var listener4 = new StubListener <Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);
            events.AddListener(new ErrorCausingHandler());

            var message1 = new Message1();
            var message2 = new Message2();

            events.SendMessage(message1);
            events.SendMessage(message2);

            Wait.Until(
                () =>
                listener1.LastMessage != null && listener2.LastMessage != null && listener3.LastMessage != null &&
                listener4.LastMessage != null);

            listener1.LastMessage.ShouldBeTheSameAs(message1);
            listener2.LastMessage.ShouldBeTheSameAs(message1);
            listener3.LastMessage.ShouldBeTheSameAs(message1);

            listener4.LastMessage.ShouldBeTheSameAs(message2);
        }
Exemplo n.º 8
0
        public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
        {
            var listener = new StubListener();

            var candidateTypes = new[]
            {
                typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                typeof(PassFailTestClass), typeof(SkipTestClass)
            };
            var discovery = new SelfTestDiscovery();
            var execution = new CreateInstancePerClass();

            discovery.Methods
            .Shuffle(new Random(1));

            var bus = new Bus(listener);

            new Runner(GetType().Assembly, bus).Run(candidateTypes, discovery, execution);

            listener.Entries.ShouldBe(
                Self + "+PassTestClass.PassB passed",
                Self + "+PassTestClass.PassA passed",
                Self + "+PassFailTestClass.Fail failed: 'Fail' failed!",
                Self + "+PassFailTestClass.Pass passed",
                Self + "+SkipTestClass.SkipB skipped",
                Self + "+SkipTestClass.SkipA skipped");
        }
Exemplo n.º 9
0
        public void send_message_to_all_listeners_for_a_message_type()
        {
            var listener1 = new StubListener <Message1>();
            var listener2 = new StubListener <Message1>();
            var listener3 = new StubListener <Message1>();
            var listener4 = new StubListener <Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            var message1 = new Message1();
            var message2 = new Message2();

            events.SendMessage(message1);
            events.SendMessage(message2);

            Wait.Until(
                () =>
                listener1.LastMessage != null && listener2.LastMessage != null && listener3.LastMessage != null &&
                listener4.LastMessage != null);

            listener1.LastMessage.ShouldBeTheSameAs(message1);
            listener2.LastMessage.ShouldBeTheSameAs(message1);
            listener3.LastMessage.ShouldBeTheSameAs(message1);

            listener4.LastMessage.ShouldBeTheSameAs(message2);
        }
 public void SetUp()
 {
     theLogger = new NulloLogger();
     theListener = new StubListener();
     theSession = new StubSession();
     theManager = new ClarifySessionManager(new[] {theListener, theListener}, theLogger);
 }
Exemplo n.º 11
0
        public void prune_expired_listeners_based_on_the_expired_property()
        {
            var listener1 = new StubListener <Message1>();
            var listener2 = new StubListener <Message1>();
            var listener3 = new StubListener <Message1>();
            var listener4 = new StubListener <Message2>();

            var listener5 = new ExpiringListener {
                IsExpired = true
            };
            var listener6 = new ExpiringListener {
                IsExpired = true
            };
            var listener7 = new ExpiringListener {
                IsExpired = false
            };

            events.AddListeners(listener1, listener2, listener3, listener4, listener5, listener6, listener7);

            events.PruneExpiredListeners(DateTime.Now);

            // non-expiring listeners should be untouched
            events.Listeners.ShouldContain(listener1);
            events.Listeners.ShouldContain(listener2);
            events.Listeners.ShouldContain(listener3);
            events.Listeners.ShouldContain(listener4);

            // expired expiring listeners should be removed
            events.Listeners.ShouldNotContain(listener5);
            events.Listeners.ShouldNotContain(listener6);

            // not-expired expiring listener should not be removed
            events.Listeners.ShouldContain(listener7);
        }
Exemplo n.º 12
0
        public void SetUp()
        {
            _listener = new StubListener();
            Log.Src.Listeners.Add(_listener);

            _origLevel           = Log.Src.Switch.Level;
            Log.Src.Switch.Level = SourceLevels.Off;
        }
Exemplo n.º 13
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsBeforeAwaitingOnAnyTask()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(FailBeforeAwaitTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.AsyncMethodTests+FailBeforeAwaitTestClass.Test failed: 'Test' failed!");
        }
Exemplo n.º 14
0
        public void ShouldFailWithOriginalExceptionWhenCaseMethodThrows()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(FailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+FailTestClass.Fail failed: 'Fail' failed!");
        }
Exemplo n.º 15
0
        public void ShouldPassUponSuccessfulAsyncExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitThenPassTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.AsyncMethodTests+AwaitThenPassTestClass.Test passed.");
        }
Exemplo n.º 16
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsWithinTheAwaitedTask()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitOnTaskThatThrowsTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.AsyncMethodTests+AwaitOnTaskThatThrowsTestClass.Test failed: Attempted to divide by zero.");
        }
Exemplo n.º 17
0
        public void ShouldPassUponSuccessfulExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(PassTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassTestClass.Pass passed.");
        }
Exemplo n.º 18
0
        public void ShouldPassUponSuccessfulExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(PassTestClass));

            listener.ShouldHaveEntries(
                "Fixie.Tests.TestClasses.CaseTests+PassTestClass.Pass passed.");
        }
Exemplo n.º 19
0
        public void ShouldFailWithOriginalExceptionWhenCaseMethodThrows()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(FailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+FailTestClass.Fail failed: 'Fail' failed!");
        }
Exemplo n.º 20
0
        public void ShouldPassUponSuccessfulExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener , typeof(PassTestClass));

            listener.ShouldHaveEntries(
                "Fixie.Tests.TestClasses.CaseTests+PassTestClass.Pass passed.");
        }
Exemplo n.º 21
0
        public void ShouldPassUponSuccessfulAsyncExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitThenPassTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestClasses.AsyncCaseTests+AwaitThenPassTestClass.Test passed.");
        }
Exemplo n.º 22
0
        public void ShouldPassUponSuccessfulExecution()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener , typeof(PassTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassTestClass.Pass passed.");
        }
Exemplo n.º 23
0
        public void ShouldFailWhenTestClassConstructorCannotBeInvoked()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(CannotInvokeConstructorTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+CannotInvokeConstructorTestClass.UnreachableCase failed: No parameterless constructor defined for this object.");
        }
Exemplo n.º 24
0
        public void ShouldFailWhenTestClassConstructorCannotBeInvoked()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(CannotInvokeConstructorTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+CannotInvokeConstructorTestClass.UnreachableCase failed: No parameterless constructor defined for this object.");
        }
Exemplo n.º 25
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsWithinTheAwaitedTask()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitOnTaskThatThrowsTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestClasses.AsyncCaseTests+AwaitOnTaskThatThrowsTestClass.Test failed: Attempted to divide by zero.");
        }
Exemplo n.º 26
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsBeforeAwaitingOnAnyTask()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(FailBeforeAwaitTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestClasses.AsyncCaseTests+FailBeforeAwaitTestClass.Test failed: 'Test' failed!");
        }
Exemplo n.º 27
0
        public void ShouldFailUnsupportedAsyncVoidCases()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(UnsupportedAsyncVoidTestTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestClasses.AsyncCaseTests+UnsupportedAsyncVoidTestTestClass.Test failed: " +
                "Async void methods are not supported. Declare async methods with a return type of " +
                "Task to ensure the task actually runs to completion.");
        }
Exemplo n.º 28
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsAfterAwaiting()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitThenFailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestClasses.AsyncCaseTests+AwaitThenFailTestClass.Test failed: Assert.Equal() Failure" + Environment.NewLine +
                "Expected: 0" + Environment.NewLine +
                "Actual:   3");
        }
Exemplo n.º 29
0
        public void ShouldFailUnsupportedAsyncVoidCases()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(UnsupportedAsyncVoidTestTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.AsyncMethodTests+UnsupportedAsyncVoidTestTestClass.Test failed: " +
                "Async void methods are not supported. Declare async methods with a return type of " +
                "Task to ensure the task actually runs to completion.");
        }
Exemplo n.º 30
0
        public void ShouldFailWithOriginalExceptionWhenAsyncCaseMethodThrowsAfterAwaiting()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(AwaitThenFailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.AsyncMethodTests+AwaitThenFailTestClass.Test failed: Assert.Equal() Failure" + Environment.NewLine +
                "Expected: 0" + Environment.NewLine +
                "Actual:   3");
        }
Exemplo n.º 31
0
        public void exposes_all_the_listeners()
        {
            var listener1 = new StubListener <Message1>();
            var listener2 = new StubListener <Message1>();
            var listener3 = new StubListener <Message1>();
            var listener4 = new StubListener <Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            events.Listeners.ShouldHaveTheSameElementsAs(handler, listener1, listener2, listener3, this, listener4);
        }
Exemplo n.º 32
0
        public void exposes_all_the_listeners()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            events.Listeners.ShouldHaveTheSameElementsAs(handler, listener1, listener2, listener3, this, listener4);
        }
Exemplo n.º 33
0
        protected Output Run()
        {
            using (var console = new RedirectedConsole())
            {
                var listener = new StubListener();

                Convention.Execute(listener, typeof(SampleTestClass));

                return(new Output(console.Lines.ToArray(), listener.Entries.ToArray()));
            }
        }
Exemplo n.º 34
0
        public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
        {
            var listener   = new StubListener();
            var convention = new SelfTestConvention();

            convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass));

            listener.ShouldHaveEntries("Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.",
                                       "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                                       "Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassA passed.",
                                       "Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassB passed.");
        }
Exemplo n.º 35
0
        public void send_message_that_creates_on_the_fly()
        {
            var listener1 = new StubListener <Message1>();

            events.AddListener(listener1);

            events.SendMessage <Message1>();

            Wait.Until(() => listener1.LastMessage != null);


            listener1.LastMessage.ShouldBeOfType <Message1>();
        }
Exemplo n.º 36
0
        protected Output Run()
        {
            using (var console = new RedirectedConsole())
            {
                var listener = new StubListener();

                Convention.ClassExecution.SortCases((x, y) => String.Compare(y.Name, x.Name, StringComparison.Ordinal));

                Convention.Execute(listener, typeof(SampleTestClass));

                return(new Output(console.Lines().ToArray(), listener.Entries.ToArray()));
            }
        }
Exemplo n.º 37
0
        public void ShouldPassOrFailCasesIndividually()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(PassFailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.FailA failed: 'FailA' failed!",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.FailB failed: 'FailB' failed!",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassA passed.",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassB passed.",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassC passed.");
        }
Exemplo n.º 38
0
        public void ShouldPassOrFailCasesIndividually()
        {
            var listener = new StubListener();

            new SelfTestConvention().Execute(listener, typeof(PassFailTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.FailA failed: 'FailA' failed!",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.FailB failed: 'FailB' failed!",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassA passed.",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassB passed.",
                "Fixie.Tests.TestMethods.NullaryMethodTests+PassFailTestClass.PassC passed.");
        }
Exemplo n.º 39
0
        public void ShouldFailWithClearExplanationWhenInputParameterGenerationHasNotBeenCustomizedYetTestMethodAcceptsParameters()
        {
            var listener = new StubListener();

            var convention = new SelfTestConvention();

            convention.Execute(listener, typeof(ParameterizedTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg failed: This parameterized test could not be executed, because no input values were available.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes failed: This parameterized test could not be executed, because no input values were available.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs passed.");
        }
Exemplo n.º 40
0
        protected Output Run()
        {
            using (var console = new RedirectedConsole())
            {
                var listener = new StubListener();

                Convention.ClassExecution.SortCases((x, y) => String.Compare(y.Name, x.Name, StringComparison.Ordinal));

                typeof(SampleTestClass).Run(listener, Convention);

                return new Output(console.Lines().ToArray(), listener.Entries.ToArray());
            }
        }
Exemplo n.º 41
0
        public void ShouldShortCircuitTestExecutionByFailingAllCasesWhenCaseOrderingThrows()
        {
            var listener   = new StubListener();
            var convention = SelfTestConvention.Build();

            convention.CaseExecution.Skip(x => x.Method.Has <SkipAttribute>());

            convention.ClassExecution
            .CreateInstancePerClass()
            .SortCases((caseA, caseB) => { throw new Exception("SortCases lambda expression threw!"); });

            convention.Parameters
            .Add <BuggyParameterSource>();

            new Runner(listener).RunTypes(GetType().Assembly, convention,
                                          typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                                          typeof(PassFailTestClass), typeof(SkipTestClass), typeof(BuggyParameterGenerationTestClass));

            //NOTE: Since the ordering of cases is deliberately failing, and since member order via reflection
            //      is undefined, we explicitly sort the listener Entries here to avoid making a brittle assertion.

            var strings = listener.Entries.OrderBy(x => x).ToArray();

            strings.ShouldEqual(

                "Fixie.Tests.Internal.RunnerTests+BuggyParameterGenerationTestClass.ParameterizedA failed: Exception thrown while attempting to yield input parameters for method: ParameterizedA" + Environment.NewLine +
                "    Secondary Failure: Failed to compare two elements in the array." + Environment.NewLine +
                "        Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+BuggyParameterGenerationTestClass.ParameterizedB failed: Exception thrown while attempting to yield input parameters for method: ParameterizedB" + Environment.NewLine +
                "    Secondary Failure: Failed to compare two elements in the array." + Environment.NewLine +
                "        Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Fail failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Pass failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassA failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassB failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipA failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipB failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!");
        }
Exemplo n.º 42
0
        public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
        {
            var listener = new StubListener();
            var convention = new SelfTestConvention();

            var conventionRunner = new ConventionRunner();
            conventionRunner.Run(convention, listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual("Fixie.Tests.Conventions.ConventionRunnerTests+PassTestClass.PassA passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassTestClass.PassB passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassFailTestClass.Pass passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+SkipTestClass.Skip skipped.");
        }
Exemplo n.º 43
0
        public void exposes_all_the_listeners()
        {
            var listener1 = new StubListener <Message1>();
            var listener2 = new StubListener <Message1>();
            var listener3 = new StubListener <Message1>();
            var listener4 = new StubListener <Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            var listeners    = events.Listeners.ToArray();
            var intersection = listeners.Intersect(new object[] { handler, this, listener1, listener2, listener3, listener4 }).ToArray();

            listeners.Length.ShouldBe(intersection.Length);
        }
Exemplo n.º 44
0
        public void ShouldShortCircuitTestExecutionByFailingAllCasesWhenCaseOrderingThrows()
        {
            var listener = new StubListener();
            var convention = SelfTestConvention.Build();
            convention.CaseExecution.Skip(x => x.Method.Has<SkipAttribute>());

            convention.ClassExecution
                .CreateInstancePerClass()
                .SortCases((caseA, caseB) => { throw new Exception("SortCases lambda expression threw!"); });

            convention.Parameters
                .Add<BuggyParameterSource>();

            new Runner(listener).RunTypes(GetType().Assembly, convention,
                typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                typeof(PassFailTestClass), typeof(SkipTestClass), typeof(BuggyParameterGenerationTestClass));

            //NOTE: Since the ordering of cases is deliberately failing, and since member order via reflection
            //      is undefined, we explicitly sort the listener Entries here to avoid making a brittle assertion.

            var strings = listener.Entries.OrderBy(x => x).ToArray();
            strings.ShouldEqual(

                "Fixie.Tests.Internal.RunnerTests+BuggyParameterGenerationTestClass.ParameterizedA failed: Exception thrown while attempting to yield input parameters for method: ParameterizedA" + Environment.NewLine +
                "    Secondary Failure: Failed to compare two elements in the array." + Environment.NewLine +
                "        Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+BuggyParameterGenerationTestClass.ParameterizedB failed: Exception thrown while attempting to yield input parameters for method: ParameterizedB" + Environment.NewLine +
                "    Secondary Failure: Failed to compare two elements in the array." + Environment.NewLine +
                "        Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Fail failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Pass failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassA failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassB failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipA failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!",

                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipB failed: Failed to compare two elements in the array." + Environment.NewLine +
                "    Inner Exception: SortCases lambda expression threw!");
        }
Exemplo n.º 45
0
        public void ShouldProduceValidXmlDocument()
        {
            var listener = new StubListener();
            var runner = new Runner(listener);

            var executionResult = new ExecutionResult();
            var convention = new SelfTestConvention();
            convention.CaseExecution.Skip(x => x.Method.Has<SkipAttribute>(), x => x.Method.GetCustomAttribute<SkipAttribute>().Reason);
            var assemblyResult = runner.RunType(GetType().Assembly, convention, typeof(PassFailTestClass));
            executionResult.Add(assemblyResult);

            var report = new NUnitXmlReport();
            var actual = report.Transform(executionResult);

            XsdValidate(actual);
            CleanBrittleValues(actual.ToString(SaveOptions.DisableFormatting)).ShouldEqual(ExpectedReport);
        }
Exemplo n.º 46
0
        public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
        {
            var listener = new StubListener();
            var convention = SelfTestConvention.Build();

            new Runner(listener).RunTypes(GetType().Assembly, convention,
                typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassA passed.",
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassB passed.",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Pass passed.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipA skipped.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipB skipped.");
        }
Exemplo n.º 47
0
        public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
        {
            var listener   = new StubListener();
            var convention = new SelfTestConvention();

            convention.ClassExecution
            .CreateInstancePerTestClass()
            .ShuffleCases(new Random(1));

            convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual("Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassB passed.",
                                         "Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassA passed.",
                                         "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                                         "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.",
                                         "Fixie.Tests.Conventions.ConventionTests+SkipTestClass.Skip skipped.");
        }
Exemplo n.º 48
0
        public void ShouldAllowConventionToGeneratePotentiallyManySetsOfInputParametersPerMethod()
        {
            var listener = new StubListener();

            var convention = new SelfTestConvention();

            convention.Parameters(ParametersFromAttributesWithTypeDefaultFallback);

            convention.Execute(listener, typeof(ParameterizedTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.IntArg(0) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(1, 1, 2) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(1, 2, 3) passed.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.MultipleCasesFromAttributes(5, 5, 11) failed: Expected sum of 11 but was 10.",
                "Fixie.Tests.Cases.ParameterizedCaseTests+ParameterizedTestClass.ZeroArgs passed.");
        }
Exemplo n.º 49
0
        public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
        {
            var listener   = new StubListener();
            var convention = SelfTestConvention.Build();

            new Runner(listener).RunTypes(GetType().Assembly, convention,
                                          typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                                          typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassA passed.",
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassB passed.",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Pass passed.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipA skipped.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipB skipped.");
        }
Exemplo n.º 50
0
        public void ShouldReportFailuresForAllAffectedCasesWithoutShortCircuitingTestExecutionWhenCaseOrderingThrows()
        {
            var listener = new StubListener();

            var candidateTypes = new[]
            {
                typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                typeof(PassFailTestClass), typeof(SkipTestClass), typeof(BuggyParameterGenerationTestClass)
            };
            var discovery = new SelfTestDiscovery();
            var execution = new CreateInstancePerClass();

            discovery.Methods
            .OrderBy((Func <MethodInfo, string>)(x => throw new Exception("OrderBy lambda expression threw!")));

            discovery.Parameters
            .Add <BuggyParameterSource>();

            var bus = new Bus(listener);

            new Runner(GetType().Assembly, bus).Run(candidateTypes, discovery, execution);

            //NOTE: Since the ordering of cases is deliberately failing, and since member order via reflection
            //      is undefined, we explicitly sort the listener Entries here to avoid making a brittle assertion.

            var strings = listener.Entries.OrderBy(x => x).ToArray();

            strings.ShouldBe(
                Self + "+BuggyParameterGenerationTestClass.ParameterizedA failed: Exception thrown while attempting to yield input parameters for method: ParameterizedA",
                Self + "+BuggyParameterGenerationTestClass.ParameterizedA failed: OrderBy lambda expression threw!",
                Self + "+BuggyParameterGenerationTestClass.ParameterizedB failed: Exception thrown while attempting to yield input parameters for method: ParameterizedB",
                Self + "+BuggyParameterGenerationTestClass.ParameterizedB failed: OrderBy lambda expression threw!",
                Self + "+PassFailTestClass.Fail failed: 'Fail' failed!",
                Self + "+PassFailTestClass.Fail failed: OrderBy lambda expression threw!",
                Self + "+PassFailTestClass.Pass failed: OrderBy lambda expression threw!",
                Self + "+PassFailTestClass.Pass passed",
                Self + "+PassTestClass.PassA failed: OrderBy lambda expression threw!",
                Self + "+PassTestClass.PassA passed",
                Self + "+PassTestClass.PassB failed: OrderBy lambda expression threw!",
                Self + "+PassTestClass.PassB passed",
                Self + "+SkipTestClass.SkipA failed: OrderBy lambda expression threw!",
                Self + "+SkipTestClass.SkipA skipped",
                Self + "+SkipTestClass.SkipB failed: OrderBy lambda expression threw!",
                Self + "+SkipTestClass.SkipB skipped");
        }
Exemplo n.º 51
0
        public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
        {
            var listener = new StubListener();
            var convention = new SelfTestConvention();

            convention.ClassExecution
                .CreateInstancePerTestClass()
                .ShuffleCases(new Random(1));

            var conventionRunner = new ConventionRunner();
            conventionRunner.Run(convention, listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual("Fixie.Tests.Conventions.ConventionRunnerTests+PassTestClass.PassB passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassTestClass.PassA passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                "Fixie.Tests.Conventions.ConventionRunnerTests+PassFailTestClass.Pass passed.",
                "Fixie.Tests.Conventions.ConventionRunnerTests+SkipTestClass.Skip skipped.");
        }
Exemplo n.º 52
0
        public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
        {
            var listener = new StubListener();
            var convention = SelfTestConvention.Build();

            convention.ClassExecution
                .CreateInstancePerClass()
                .ShuffleCases(new Random(1));

            new Runner(listener).RunTypes(GetType().Assembly, convention,
                typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int),
                typeof(PassFailTestClass), typeof(SkipTestClass));

            listener.Entries.ShouldEqual(
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassB passed.",
                "Fixie.Tests.Internal.RunnerTests+PassTestClass.PassA passed.",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                "Fixie.Tests.Internal.RunnerTests+PassFailTestClass.Pass passed.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipB skipped.",
                "Fixie.Tests.Internal.RunnerTests+SkipTestClass.SkipA skipped.");
        }
Exemplo n.º 53
0
        public void prune_expired_listeners_based_on_time()
        {
            var now = DateTime.Today.AddHours(5);

            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            var listener5 = new ExpiringListener {ExpiresAt = now.AddMinutes(-1)};
            var listener6 = new ExpiringListener {ExpiresAt = now.AddMinutes(-1)};
            var listener7 = new ExpiringListener {ExpiresAt = now.AddMinutes(1)};

            events.AddListeners(listener1, listener2, listener3, listener4, listener5, listener6, listener7);

            events.PruneExpiredListeners(now);

            // non-expiring listeners should be untouched
            events.Listeners.ShouldContain(listener1);
            events.Listeners.ShouldContain(listener2);
            events.Listeners.ShouldContain(listener3);
            events.Listeners.ShouldContain(listener4);

            // expired expiring listeners should be removed
            events.Listeners.ShouldNotContain(listener5);
            events.Listeners.ShouldNotContain(listener6);

            // not-expired expiring listener should not be removed

            listener7.IsExpired(now).ShouldBeFalse();
            events.Listeners.ShouldContain(listener7);
        }
Exemplo n.º 54
0
        public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
        {
            var listener = new StubListener();
            var convention = new SelfTestConvention();

            convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass));

            listener.ShouldHaveEntries("Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.",
                                       "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Fail failed: 'Fail' failed!",
                                       "Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassA passed.",
                                       "Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassB passed.");
        }
Exemplo n.º 55
0
        public void remove_listener()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            var listener5 = MockRepository.GenerateMock<IListener<Message1>>();
            events.AddListeners(listener1, listener2, listener3, this, listener4, listener5);

            var message1 = new Message1();

            events.RemoveListener(listener5);
            events.SendMessage(message1);

            listener5.AssertWasNotCalled(x => x.Handle(message1));
        }
Exemplo n.º 56
0
        public void send_message_that_creates_on_the_fly()
        {
            var listener1 = new StubListener<Message1>();
            events.AddListener(listener1);

            events.SendMessage<Message1>();

            Wait.Until(() => listener1.LastMessage != null);

            listener1.LastMessage.ShouldBeOfType<Message1>();
        }
Exemplo n.º 57
0
        protected Output Run()
        {
            using (var console = new RedirectedConsole())
            {
                var listener = new StubListener();

                Convention.Execute(listener, typeof(SampleTestClass));

                return new Output(console.Lines.ToArray(), listener.Entries.ToArray());
            }
        }
Exemplo n.º 58
0
        public void exposes_all_the_listeners()
        {
            var listener1 = new StubListener<Message1>();
            var listener2 = new StubListener<Message1>();
            var listener3 = new StubListener<Message1>();
            var listener4 = new StubListener<Message2>();

            events.AddListeners(listener1, listener2, listener3, this, listener4);

            var listeners = events.Listeners.ToArray();
            var intersection = listeners.Intersect(new object[] {handler, this, listener1, listener2, listener3, listener4}).ToArray();
            listeners.Length.ShouldBe(intersection.Length);
        }