Skip to content

Commit

Permalink
Merge pull request #1554 from blairconrad/explain-5-parameters
Browse files Browse the repository at this point in the history
Explain how to deal with calls of more than 4 parameters
  • Loading branch information
thomaslevesque committed Jan 1, 2019
2 parents 713a2d6 + 131dfae commit 26ce84b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/argument-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ A.CallTo(() => fake.Bar(null, 0))
.Throws<Exception>();
```

Strongly typed overloads of `WhenArgumentsMatch` are also available:
Strongly typed overloads of `WhenArgumentsMatch` are also available for methods of up to 4
parameters (if a method has more parameters, use the variant described above):

```csharp
A.CallTo(() => fake.Bar(null, 0))
Expand Down
7 changes: 4 additions & 3 deletions docs/invoking-custom-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ arguments supplied to the faked method. These act similarly to how you
specify return values that are calculated at call time. For example

```csharp
// Pass up to 4 original call argument values into the method that creates the exception.
A.CallTo(()=>fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
// Pass up to 4 original call argument values into the callback method.
A.CallTo(() => fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
.Invokes((DateTime when) => System.Console.Out.WriteLine("showing sweet sales for " + when))
.Returns(17);

// Pass an IFakeObjectCall into the creation method for more advanced scenarios.
// Pass an IFakeObjectCall into the callback for more advanced scenarios,
// including configuring methods that have more than 4 parameters.
A.CallTo(() => fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
.Invokes(callObject => System.Console.Out.WriteLine(callObject.FakedObject +
" is closed on " +
Expand Down
8 changes: 7 additions & 1 deletion docs/throwing-exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ A.CallTo(() => fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
A.CallTo(() => fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
.Throws((DateTime when)=>new InvalidDateException(when + " is in the future"));

// Pass an IFakeObjectCall into the creation method for more advanced scenarios.
// Pass an IFakeObjectCall into the creation method for more advanced scenarios,
// including throwing an exception from a method that has more than 4 parameters.
A.CallTo(() => fakeShop.NumberOfSweetsSoldOn(A<DateTime>._))
.Throws(callObject => new InvalidDateException(callObject.FakedObject +
" is closed on " +
Expand All @@ -57,3 +58,8 @@ A.CallTo(() => fakeShop.OrderSweetsAsync("cheeseburger"))

This will cause the configured method to return a failed `Task` whose `Exception` property
is set to the exception specified in `ThrowsAsync`.

As with `Throws` above, `ThrowsAsync` has several overloads, including those that take `Func`s of up to
4 parameters, and one that takes a `Func` that operates on an `IFakeObjectCall`. The latter is suitable
for examining, in detail, the call that triggers the exception, or for configuring a method that has
more than 4 parameters.

0 comments on commit 26ce84b

Please sign in to comment.