Skip to content

Commit

Permalink
Support invocation of abstract members when callsBaseMethods is set
Browse files Browse the repository at this point in the history
  • Loading branch information
blairconrad committed Jun 4, 2018
1 parent e875bf0 commit b998a8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Autofac.Extras.FakeItEasy/FakeRegistrationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This software is part of the Autofac IoC container
// Copyright (c) 2007 - 2008 Autofac Contributors
// Copyright (c) 2007 - 2018 Autofac Contributors
// http://autofac.org
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -103,26 +103,24 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(
/// <returns>A fake object.</returns>
private object CreateFake(TypedService typedService)
{
var fake = Create.Fake(typedService.ServiceType, this.ApplyOptions);

if (this._callsBaseMethods)
{
A.CallTo(fake).CallsBaseMethod();
}

return fake;
return Create.Fake(typedService.ServiceType, this.ApplyOptions);
}

private void ApplyOptions(IFakeOptions options)
{
if (this._strict)
{
options.Strict();
options = options.Strict();
}

if (this._configureFake != null)
{
options.ConfigureFake(x => this._configureFake(x));
options = options.ConfigureFake(x => this._configureFake(x));
}

if (this._callsBaseMethods)
{
options.CallsBaseMethods();
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/Autofac.Extras.FakeItEasy.Test/AutoFakeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void CanResolveFakesWhichCallsBaseMethods()
}
}

[Fact]
public void CanResolveFakesWhichCallsBaseMethodsAndInvokeAbstractMethod()
{
using (var fake = new AutoFake(callsBaseMethods: true))
{
var bar = fake.Resolve<Bar>();
bar.GoAbstractly();
}
}

[Fact]
public void CanResolveFakesWhichInvokeActionsWhenResolved()
{
Expand Down Expand Up @@ -198,6 +208,8 @@ public IBar Spawn()
{
throw new NotImplementedException();
}

public abstract void GoAbstractly();
}

public class Baz : IBaz
Expand Down

0 comments on commit b998a8e

Please sign in to comment.