Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Telerik.JustMock/Core/Behaviors/RecursiveMockingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ private object CreateMock(Type returnType, MocksRepository repository, Invocatio
? CreateMock(elementType, repository, invocation)
: elementType.GetDefaultValue();

Expression<Func<Task<object>>> taskFromResult = () => MockingUtil.TaskFromResult((object)null);
mock = ((MethodCallExpression)taskFromResult.Body).Method
.GetGenericMethodDefinition()
var taskFromResultMethod = typeof(MockingUtil).GetMethod("TaskFromResult", BindingFlags.Static | BindingFlags.Public);

mock = taskFromResultMethod
.MakeGenericMethod(elementType)
.Invoke(null, new object[] { taskResultValue });
}
Expand All @@ -189,6 +189,10 @@ private object CreateMock(Type returnType, MocksRepository repository, Invocatio
{
mock = String.Empty;
}
else if (returnType.IsValueType)
{
mock = returnType.GetDefaultValue();
}
else
{
try
Expand Down
14 changes: 7 additions & 7 deletions Telerik.JustMock/Core/Behaviors/ThrowAsyncExceptionBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Telerik.JustMock.Core.Context;
using Telerik.JustMock.Setup;
Expand Down Expand Up @@ -49,13 +50,12 @@ public void Process(Invocation invocation)

var elementType = returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>)
? returnType.GetGenericArguments()[0] : typeof(object);
Expression<Func<Task<object>>> taskFromException =
() => MockingUtil.TaskFromException<object>((Exception)null);
var mock =
((MethodCallExpression)taskFromException.Body).Method
.GetGenericMethodDefinition()
.MakeGenericMethod(elementType)
.Invoke(null, new object[] { this.exception });

var taskFromException = typeof(MockingUtil).GetMethod("TaskFromException", BindingFlags.Static | BindingFlags.Public);

var mock = taskFromException
.MakeGenericMethod(elementType)
.Invoke(null, new object[] { this.exception });

var parentMock = invocation.MockMixin;
var mockMixin = MocksRepository.GetMockMixin(mock, null);
Expand Down