Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private Request(Request parent, Type type)
        {
            Parent = parent;
              Type = type;

              Settings = parent.Settings;
              Instances = parent.Instances;
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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;
        }