public void SetUp() { Fake.InitializeFixture(this); A.CallTo(() => this.callFormatter.GetDescription(A<IFakeObjectCall>._)) .Returns("Default call description"); this.calls = new List<IFakeObjectCall>(); this.writer = new StringBuilderOutputWriter(); }
private static void WriteArgumentList(StringBuilderOutputWriter builder, IEnumerable <ArgumentInfo> arguments) { int lengthWhenStarting = builder.Builder.Length; foreach (var argument in arguments) { if (builder.Builder.Length > lengthWhenStarting) { builder.Write(", "); } WriteArgument(builder, argument); } }
private void WriteArgumentList(StringBuilderOutputWriter builder) { int lengthWhenStarting = builder.Builder.Length; foreach (var argument in this.Arguments) { if (builder.Builder.Length > lengthWhenStarting) { builder.Write(", "); } builder.WriteArgumentValue(argument); } }
public UnorderedCallAssertion MustHaveHappened(Repeated repeatConstraint) { Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint)); var asserter = this.asserterFactory.Invoke(this.Calls); var description = new StringBuilderOutputWriter(); this.RuleBeingBuilt.WriteDescriptionOfValidCall(description); asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString()); return(new UnorderedCallAssertion(this.manager, this.Matcher, description.Builder.ToString(), repeatConstraint)); }
internal static Action <IOutputWriter> Writes( this IArgumentConstraintManager <Action <IOutputWriter> > manager, string expectedValue) { return(manager.NullCheckedMatches( x => { var writer = new StringBuilderOutputWriter(); x.Invoke(writer); return string.Equals(writer.Builder.ToString(), expectedValue, StringComparison.Ordinal); }, x => x.Write("action that writes ").WriteArgumentValue(expectedValue).Write(" to output."))); }
public void BeNullGuarded() { var matches = this.Matches(this.call); if (matches) { return; } var builder = new StringBuilderOutputWriter(); this.WriteDescriptionTo(builder); builder.WriteLine(); this.WriteActualValueTo(builder); var reason = builder.Builder.ToString(); Execute.Assertion.FailWith(reason); }
public IAfterMustHaveHappenedConfiguration MustHaveHappened(Repeated repeatConstraint) { Guard.AgainstNull(repeatConstraint, "repeatConstraint"); this.manager.RemoveRule(this.RuleBeingBuilt); var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>()); var description = new StringBuilderOutputWriter(); this.RuleBeingBuilt.WriteDescriptionOfValidCall(description); asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString()); return(new AfterMustHaveHappenedConfiguration(this.manager, this.Matcher, description.Builder.ToString(), repeatConstraint)); }
private static string CreateExceptionMessage( IEnumerable<IFakeObjectCall> calls, CallWriter callWriter, string callDescription, string repeatDescription, int matchedCallCount) { var writer = new StringBuilderOutputWriter(); writer.WriteLine(); using (writer.Indent()) { AppendCallDescription(callDescription, writer); AppendExpectation(calls, repeatDescription, matchedCallCount, writer); AppendCallList(calls, callWriter, writer); writer.WriteLine(); } return writer.Builder.ToString(); }
private string CreateExceptionMessage(string callDescription, string repeatDescription, int repeat) { var outputWriter = new StringBuilderOutputWriter(); outputWriter.WriteLine(); using (outputWriter.Indent()) { AppendCallDescription(callDescription, outputWriter); this.AppendExpectation(repeatDescription, repeat, outputWriter); this.AppendCallList(outputWriter); outputWriter.WriteLine(); } return(outputWriter.Builder.ToString()); }
private static string CreateExceptionMessage( IEnumerable <IFakeObjectCall> calls, CallWriter callWriter, string callDescription, string repeatDescription, int matchedCallCount) { var writer = new StringBuilderOutputWriter(); writer.WriteLine(); using (writer.Indent()) { AppendCallDescription(callDescription, writer); AppendExpectation(calls, repeatDescription, matchedCallCount, writer); AppendCallList(calls, callWriter, writer); writer.WriteLine(); } return(writer.Builder.ToString()); }
public void Should_append_where_predicates_to_description_correctly() { // Arrange this.rule.DescriptionOfValidCallReturnValue = "description"; this.rule.ApplyWherePredicate(x => true, x => x.Write("description of first where")); this.rule.ApplyWherePredicate(x => true, x => x.Write("description of second where")); var descriptionWriter = new StringBuilderOutputWriter(); // Act this.rule.WriteDescriptionOfValidCall(descriptionWriter); // Assert Assert.That(descriptionWriter.Builder.ToString(), Is.EqualTo(@"description where description of first where and description of second where")); }
public void BeNullGuarded() { var matches = this.Matches(this.call); if (matches) { return; } var builder = new StringBuilderOutputWriter(); this.WriteDescriptionTo(builder); builder.WriteLine(); this.WriteActualValueTo(builder); var reason = builder.Builder.ToString(); Execute.Assertion.FailWith(reason); }
public virtual void AssertWasCalled( Func <ICompletedFakeObjectCall, bool> callPredicate, Action <IOutputWriter> callDescriber, Repeated repeatConstraint) { var lastCall = this.calls.LastOrDefault(); int lastSequenceNumber = lastCall != null?SequenceNumberManager.GetSequenceNumber(lastCall) : -1; bool IsBeforeAssertionStart(ICompletedFakeObjectCall call) => SequenceNumberManager.GetSequenceNumber(call) <= lastSequenceNumber; var matchedCallCount = this.calls.Count(c => IsBeforeAssertionStart(c) && callPredicate(c)); if (!repeatConstraint.Matches(matchedCallCount)) { var description = new StringBuilderOutputWriter(); callDescriber.Invoke(description); var message = CreateExceptionMessage(this.calls.Where(IsBeforeAssertionStart), this.callWriter, description.Builder.ToString(), repeatConstraint.ToString(), matchedCallCount); throw new ExpectationException(message); } }
private void WriteFailReason(StringBuilderOutputWriter description) { if (this.thrown is null) { description.Write("did not throw any exception."); } else { var argumentNullException = this.thrown as ArgumentNullException; if (argumentNullException is object) { description.Write( $"threw ArgumentNullException with wrong argument name, it should be {this.ArgumentName}."); } else { description.Write($"threw unexpected {this.thrown.GetType()}."); } } }
private void WriteFailReason(StringBuilderOutputWriter description) { if (this.thrown == null) { description.Write("did not throw any exception."); } else { var argumentNullException = this.thrown as ArgumentNullException; if (argumentNullException != null) { description.Write( "threw ArgumentNullException with wrong argument name, it should be \"{0}\"." .FormatInvariant(this.ArgumentName)); } else { description.Write("threw unexpected {0}.".FormatInvariant(this.thrown.GetType().FullName)); } } }
private static void ThrowExceptionWhenAssertionFailed( List<AssertedCall> assertedCalls, CallWriter callWriter, IEnumerable<IFakeObjectCall> originalCallList) { var message = new StringBuilderOutputWriter(); message.WriteLine(); message.WriteLine(); using (message.Indent()) { message.Write("Assertion failed for the following calls:"); message.WriteLine(); using (message.Indent()) { foreach (var call in assertedCalls) { message.Write("'"); message.Write(call.CallDescription); message.Write("' "); message.Write("repeated "); message.Write(call.RepeatDescription); message.WriteLine(); } } message.Write("The calls where found but not in the correct order among the calls:"); message.WriteLine(); using (message.Indent()) { callWriter.WriteCalls(originalCallList, message); } } throw new ExpectationException(message.Builder.ToString()); }
private static void ThrowExceptionWhenAssertionFailed( List <AssertedCall> assertedCalls, CallWriter callWriter, List <ICompletedFakeObjectCall> originalCallList) { var message = new StringBuilderOutputWriter(); message.WriteLine(); message.WriteLine(); using (message.Indent()) { message.Write("Assertion failed for the following calls:"); message.WriteLine(); using (message.Indent()) { foreach (var call in assertedCalls) { message.Write("'"); message.Write(call.CallDescription); message.Write("' "); message.Write("repeated "); message.Write(call.RepeatDescription); message.WriteLine(); } } message.Write("The calls where found but not in the correct order among the calls:"); message.WriteLine(); using (message.Indent()) { callWriter.WriteCalls(originalCallList, message); } } throw new ExpectationException(message.Builder.ToString()); }
public void Should_append_where_predicates_to_description_correctly() { // Arrange this.rule.DescriptionOfValidCallReturnValue = "description"; this.rule.ApplyWherePredicate(x => true, x => x.Write("description of first where")); this.rule.ApplyWherePredicate(x => true, x => x.Write("description of second where")); var descriptionWriter = new StringBuilderOutputWriter(); // Act this.rule.WriteDescriptionOfValidCall(descriptionWriter); // Assert var expectedDescription = @"description where description of first where and description of second where"; descriptionWriter.Builder.ToString().Should().Be(expectedDescription); }
public void Should_write_description_of_valid_call_by_calling_the_description_property() { // Arrange this.rule.DescriptionOfValidCallReturnValue = "description"; var writer = new StringBuilderOutputWriter(); // Act this.rule.WriteDescriptionOfValidCall(writer); // Assert writer.Builder.ToString().Should().Be("description"); }
public void WriteTo(StringBuilderOutputWriter builder) { builder.Write(this.CallDescription); builder.Write("("); WriteArgumentList(builder, this.ValidArguments); builder.Write(")"); }
private void WriteActualValueTo(StringBuilderOutputWriter builder) { builder.Write( "When called with the following arguments the method did not throw the appropriate exception:"); builder.WriteLine(); this.state.WriteFailingCallsDescriptions(builder); }
private static void WriteArgumentList(StringBuilderOutputWriter builder, IEnumerable<ArgumentInfo> arguments) { int lengthWhenStarting = builder.Builder.Length; foreach (var argument in arguments) { if (builder.Builder.Length > lengthWhenStarting) { builder.Write(", "); } WriteArgument(builder, argument); } }
public void WriteFailingCallDescription(StringBuilderOutputWriter builder) { builder.Write("("); this.WriteArgumentList(builder); builder.Write(") "); this.WriteFailReason(builder); }
public void WriteFailingCallsDescriptions(StringBuilderOutputWriter builder) { using (builder.Indent()) { foreach (var call in this.unguardedCalls) { call.WriteFailingCallDescription(builder); builder.WriteLine(); } } }
private void WriteArgumentList(StringBuilderOutputWriter builder) { int lengthWhenStarting = builder.Builder.Length; foreach (var argument in this.Arguments) { if (builder.Builder.Length > lengthWhenStarting) { builder.Write(", "); } builder.WriteArgumentValue(argument); } }
private void WriteFailReason(StringBuilderOutputWriter description) { if (this.thrown == null) { description.Write("did not throw any exception."); } else { var argumentNullException = this.thrown as ArgumentNullException; if (argumentNullException != null) { description.Write( "threw ArgumentNullException with wrong argument name, it should be \"{0}\"." .FormatInvariant(this.ArgumentName)); } else { description.Write("threw unexpected {0}.".FormatInvariant(this.thrown.GetType().FullName)); } } }
private void WriteDescriptionTo(StringBuilderOutputWriter builder) { builder.Write("Expected calls to "); this.state.WriteTo(builder); builder.Write(" to be null guarded."); }
public void Should_create_constraint_that_writes_beginning_and_end_of_argument_constraint() { // Arrange var writer = new StringBuilderOutputWriter(); // Act this.constraintManager.Matches(x => true, x => x.Write("foo")); // Assert this.createdConstraint.WriteDescription(writer); Assert.That(writer.Builder.ToString(), Is.EqualTo("<foo>")); }
private static void WriteArgument(StringBuilderOutputWriter builder, ArgumentInfo argument) { builder.Write("["); builder.Write(argument.ArgumentType.Name); builder.Write("]"); builder.Write(" "); builder.Write(argument.Name); }
private void WriteDescriptionTo(StringBuilderOutputWriter builder) { builder.Write("Expected calls to "); this.state.WriteTo(builder); builder.Write(" to be null guarded."); }
private string CreateExceptionMessage(string callDescription, string repeatDescription, int repeat) { var outputWriter = new StringBuilderOutputWriter(); outputWriter.WriteLine(); using (outputWriter.Indent()) { AppendCallDescription(callDescription, outputWriter); this.AppendExpectation(repeatDescription, repeat, outputWriter); this.AppendCallList(outputWriter); outputWriter.WriteLine(); } return outputWriter.Builder.ToString(); }