diff --git a/Source/Mockolate/Setup/ReturnMethodSetup.cs b/Source/Mockolate/Setup/ReturnMethodSetup.cs index 0247918d..0668f668 100644 --- a/Source/Mockolate/Setup/ReturnMethodSetup.cs +++ b/Source/Mockolate/Setup/ReturnMethodSetup.cs @@ -420,11 +420,6 @@ protected override TResult GetReturnValue(MethodInvocation invocation, Func defaultValueGenerator) where TResult : default { - if (_returnCallbacks.Count == 0) - { - return defaultValueGenerator(); - } - if (!TryCast(invocation.Parameters[0].Value, out T1 p1, behavior)) { throw new MockException( @@ -709,11 +704,6 @@ protected override TResult GetReturnValue(MethodInvocation invocation, Func defaultValueGenerator) where TResult : default { - if (_returnCallbacks.Count == 0) - { - return defaultValueGenerator(); - } - if (!TryCast(invocation.Parameters[0].Value, out T1 p1, behavior)) { throw new MockException( @@ -1013,11 +1003,6 @@ protected override TResult GetReturnValue(MethodInvocation invocation, Func defaultValueGenerator) where TResult : default { - if (_returnCallbacks.Count == 0) - { - return defaultValueGenerator(); - } - if (!TryCast(invocation.Parameters[0].Value, out T1 p1, behavior)) { throw new MockException( @@ -1335,11 +1320,6 @@ protected override TResult GetReturnValue(MethodInvocation invocation, Func defaultValueGenerator) where TResult : default { - if (_returnCallbacks.Count == 0) - { - return defaultValueGenerator(); - } - if (!TryCast(invocation.Parameters[0].Value, out T1 p1, behavior)) { throw new MockException( diff --git a/Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs b/Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs index d6b17dfb..b5a5615b 100644 --- a/Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs +++ b/Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs @@ -199,6 +199,18 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo"); } + [Fact] + public async Task SetupWithReturn_ShouldReturnSetupValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method0() + .Returns("bar"); + + string result = sut.Method0(); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() { @@ -491,6 +503,18 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo-1"); } + [Fact] + public async Task SetupWithReturn_ShouldReturnSetupValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method1(It.IsAny()) + .Returns("bar"); + + string result = sut.Method1(1); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() { @@ -818,6 +842,18 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo-1-2"); } + [Fact] + public async Task SetupWithReturn_ShouldReturnSetupValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method2(It.IsAny(), It.IsAny()) + .Returns("bar"); + + string result = sut.Method2(1, 2); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() { @@ -1151,6 +1187,18 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo-1-2-3"); } + [Fact] + public async Task SetupWithReturn_ShouldReturnSetupValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method3(It.IsAny(), It.IsAny(), It.IsAny()) + .Returns("bar"); + + string result = sut.Method3(1, 2, 3); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() { @@ -1486,6 +1534,18 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo-1-2-3-4"); } + [Fact] + public async Task SetupWithReturn_ShouldIgnoreBaseValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method4(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()) + .Returns("bar"); + + string result = sut.Method4(1, 2, 3, 4); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() { @@ -1833,6 +1893,19 @@ public async Task SetupWithoutReturn_ShouldUseBaseValue() await That(result).IsEqualTo("foo-1-2-3-4-5"); } + [Fact] + public async Task SetupWithReturn_ShouldIgnoreBaseValue() + { + ReturnMethodSetupTest sut = Mock.Create(); + sut.SetupMock.Method.Method5(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()) + .Returns("bar"); + + string result = sut.Method5(1, 2, 3, 4, 5); + + await That(result).IsEqualTo("bar"); + } + [Fact] public async Task Throws_Callback_ShouldThrowException() {