Skip to content

Commit 23540eb

Browse files
authored
Fix issue with generic types and SkipTypeMockHandler (#63)
1 parent 6cd3b02 commit 23540eb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

AutofacContrib.NSubstitute.Tests/TypesToSkipForMockingFixture.cs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void ManuallyCheckTypeToSkipOpenGeneric()
6262
.Build();
6363

6464
Assert.Throws<ComponentNotRegisteredException>(() => mock.Resolve<IDependency<object>>());
65+
Assert.That(mock.Resolve<IDependency2<object>>(), Is.NSubstituteMock);
6566
}
6667

6768
[Test]
@@ -81,6 +82,10 @@ public interface IDependency
8182
{
8283
}
8384

85+
public interface IDependency2<T>
86+
{
87+
}
88+
8489
public interface IDependency<T>
8590
{
8691
}

AutofacContrib.NSubstitute/MockHandlers/SkipTypeMockHandler.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ protected internal override void OnMockCreating(MockCreatingContext context)
4141
{
4242
foreach (var type in _types)
4343
{
44-
if (type.IsGenericType && type == type.GetGenericTypeDefinition())
44+
if (type.IsGenericType && context.Type.IsGenericType)
4545
{
46-
context.DoNotCreate();
46+
if (context.Type.GetGenericTypeDefinition() == type.GetGenericTypeDefinition())
47+
{
48+
context.DoNotCreate();
49+
}
4750
}
4851
else if (type == context.Type)
4952
{

0 commit comments

Comments
 (0)