예제 #1
0
        public void SetUp()
        {
            _serializationInfo = new SerializationInfo(ReflectionObjectMother.GetSomeOtherType(), new FormatterConverter());
            _streamingContext  = new StreamingContext(StreamingContextStates.File);

            _proxy = new ObjectWithoutDeserializationConstructorProxy(_serializationInfo, _streamingContext);
        }
예제 #2
0
        public void GetAdditionalTypeID_MultipleParticpantsProvidesID_ThrowsInvalidOperationException()
        {
            var additionalType = ReflectionObjectMother.GetSomeOtherType();

            var participantMock1 = MockRepository.GenerateStrictMock <IParticipant>();

            participantMock1.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock1.Expect(_ => _.GetAdditionalTypeID(additionalType)).Return(null);

            var participantMock2 = MockRepository.GenerateStrictMock <IParticipant>();

            participantMock2.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock2.Expect(_ => _.GetAdditionalTypeID(additionalType)).Return(new object());

            var participantMock3 = MockRepository.GenerateStrictMock <IParticipant>();

            participantMock3.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock3.Expect(_ => _.GetAdditionalTypeID(additionalType)).Return(new object());

            var typeAssembler = CreateTypeAssembler(participants: new[] { participantMock1, participantMock2, participantMock3 });

            Assert.That(
                () => typeAssembler.GetAdditionalTypeID(additionalType),
                Throws.InvalidOperationException
                .And.Message.EqualTo(string.Format("More than one participant returned an ID for the additional type '{0}'", additionalType.Name)));
        }
        public void SetUp()
        {
            _returnType    = ReflectionObjectMother.GetSomeType();
            _parameterType = ReflectionObjectMother.GetSomeOtherType();

            _type = new DelegateTypePlaceholder(_returnType, new[] { _parameterType }.AsOneTime());
        }
예제 #4
0
        public void GetAdditionalTypeID_MultipleParticpantsProvidesID_ThrowsInvalidOperationException()
        {
            var additionalType = ReflectionObjectMother.GetSomeOtherType();

            var participantMock1 = new Mock <IParticipant> (MockBehavior.Strict);

            participantMock1.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock1.Setup(_ => _.GetAdditionalTypeID(additionalType)).Returns(null).Verifiable();

            var participantMock2 = new Mock <IParticipant> (MockBehavior.Strict);

            participantMock2.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock2.Setup(_ => _.GetAdditionalTypeID(additionalType)).Returns(new object()).Verifiable();

            var participantMock3 = new Mock <IParticipant> (MockBehavior.Strict);

            participantMock3.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock3.Setup(_ => _.GetAdditionalTypeID(additionalType)).Returns(new object()).Verifiable();

            var typeAssembler = CreateTypeAssembler(participants: new[] { participantMock1.Object, participantMock2.Object, participantMock3.Object });

            Assert.That(
                () => typeAssembler.GetAdditionalTypeID(additionalType),
                Throws.InvalidOperationException
                .And.Message.EqualTo(string.Format("More than one participant returned an ID for the additional type '{0}'", additionalType.Name)));
        }
예제 #5
0
        public void SelectSingleProperty()
        {
            var properties =
                new[]
            {
                CreatePropertyStub("Property1", accessors: new[] { CreateMethodStub() }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Assembly) }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Public) })
            };
            var bindingFlags = (BindingFlags)1;
            var propertyType = ReflectionObjectMother.GetSomeType();
            var indexerTypes = new[] { ReflectionObjectMother.GetSomeOtherType() };
            var modifiers    = new[] { new ParameterModifier(2) };

            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Assembly, bindingFlags)).Return(true);
            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Public, bindingFlags)).Return(true);

            var binderMock = MockRepository.GenerateStrictMock <Binder>();
            var fakeResult = ReflectionObjectMother.GetSomeProperty();

            binderMock.Expect(mock => mock.SelectProperty(bindingFlags, new[] { properties[1], properties[2] }, propertyType, indexerTypes, modifiers))
            .Return(fakeResult);

            var result = _selector.SelectSingleProperty(
                properties, binderMock, bindingFlags, "Property2", _someDeclaringType, propertyType, indexerTypes, modifiers);

            _bindingFlagsEvaluatorMock.VerifyAllExpectations();
            binderMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeResult));
        }
예제 #6
0
        public void LoadTypes_DequeuesAllAssemblyContextDuringLoad()
        {
            var assembledType = typeof(AssembledType);

            _typeAssemblerMock.Stub(stub => stub.IsAssembledType(assembledType)).Return(true);

            var assembledTypeID = AssembledTypeIDObjectMother.Create();

            _typeAssemblerMock.Stub(stub => stub.ExtractTypeID(assembledType)).Return(assembledTypeID);

            var additionalGeneratedType = ReflectionObjectMother.GetSomeOtherType();

            _typeAssemblerMock.Stub(stub => stub.IsAssembledType(additionalGeneratedType)).Return(false);

            object additionalTypeID = new object();

            _typeAssemblerMock.Stub(stub => stub.GetAdditionalTypeID(additionalGeneratedType)).Return(additionalTypeID);

            var assemblyContexts = new[] { CreateAssemblyContext(), CreateAssemblyContext() };

            bool isDequeued0 = false;
            bool isDequeued1 = false;

            _assemblyContextPoolMock
            .Expect(mock => mock.DequeueAll())
            .Return(assemblyContexts)
            .WhenCalled(
                mi =>
            {
                isDequeued0 = true;
                isDequeued1 = true;
            });

            _assemblyContextPoolMock
            .Expect(mock => mock.Enqueue(assemblyContexts[0]))
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued0, Is.True);
                isDequeued0 = false;
            });

            _assemblyContextPoolMock
            .Expect(mock => mock.Enqueue(assemblyContexts[1]))
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued0, Is.False);
                Assert.That(isDequeued1, Is.True);
                isDequeued1 = false;
                Assert.That(_assembledTypes.ContainsKey(assembledTypeID), Is.True);
                Assert.That(_additionalTypes.ContainsKey(additionalTypeID), Is.True);
            });

            _cache.LoadTypes(new[] { assembledType, additionalGeneratedType });

            _assemblyContextPoolMock.VerifyAllExpectations();
        }
예제 #7
0
        public void SetUp()
        {
            _genericTypeDefinition = typeof(List <>);
            _typeArg = ReflectionObjectMother.GetSomeType();

            _info1 = new TypeInstantiationInfo(_genericTypeDefinition, new[] { _typeArg }.AsOneTime());
            _info2 = new TypeInstantiationInfo(typeof(Func <>), new[] { _typeArg });
            _info3 = new TypeInstantiationInfo(_genericTypeDefinition, new[] { ReflectionObjectMother.GetSomeOtherType() });
            _info4 = new TypeInstantiationInfo(_genericTypeDefinition, new[] { _typeArg });
        }
예제 #8
0
        public void GetAssembledType_AssembledTypeID()
        {
            var typeID            = AssembledTypeIDObjectMother.Create();
            var fakeAssembledType = ReflectionObjectMother.GetSomeOtherType();

            _typeCacheMock.Expect(mock => mock.GetOrCreateType(Arg <AssembledTypeID> .Matches(id => id.Equals(typeID)))).Return(fakeAssembledType);

            var result = _service.GetAssembledType(typeID);

            _typeCacheMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeAssembledType));
        }
예제 #9
0
        public void GetRequestedType()
        {
            var assembledType     = ReflectionObjectMother.GetSomeType();
            var fakeRequestedType = ReflectionObjectMother.GetSomeOtherType();

            _typeAssemblerMock.Expect(mock => mock.GetRequestedType(assembledType)).Return(fakeRequestedType);

            var result = _service.GetRequestedType(assembledType);

            _typeAssemblerMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeRequestedType));
        }
예제 #10
0
        public void Initialization()
        {
            var proxyType      = new LoadedProxy(typeof(int), typeof(string));
            var additionalType = ReflectionObjectMother.GetSomeOtherType();
            var state          = new ParticipantState();

            var context = new LoadedTypesContext(new[] { proxyType }.AsOneTime(), new[] { additionalType }.AsOneTime(), state);

            Assert.That(context.ProxyTypes, Is.EqualTo(new[] { proxyType }));
            Assert.That(context.AdditionalTypes, Is.EqualTo(new[] { additionalType }));
            Assert.That(context.ParticipantState, Is.SameAs(state));
        }
예제 #11
0
        public void GetAssembledType_AssembledTypeID()
        {
            var typeID            = AssembledTypeIDObjectMother.Create();
            var fakeAssembledType = ReflectionObjectMother.GetSomeOtherType();

            _typeCacheMock.Setup(mock => mock.GetOrCreateType(It.Is <AssembledTypeID> (id => id.Equals(typeID)))).Returns(fakeAssembledType).Verifiable();

            var result = _service.GetAssembledType(typeID);

            _typeCacheMock.Verify();
            Assert.That(result, Is.SameAs(fakeAssembledType));
        }
예제 #12
0
        public void GetTypeIDForRequestedType()
        {
            var fakeRequestedType = ReflectionObjectMother.GetSomeOtherType();
            var fakeTypeID        = AssembledTypeIDObjectMother.Create();

            _typeAssemblerMock.Expect(mock => mock.ComputeTypeID(fakeRequestedType)).Return(fakeTypeID);

            var result = _service.GetTypeIDForRequestedType(fakeRequestedType);

            _typeAssemblerMock.VerifyAllExpectations();
            Assert.That(result, Is.EqualTo(fakeTypeID));
        }
예제 #13
0
        public void BeginCatchBlock()
        {
            var exceptionType        = ReflectionObjectMother.GetSomeType();
            var fakeEmittableOperand = ReflectionObjectMother.GetSomeOtherType();

            _emittableOperandProviderStub.Stub(stub => stub.GetEmittableType(exceptionType)).Return(fakeEmittableOperand);

            _innerILGeneratorMock.Expect(mock => mock.BeginCatchBlock(fakeEmittableOperand));

            _decorator.BeginCatchBlock(exceptionType);

            _innerILGeneratorMock.VerifyAllExpectations();
        }
예제 #14
0
        public void SetReturnType()
        {
            var returnType          = ReflectionObjectMother.GetSomeType();
            var emittableReturnType = ReflectionObjectMother.GetSomeOtherType();

            _operandProviderMock.Expect(mock => mock.GetEmittableType(returnType)).Return(emittableReturnType);
            _innerMock.Expect(mock => mock.SetReturnType(emittableReturnType));

            _decorator.SetReturnType(returnType);

            _operandProviderMock.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
        }
예제 #15
0
        public void SetParameters()
        {
            var parameterType          = ReflectionObjectMother.GetSomeType();
            var emittableParameterType = ReflectionObjectMother.GetSomeOtherType();

            _operandProviderMock.Expect(mock => mock.GetEmittableType(parameterType)).Return(emittableParameterType);
            _innerMock.Expect(mock => mock.SetParameters(new[] { emittableParameterType }));

            _decorator.SetParameters(new[] { parameterType });

            _operandProviderMock.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
        }
        public void SetBaseTypeConstraint()
        {
            var baseTypeConstraint          = ReflectionObjectMother.GetSomeType();
            var emittableBaseTypeConstraint = ReflectionObjectMother.GetSomeOtherType();

            _operandProvider.Setup(mock => mock.GetEmittableType(baseTypeConstraint)).Returns(emittableBaseTypeConstraint);
            _innerMock.Setup(mock => mock.SetBaseTypeConstraint(emittableBaseTypeConstraint)).Verifiable();

            _decorator.SetBaseTypeConstraint(baseTypeConstraint);

            _operandProvider.Verify();
            _innerMock.Verify();
        }
예제 #17
0
        public void GetAdditionalTypeID_NoParticpantProvidesID_ReturnsNull()
        {
            var additionalType = ReflectionObjectMother.GetSomeOtherType();

            var participantMock = MockRepository.GenerateStrictMock <IParticipant>();

            participantMock.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock.Expect(_ => _.GetAdditionalTypeID(additionalType)).Return(null);

            var typeAssembler    = CreateTypeAssembler(participants: new[] { participantMock });
            var additionalTypeID = typeAssembler.GetAdditionalTypeID(additionalType);

            Assert.That(additionalTypeID, Is.Null);
        }
예제 #18
0
        public void GetAdditionalTypeID_NoParticpantProvidesID_ReturnsNull()
        {
            var additionalType = ReflectionObjectMother.GetSomeOtherType();

            var participantMock = new Mock <IParticipant> (MockBehavior.Strict);

            participantMock.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock.Setup(_ => _.GetAdditionalTypeID(additionalType)).Returns(null).Verifiable();

            var typeAssembler    = CreateTypeAssembler(participants: new[] { participantMock.Object });
            var additionalTypeID = typeAssembler.GetAdditionalTypeID(additionalType);

            Assert.That(additionalTypeID, Is.Null);
        }
예제 #19
0
        public void SetUp()
        {
            _declaringType  = CustomTypeObjectMother.Create();
            _type           = ReflectionObjectMother.GetSomeType();
            _valueParameter = CustomParameterInfoObjectMother.Create(type: _type);
            var indexParameterType = ReflectionObjectMother.GetSomeOtherType();

            _indexParameter = CustomParameterInfoObjectMother.Create(type: indexParameterType);
            _getMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter }, returnParameter: _valueParameter);
            _setMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter, _valueParameter });

            _readOnlyProperty  = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod);
            _writeOnlyProperty = CustomPropertyInfoObjectMother.Create(setMethod: _setMethod);
        }
예제 #20
0
        public void AddInterfaceImplementation()
        {
            var interfaceType = ReflectionObjectMother.GetSomeInterfaceType();

            var emittableType = ReflectionObjectMother.GetSomeOtherType();

            _operandProvider.Expect(mock => mock.GetEmittableType(interfaceType)).Return(emittableType);
            _innerMock.Expect(mock => mock.AddInterfaceImplementation(emittableType));

            _decorator.AddInterfaceImplementation(interfaceType);

            _operandProvider.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
        }
예제 #21
0
        public void SetParent()
        {
            var baseType = ReflectionObjectMother.GetSomeSubclassableType();

            var emittableType = ReflectionObjectMother.GetSomeOtherType();

            _operandProvider.Expect(mock => mock.GetEmittableType(baseType)).Return(emittableType);
            _innerMock.Expect(mock => mock.SetParent(emittableType));

            _decorator.SetParent(baseType);

            _operandProvider.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
        }
예제 #22
0
        private MutableEventInfo CreateEvent(MutableType mutableType, MethodAttributes accessorAttributes)
        {
            var argumentType = ReflectionObjectMother.GetSomeType();
            var returnType   = ReflectionObjectMother.GetSomeOtherType();
            var handlerType  = typeof(Func <,>).MakeGenericType(argumentType, returnType);

            return(_factory.CreateEvent(
                       mutableType,
                       "dummy",
                       handlerType,
                       accessorAttributes,
                       ctx => Expression.Empty(),
                       ctx => Expression.Empty(),
                       ctx => Expression.Default(returnType)));
        }
예제 #23
0
        public void GetEmittableType_DelegateTypePlaceholder()
        {
            var mutableReturnType   = MutableTypeObjectMother.Create();
            var emittableReturnType = ReflectionObjectMother.GetSomeOtherType();

            _provider.AddMapping(mutableReturnType, emittableReturnType);
            _provider.AddMapping(_mutableType, _emittableType);
            var delegateTypePlaceholder = new DelegateTypePlaceholder(mutableReturnType, new[] { _mutableType });

            var fakeResult = ReflectionObjectMother.GetSomeDelegateType();

            _delegateProviderMock.Setup(mock => mock.GetDelegateType(mutableReturnType, new[] { _mutableType })).Returns(fakeResult).Verifiable();

            var result = _provider.GetEmittableType(delegateTypePlaceholder);

            Assert.That(result, Is.SameAs(fakeResult));
        }
예제 #24
0
        public void CreateConstructorCall_ValueType_Boxing()
        {
            var requestedType  = ReflectionObjectMother.GetSomeType();
            var delegateType   = typeof(Func <string, int, object>);
            var allowNonPublic = BooleanObjectMother.GetRandomBoolean();
            var assembledType  = ReflectionObjectMother.GetSomeOtherType();

            _constructorFinderMock
            .Expect(mock => mock.GetConstructor(requestedType, new[] { typeof(string), typeof(int) }, allowNonPublic, assembledType))
            .Return(NormalizingMemberInfoFromExpressionUtility.GetConstructor(() => new DomainValueType("", 7)));

            var result = (Func <string, int, object>)_factory.CreateConstructorCall(requestedType, assembledType, delegateType, allowNonPublic);

            var instance = (DomainValueType)result("abc", 7);

            Assert.That(instance.String, Is.EqualTo("abc"));
            Assert.That(instance.Int, Is.EqualTo(7));
        }
예제 #25
0
        public void LoadTypes_SkipsAdditionalTypesWithoutID()
        {
            var additionalGeneratedType = ReflectionObjectMother.GetSomeOtherType();

            _typeAssemblerMock.Setup(mock => mock.IsAssembledType(additionalGeneratedType)).Returns(false).Verifiable();

            object additionalTypeID = new object();

            _typeAssemblerMock.Setup(mock => mock.GetAdditionalTypeID(additionalGeneratedType)).Returns(null).Verifiable();

            _assemblyContextPoolMock.Setup(stub => stub.DequeueAll()).Returns(new[] { CreateAssemblyContext() });
            _assemblyContextPoolMock.Setup(stub => stub.Enqueue(It.IsAny <AssemblyContext>()));

            _cache.LoadTypes(new[] { additionalGeneratedType });

            Assert.That(_additionalTypes.ContainsKey(additionalTypeID), Is.False);

            _typeAssemblerMock.Verify();
        }
예제 #26
0
        public void DefineConstructor()
        {
            var parameterType     = ReflectionObjectMother.GetSomeType();
            var attributes        = (MethodAttributes)7;
            var callingConvention = (CallingConventions)7;

            var emittableParameterType = ReflectionObjectMother.GetSomeOtherType();
            var fakeConstructorBuilder = MockRepository.GenerateStub <IConstructorBuilder>();

            _operandProvider.Expect(mock => mock.GetEmittableType(parameterType)).Return(emittableParameterType);
            _innerMock.Expect(mock => mock.DefineConstructor(attributes, callingConvention, new[] { emittableParameterType })).Return(fakeConstructorBuilder);

            var result = _decorator.DefineConstructor(attributes, callingConvention, new[] { parameterType });

            _operandProvider.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
            Assert.That(result, Is.TypeOf <ConstructorBuilderDecorator>());
            Assert.That(result.As <ConstructorBuilderDecorator>().DecoratedConstructorBuilder, Is.SameAs(fakeConstructorBuilder));
        }
예제 #27
0
        public void LoadTypes_SkipsAdditionalTypesWithoutID()
        {
            var additionalGeneratedType = ReflectionObjectMother.GetSomeOtherType();

            _typeAssemblerMock.Expect(mock => mock.IsAssembledType(additionalGeneratedType)).Return(false);

            object additionalTypeID = new object();

            _typeAssemblerMock.Expect(mock => mock.GetAdditionalTypeID(additionalGeneratedType)).Return(null);

            _assemblyContextPoolMock.Stub(stub => stub.DequeueAll()).Return(new[] { CreateAssemblyContext() });
            _assemblyContextPoolMock.Stub(stub => stub.Enqueue(null)).IgnoreArguments();

            _cache.LoadTypes(new[] { additionalGeneratedType });

            Assert.That(_additionalTypes.ContainsKey(additionalTypeID), Is.False);

            _typeAssemblerMock.VerifyAllExpectations();
        }
예제 #28
0
        public void DefineField()
        {
            var name       = "field";
            var type       = ReflectionObjectMother.GetSomeType();
            var attributes = (FieldAttributes)7;

            var emittableType    = ReflectionObjectMother.GetSomeOtherType();
            var fakeFieldBuilder = MockRepository.GenerateStub <IFieldBuilder>();

            _operandProvider.Expect(mock => mock.GetEmittableType(type)).Return(emittableType);
            _innerMock.Expect(mock => mock.DefineField(name, emittableType, attributes)).Return(fakeFieldBuilder);

            var result = _decorator.DefineField(name, type, attributes);

            _operandProvider.VerifyAllExpectations();
            _innerMock.VerifyAllExpectations();
            Assert.That(result, Is.TypeOf <FieldBuilderDecorator>());
            Assert.That(result.As <FieldBuilderDecorator>().DecoratedFieldBuilder, Is.SameAs(fakeFieldBuilder));
        }
예제 #29
0
        public void DefineField()
        {
            var name       = "field";
            var type       = ReflectionObjectMother.GetSomeType();
            var attributes = (FieldAttributes)7;

            var emittableType    = ReflectionObjectMother.GetSomeOtherType();
            var fakeFieldBuilder = new Mock <IFieldBuilder>().Object;

            _operandProvider.Setup(mock => mock.GetEmittableType(type)).Returns(emittableType).Verifiable();
            _innerMock.Setup(mock => mock.DefineField(name, emittableType, attributes)).Returns(fakeFieldBuilder).Verifiable();

            var result = _decorator.DefineField(name, type, attributes);

            _operandProvider.Verify();
            _innerMock.Verify();
            Assert.That(result, Is.TypeOf <FieldBuilderDecorator>());
            Assert.That(result.As <FieldBuilderDecorator>().DecoratedFieldBuilder, Is.SameAs(fakeFieldBuilder));
        }
예제 #30
0
        public void LoadTypes_PopulatesAdditionalTypeCache()
        {
            var additionalGeneratedType = ReflectionObjectMother.GetSomeOtherType();

            _typeAssemblerMock.Setup(mock => mock.IsAssembledType(additionalGeneratedType)).Returns(false).Verifiable();

            object additionalTypeID = new object();

            _typeAssemblerMock.Setup(mock => mock.GetAdditionalTypeID(additionalGeneratedType)).Returns(additionalTypeID).Verifiable();

            _assemblyContextPoolMock.Setup(stub => stub.DequeueAll()).Returns(new[] { CreateAssemblyContext() });
            _assemblyContextPoolMock.Setup(stub => stub.Enqueue(It.IsAny <AssemblyContext>()));

            _cache.LoadTypes(new[] { additionalGeneratedType });

            Assert.That(_additionalTypes[additionalTypeID].IsValueCreated, Is.False);
            Assert.That(_additionalTypes[additionalTypeID].Value, Is.SameAs(additionalGeneratedType));

            _typeAssemblerMock.Verify();
        }