EntityFrameworkCore.Testing.Moq.Helpers.NoSetUpDefaultValueProvider.GetModelType(System.Reflection.MethodInfo)

Here are the examples of the csharp api EntityFrameworkCore.Testing.Moq.Helpers.NoSetUpDefaultValueProvider.GetModelType(System.Reflection.MethodInfo) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : NoSetUpDefaultValueProvider.cs
with MIT License
from rgvlee

protected override object GetDefaultValue(Type type, Mock mock)
        {
            var dbContextMock = mock;
            var lastInvocation = mock.Invocations.Last();
            var invokedMethod = lastInvocation.Method;
            var arguments = lastInvocation.Arguments;

            var modelType = GetModelType(invokedMethod);
            if (modelType == null)
            {
                return invokedMethod.ReturnType.GetDefaultValue();
            }

            Logger.LogDebug("Setting up model '{type}'", modelType);

            var modelEnreplacedyType = _allModelEnreplacedyTypes.SingleOrDefault(x => x.ClrType.Equals(modelType));
            if (modelEnreplacedyType == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.CannotCreateDbSetTypeNotIncludedInModel,
                    invokedMethod.GetGenericArguments().Single().Name));
            }

            var setUpModelMethod = typeof(NoSetUpDefaultValueProvider<TDbContext>).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
                .Single(x => x.Name.Equals(modelEnreplacedyType.FindPrimaryKey() != null ? "SetUpModel" : "SetUpReadOnlyModel"));

            setUpModelMethod.MakeGenericMethod(modelType).Invoke(this, new[] { dbContextMock });

            return invokedMethod.Invoke(dbContextMock.Object, arguments?.ToArray());
        }