Skip to content

Commit

Permalink
use local variable instead of re-calling .As()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminMichaelis committed Feb 8, 2024
1 parent 4280c54 commit 84801ef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Moq.AutoMock/AutoMocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,15 @@ public Mock<TService> WithSelfMock<TService, TImplementation>(
defaultValue ?? DefaultValue,
defaultValueProvider ?? DefaultValueProvider,
callBase ?? CallBase);

Mock<TService> serviceMock = selfMock.As<TService>();

WithTypeMap(typeMap =>
{
typeMap[typeof(TImplementation)] = new MockInstance(selfMock);
typeMap[typeof(TService)] = new MockInstance(selfMock.As<TService>());
typeMap[typeof(TService)] = new MockInstance(serviceMock);
});
return selfMock.As<TService>();
return serviceMock;
}

/// <summary>
Expand Down

0 comments on commit 84801ef

Please sign in to comment.