示例#1
0
文件: Resolver.cs 项目: yln/Nukito
        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);
        }
示例#2
0
文件: Request.cs 项目: yln/Nukito
        private Request(Request parent, Type type)
        {
            Parent = parent;
              Type = type;

              Settings = parent.Settings;
              Instances = parent.Instances;
        }
示例#3
0
文件: Resolver.cs 项目: yln/Nukito
        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);
        }
示例#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);
        }
示例#5
0
文件: Resolver.cs 项目: yln/Nukito
        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;
        }