Skip to content

Commit

Permalink
Merge pull request #1406 from FakeItEasy/release/4.8.0
Browse files Browse the repository at this point in the history
Release 4.8.0
  • Loading branch information
thomaslevesque committed Aug 8, 2018
2 parents ce8ea2a + d3b7d8a commit 4d876c1
Show file tree
Hide file tree
Showing 38 changed files with 1,242 additions and 1,459 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
GITHUB_TOKEN:
secure: 5dFninlYVqNF98Pk9ykQwPU2pBFeQmbMOiFG2iSkg+hhcwF3UfmnDB07lvOwYtez
NUGET_API_KEY:
secure: ynOI8xETJ5V28b5ij2huIKbWRvqJU8QtLtFf8FLTJCWbxmcVP/OPpcF4B8jcOOKW
secure: COpoeqj1SAECW663nwrEcZr3bIqAryNuYZ+tv1uaFgoxhXQw+GEQyYDQXrRvXWkR

build_script:
- cmd: build.cmd
Expand Down
19 changes: 10 additions & 9 deletions docs/creating-fakes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ IList<object> fakes = Create.CollectionOfFake(type, 10);
```

##Explicit Creation Options
When creating fakes you can, through a fluent interface, specify options for how the fake should be created:

* Specify arguments for the constructor of the faked type.
* Specify additional interfaces that the fake should implement.
* Assign additional custom attributes to the faked type.
* Cause a fake to have [strict mocking semantics](strict-fakes.md).
* Configure all of a fake's methods to [use their original implementation](calling-base-methods.md).
* Create a fake that wraps another object.
* Specify a recorder for wrapping fakes.
When creating fakes you can, through a fluent interface, specify options for how the fake should be created, depending on the type of fake being made:

| Option | Applies to |
|---------------------------------------------------------------------------------------------------|---------------|
| Specify arguments for the constructor of the faked type | non-delegates |
| Specify additional interfaces that the fake should implemen | non-delegates |
| Assign additional custom attributes to the faked type | non-delegates |
| Cause a fake to have [strict mocking semantics](strict-fakes.md) | any fake |
| Configure all of a fake's methods to [use their original implementation](calling-base-methods.md) | classes |
| Create a fake that wraps another object | any fake |

Examples:

Expand Down
13 changes: 4 additions & 9 deletions docs/specifying-a-call-to-configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ done using a method on the `A` class: `A.CallTo`.
## Specifying a method call or property `get` using an Expression

```csharp
A.CallTo(() => fakeShop.GetTopSellingCandy())
A.CallTo(() => fakeShop.Address)
A.CallTo(() => fakeShop.GetTopSellingCandy()).Returns(lollipop);
A.CallTo(() => fakeShop.Address).Returns("123 Fake Street");
```

The expressions in the above example are not evaluated by FakeItEasy:
no call to `GetTopSellingCandy` or `Address` is made. The expressions
are just used to identify which call to configure.

are just used to identify which call to configure, after which
`A.CallTo` returns an object that can be used to specify how the fake
should behave when the call is made. For example:
should behave when the call is made.

```csharp
A.CallTo(() => fakeShop.GetTopSellingCandy())
.Returns(lollipop);
```

Many types of actions can be specified, including
[returning various values](specifying-return-values.md),
Expand Down
8 changes: 4 additions & 4 deletions src/FakeItEasy/Configuration/DefaultInterceptionAsserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace FakeItEasy.Configuration
internal class DefaultInterceptionAsserter
: IInterceptionAsserter
{
private readonly IProxyGenerator proxyGenerator;
private readonly IMethodInterceptionValidator methodInterceptionValidator;

public DefaultInterceptionAsserter(IProxyGenerator proxyGenerator)
public DefaultInterceptionAsserter(IMethodInterceptionValidator methodInterceptionValidator)
{
this.proxyGenerator = proxyGenerator;
this.methodInterceptionValidator = methodInterceptionValidator;
}

public void AssertThatMethodCanBeInterceptedOnInstance(MethodInfo method, object callTarget)
{
string failReason;
if (!this.proxyGenerator.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason))
if (!this.methodInterceptionValidator.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason))
{
string memberType = method.IsPropertyGetterOrSetter() ? "property" : "method";
string description = method.GetDescription();
Expand Down
97 changes: 0 additions & 97 deletions src/FakeItEasy/Core/DefaultExceptionThrower.cs

This file was deleted.

59 changes: 59 additions & 0 deletions src/FakeItEasy/Core/DummyCreationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace FakeItEasy.Core
{
using System;
using System.Runtime.Serialization;

/// <summary>
/// An exception that is thrown when there was an error creating a Dummy.
/// </summary>
#if FEATURE_BINARY_SERIALIZATION
[Serializable]
#endif
public class DummyCreationException
: Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="DummyCreationException"/> class.
/// </summary>
public DummyCreationException()
: base(ExceptionMessages.DummyCreationExceptionDefault)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DummyCreationException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public DummyCreationException(string message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DummyCreationException"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public DummyCreationException(string message, Exception innerException)
: base(message, innerException)
{
}

#if FEATURE_BINARY_SERIALIZATION
/// <summary>
/// Initializes a new instance of the <see cref="DummyCreationException"/> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">
/// The <paramref name="info"/> parameter is null.
/// </exception>
/// <exception cref="T:System.Runtime.Serialization.SerializationException">
/// The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0).
/// </exception>
protected DummyCreationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}
15 changes: 0 additions & 15 deletions src/FakeItEasy/Core/IExceptionThrower.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@
using Castle.DynamicProxy;
using FakeItEasy.Core;

internal class CastleDynamicProxyGenerator
: FakeItEasy.Creation.IProxyGenerator
internal static class CastleDynamicProxyGenerator
{
private static readonly IProxyGenerationHook ProxyGenerationHook = new InterceptEverythingHook();
private static readonly ProxyGenerator ProxyGenerator = new ProxyGenerator();
private readonly CastleDynamicProxyInterceptionValidator interceptionValidator;

public CastleDynamicProxyGenerator(CastleDynamicProxyInterceptionValidator interceptionValidator)
{
this.interceptionValidator = interceptionValidator;
}

public ProxyGeneratorResult GenerateProxy(
public static ProxyGeneratorResult GenerateProxy(
Type typeOfProxy,
IEnumerable<Type> additionalInterfacesToImplement,
IEnumerable<object> argumentsForConstructor,
Expand All @@ -34,7 +27,7 @@ public CastleDynamicProxyGenerator(CastleDynamicProxyInterceptionValidator inter
Guard.AgainstNull(attributes, nameof(attributes));
Guard.AgainstNull(fakeCallProcessorProvider, nameof(fakeCallProcessorProvider));

if (!this.CanGenerateProxy(typeOfProxy, out string failReason))
if (!CanGenerateProxy(typeOfProxy, out string failReason))
{
return new ProxyGeneratorResult(failReason);
}
Expand All @@ -50,12 +43,7 @@ public CastleDynamicProxyGenerator(CastleDynamicProxyInterceptionValidator inter
return CreateProxyGeneratorResult(typeOfProxy, options, additionalInterfacesToImplement, argumentsForConstructor, fakeCallProcessorProvider);
}

public bool MethodCanBeInterceptedOnInstance(MethodInfo method, object callTarget, out string failReason)
{
return this.interceptionValidator.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason);
}

public bool CanGenerateProxy(Type typeOfProxy, out string failReason)
public static bool CanGenerateProxy(Type typeOfProxy, out string failReason)
{
if (typeOfProxy.GetTypeInfo().IsValueType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Reflection;
using FakeItEasy.Core;

internal class CastleDynamicProxyInterceptionValidator
internal class CastleDynamicProxyInterceptionValidator : IMethodInterceptionValidator
{
private readonly MethodInfoManager methodInfoManager;

Expand All @@ -14,7 +14,7 @@ public CastleDynamicProxyInterceptionValidator(MethodInfoManager methodInfoManag
this.methodInfoManager = methodInfoManager;
}

public virtual bool MethodCanBeInterceptedOnInstance(MethodInfo method, object callTarget, out string failReason)
public bool MethodCanBeInterceptedOnInstance(MethodInfo method, object callTarget, out string failReason)
{
var invokedMethod = this.GetInvokedMethod(method, callTarget);

Expand Down Expand Up @@ -55,8 +55,7 @@ private static string GetReasonForWhyMethodCanNotBeIntercepted(MethodInfo method
return "Non-virtual members can not be intercepted. Only interface members and virtual, overriding, and abstract members can be intercepted.";
}

string message;
if (!Castle.DynamicProxy.ProxyUtil.IsAccessible(method, out message))
if (!Castle.DynamicProxy.ProxyUtil.IsAccessible(method, out var message))
{
return message;
}
Expand Down
Loading

0 comments on commit 4d876c1

Please sign in to comment.