public void GetRealObject_RequestedTypeNotFound()
        {
            var data = new AssembledTypeIDData("UnknownType", new IFlatValue[0]);

            Assert.That(
                () => data.CreateTypeID(),
                Throws.InstanceOf <TypeLoadException>()
                .With.Message.StartsWith("Could not load type 'UnknownType' from assembly 'Remotion.TypePipe, "));
        }
        public void CreateTypeID()
        {
            var deserializedIdPart = new object();

            _flatValueStub.RealValue = deserializedIdPart;

            var result = _data.CreateTypeID();

            Assert.That(result.RequestedType, Is.SameAs(_type));
            Assert.That(result.Parts, Is.EqualTo(new[] { deserializedIdPart, null }));
        }
Exemple #3
0
        public void GetRealObject_RequestedTypeNotFound()
        {
            var data = new AssembledTypeIDData("UnknownType", new IFlatValue[0]);

            data.CreateTypeID();
        }
Exemple #4
0
        public void GetRealObject()
        {
            var requestedType = typeof(DomainType);
            var data          = new AssembledTypeIDData(requestedType.AssemblyQualifiedName, new IFlatValue[0]);

            _info.AddValue("<tp>participantConfigurationID", "config1");
            _info.AddValue("<tp>assembledTypeIDData", data);

            var pipelineStub          = MockRepository.GenerateStub <IPipeline>();
            var reflectionServiceStub = MockRepository.GenerateStub <IReflectionService>();

            _pipelineRegistryStub.Stub(_ => _.Get("config1")).Return(pipelineStub);
            pipelineStub.Stub(_ => _.ReflectionService).Return(reflectionServiceStub);
            reflectionServiceStub.Stub(_ => _.GetAssembledType(Arg <AssembledTypeID> .Matches(id => id.Equals(data.CreateTypeID())))).Return(requestedType);

            object instance = null;

            _createRealObjectAssertions = (inst, info, ctx, typeName) =>
            {
                Assert.That(inst, Is.TypeOf(requestedType));
                Assert.That(info, Is.SameAs(_info));
                Assert.That(ctx, Is.EqualTo(_context));
                Assert.That(typeName, Is.EqualTo(requestedType.Name));
                instance = inst;
            };

            var result = _objectDeserializationProxyBase.GetRealObject(_context);

            _pipelineRegistryStub.VerifyAllExpectations();
            _deserializationMethodInvokerMock.AssertWasCalled(_ => _.InvokeOnDeserializing(Arg <DomainType> .Is.Anything, Arg.Is(_context)));
            Assert.That(result, Is.SameAs(instance).And.Not.Null);
            Assert.That(PrivateInvoke.GetNonPublicField(_objectDeserializationProxyBase, "_instance"), Is.SameAs(instance), "Should be cached.");
        }
Exemple #5
0
        public void GetRealObject()
        {
            var requestedType = typeof(DomainType);
            var data          = new AssembledTypeIDData(requestedType.AssemblyQualifiedName, new IFlatValue[0]);

            _info.AddValue("<tp>participantConfigurationID", "config1");
            _info.AddValue("<tp>assembledTypeIDData", data);

            var pipelineStub          = new Mock <IPipeline>();
            var reflectionServiceStub = new Mock <IReflectionService>();

            _pipelineRegistryStub.Setup(_ => _.Get("config1")).Returns(pipelineStub.Object);
            pipelineStub.SetupGet(_ => _.ReflectionService).Returns(reflectionServiceStub.Object);
            reflectionServiceStub.Setup(_ => _.GetAssembledType(It.Is <AssembledTypeID> (id => id.Equals(data.CreateTypeID())))).Returns(requestedType);

            object instance = null;

            _createRealObjectAssertions = (inst, info, ctx, typeName) =>
            {
                Assert.That(inst, Is.TypeOf(requestedType));
                Assert.That(info, Is.SameAs(_info));
                Assert.That(ctx, Is.EqualTo(_context));
                Assert.That(typeName, Is.EqualTo(requestedType.Name));
                instance = inst;
            };

            var result = _objectDeserializationProxyBase.GetRealObject(_context);

            _pipelineRegistryStub.Verify();
            _deserializationMethodInvokerMock.Verify(_ => _.InvokeOnDeserializing(It.IsAny <DomainType>(), It.Is <StreamingContext> (param => param.Equals(_context))), Times.Once());
            Assert.That(result, Is.SameAs(instance).And.Not.Null);
            Assert.That(PrivateInvoke.GetNonPublicField(_objectDeserializationProxyBase, "_instance"), Is.SameAs(instance), "Should be cached.");
        }