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); }
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); }
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."); }
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); }
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."); }
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); }
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"); }
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); }
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); }
public void SetUp() { _listener = new StubListener(); Log.Src.Listeners.Add(_listener); _origLevel = Log.Src.Switch.Level; Log.Src.Switch.Level = SourceLevels.Off; }
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!"); }
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!"); }
public void ShouldPassUponSuccessfulAsyncExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener, typeof(AwaitThenPassTestClass)); listener.Entries.ShouldEqual( "Fixie.Tests.TestMethods.AsyncMethodTests+AwaitThenPassTestClass.Test passed."); }
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."); }
public void ShouldPassUponSuccessfulExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener, typeof(PassTestClass)); listener.Entries.ShouldEqual( "Fixie.Tests.TestMethods.NullaryMethodTests+PassTestClass.Pass passed."); }
public void ShouldPassUponSuccessfulExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener, typeof(PassTestClass)); listener.ShouldHaveEntries( "Fixie.Tests.TestClasses.CaseTests+PassTestClass.Pass passed."); }
public void ShouldPassUponSuccessfulExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener , typeof(PassTestClass)); listener.ShouldHaveEntries( "Fixie.Tests.TestClasses.CaseTests+PassTestClass.Pass passed."); }
public void ShouldPassUponSuccessfulAsyncExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener, typeof(AwaitThenPassTestClass)); listener.Entries.ShouldEqual( "Fixie.Tests.TestClasses.AsyncCaseTests+AwaitThenPassTestClass.Test passed."); }
public void ShouldPassUponSuccessfulExecution() { var listener = new StubListener(); new SelfTestConvention().Execute(listener , typeof(PassTestClass)); listener.Entries.ShouldEqual( "Fixie.Tests.TestMethods.NullaryMethodTests+PassTestClass.Pass passed."); }
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."); }
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."); }
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!"); }
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."); }
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"); }
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."); }
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"); }
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); }
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); }
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())); } }
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."); }
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>(); }
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())); } }
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."); }
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."); }
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()); } }
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!"); }
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."); }
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); }
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!"); }
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); }
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."); }
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."); }
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."); }
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"); }
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."); }
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."); }
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); }
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)); }
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>(); }
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()); } }
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); }