private object CreateClassInstance(Request request) { var constructor = _constructorChooser.GetConstructor (request.Type); var arguments = constructor.GetParameters ().Select (p => Get (request.CreateSubRequest (p.ParameterType))).ToArray (); return _reflectionHelper.InvokeConstructor (constructor, arguments); }
private Request(Request parent, Type type) { Parent = parent; Type = type; Settings = parent.Settings; Instances = parent.Instances; }
private object Create(Request request) { if (!request.ForceMockCreation) { if (request.Type.IsClass && !request.Type.IsAbstract) return CreateClassInstance (request); if (request.Type.IsValueType) return Activator.CreateInstance (request.Type); } return _mockRepository.CreateMock (request.Type, request.Settings); }
public void GetReturnsInnerValue(MoqResolver moqResolver, Mock<IResolver> innerResolver) { // Arrange var request = new Request (typeof (string), false, new MockSettings(), new Dictionary<Type, object>()); var fakeInnerValue = new object(); innerResolver.Setup(x => x.Get (request)).Returns (fakeInnerValue); // Act var result = moqResolver.Get (request); // Assert result.Should().BeSameAs (fakeInnerValue); }
public object Get(Request request) { if (_mockRepository.IsMockRepositoryType (request.Type)) return _mockRepository.WrappedRepository; object obj; if (!request.Instances.TryGetValue (request.Type, out obj)) { obj = Create (request); request.Instances.Add (request.Type, obj); } return obj; }