Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public static MockingContext Create(object[] dependencies)
        {
            var context = new MockingContext();
            context.AddMockGenerator(new ArrayMockGenerator());
            context.AddMockGenerator(new EnumerableMockGenerator());
            context.AddMockGenerator(new ConcreteMockGenerator());

            if (dependencies != null)
            {
                foreach (var dependency in dependencies)
                {
                    context.AddDependency(dependency);
                }
            }
            return context;
        }
Exemplo n.º 5
0
        public MockedInstance GenerateMock(MockingContext context, Type type)
        {
            var mockInstance = type.CreateMock();

            return new MockedInstance(type, mockInstance);
        }