Пример #1
0
        public MockedInstance GenerateMock(MockingContext context, Type type)
        {
            var elementType = type.GetGenericArguments()[0];
            var mockInstance = context.GenerateMock(elementType);
            var list = (IList)typeof(List<>).MakeGenericType(elementType).GetConstructor(new Type[0]).Invoke(new object[0]);
            list.Add(mockInstance.InstanceToPassToConstructor);

            return new MockedInstance(elementType, mockInstance.Mock, list);
        }
Пример #2
0
        public MockedInstance GenerateMock(MockingContext context, Type type)
        {
            var mocks = type
                           .GetMostSpecificConstructor()
                           .GetParameters()
                           .Select(param => context.GenerateMock(param.ParameterType))
                           .Select(mock => mock.Mock.Object)
                           .ToArray();

            return new MockedInstance(type, type.CreateMock(mocks));
        }
Пример #3
0
        public MockedInstance GenerateMock(MockingContext context, Type type)
        {
            var dependencyType = type.GetElementType();
            var mockInstance = context.GenerateMock(dependencyType);
            var array = Array.CreateInstance(dependencyType, 1);

            for (var i = 0; i < array.Length; i++)
            {
                array.SetValue(mockInstance.InstanceToPassToConstructor, i);
            }

            return new MockedInstance(dependencyType, mockInstance.Mock, array);
        }