Skip to content

Commit b998a8e

Browse files
committed
Support invocation of abstract members when callsBaseMethods is set
1 parent e875bf0 commit b998a8e

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/Autofac.Extras.FakeItEasy/FakeRegistrationHandler.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This software is part of the Autofac IoC container
2-
// Copyright (c) 2007 - 2008 Autofac Contributors
2+
// Copyright (c) 2007 - 2018 Autofac Contributors
33
// http://autofac.org
44
//
55
// Permission is hereby granted, free of charge, to any person
@@ -103,26 +103,24 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(
103103
/// <returns>A fake object.</returns>
104104
private object CreateFake(TypedService typedService)
105105
{
106-
var fake = Create.Fake(typedService.ServiceType, this.ApplyOptions);
107-
108-
if (this._callsBaseMethods)
109-
{
110-
A.CallTo(fake).CallsBaseMethod();
111-
}
112-
113-
return fake;
106+
return Create.Fake(typedService.ServiceType, this.ApplyOptions);
114107
}
115108

116109
private void ApplyOptions(IFakeOptions options)
117110
{
118111
if (this._strict)
119112
{
120-
options.Strict();
113+
options = options.Strict();
121114
}
122115

123116
if (this._configureFake != null)
124117
{
125-
options.ConfigureFake(x => this._configureFake(x));
118+
options = options.ConfigureFake(x => this._configureFake(x));
119+
}
120+
121+
if (this._callsBaseMethods)
122+
{
123+
options.CallsBaseMethods();
126124
}
127125
}
128126
}

test/Autofac.Extras.FakeItEasy.Test/AutoFakeFixture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public void CanResolveFakesWhichCallsBaseMethods()
8989
}
9090
}
9191

92+
[Fact]
93+
public void CanResolveFakesWhichCallsBaseMethodsAndInvokeAbstractMethod()
94+
{
95+
using (var fake = new AutoFake(callsBaseMethods: true))
96+
{
97+
var bar = fake.Resolve<Bar>();
98+
bar.GoAbstractly();
99+
}
100+
}
101+
92102
[Fact]
93103
public void CanResolveFakesWhichInvokeActionsWhenResolved()
94104
{
@@ -198,6 +208,8 @@ public IBar Spawn()
198208
{
199209
throw new NotImplementedException();
200210
}
211+
212+
public abstract void GoAbstractly();
201213
}
202214

203215
public class Baz : IBaz

0 commit comments

Comments
 (0)