public void GetValue()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "Scalar");
            PropertyBase         propertyBase = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    isRequired: true,
                    isReadOnly: true));

            var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty);

            var value = new SimpleReferenceType();

            instance.Scalar = value;

            Assert.That(propertyBase.GetValue(((IBusinessObject)instance)), Is.SameAs(value));
        }
        public void GetValue_NoGetter()
        {
            var propertyInfo = MockRepository.GenerateStub <IPropertyInformation>();

            propertyInfo.Stub(stub => stub.PropertyType).Return(typeof(bool));
            propertyInfo.Stub(stub => stub.GetIndexParameters()).Return(new ParameterInfo[0]);
            propertyInfo.Stub(stub => stub.GetSetMethod(true)).Return(null);
            PropertyBase propertyBase = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    isRequired: true,
                    isReadOnly: true));

            var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty);

            propertyBase.GetValue(((IBusinessObject)instance));
        }
        public void GetValue_WithExceptionNotHandledByPropertyAccessStrategy_RethrowsOriginalException()
        {
            var bindablePropertyReadAccessStrategyStub = MockRepository.GenerateStub <IBindablePropertyReadAccessStrategy>();

            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ThrowingProperty");
            PropertyBase         propertyBase = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    bindablePropertyReadAccessStrategy: bindablePropertyReadAccessStrategyStub));

            var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty);

            var originalException = new Exception("The Exception");

            bindablePropertyReadAccessStrategyStub
            .Stub(
                mock => mock.IsPropertyAccessException(
                    Arg.Is((IBusinessObject)instance),
                    Arg.Is(propertyBase),
                    Arg.Is(originalException),
                    out Arg <BusinessObjectPropertyAccessException> .Out(new BusinessObjectPropertyAccessException("Unexpected", null)).Dummy))
            .Return(false);

            instance.PrepareException(originalException);

            var actualException = Assert.Throws <Exception> (() => propertyBase.GetValue(((IBusinessObject)instance)));

            Assert.That(actualException, Is.SameAs(originalException));
#if DEBUG
            Assert.That(
                originalException.StackTrace,
                Is.StringStarting("   at Remotion.ObjectBinding.UnitTests.TestDomain.ClassWithReferenceType`1.get_ThrowingProperty()"));
#endif
        }
        public void GetValue_WithExceptionHandledByPropertyAccessStrategy_ThrowsBusinessObjectPropertyAccessException()
        {
            var bindablePropertyReadAccessStrategyStub = MockRepository.GenerateStub <IBindablePropertyReadAccessStrategy>();

            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ThrowingProperty");
            PropertyBase         propertyBase = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    bindablePropertyReadAccessStrategy: bindablePropertyReadAccessStrategyStub));

            var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty);

            var originalException = new Exception("The Exception");
            var expectedException = new BusinessObjectPropertyAccessException("The Message", null);

            bindablePropertyReadAccessStrategyStub
            .Stub(
                mock => mock.IsPropertyAccessException(
                    Arg.Is((IBusinessObject)instance),
                    Arg.Is(propertyBase),
                    Arg.Is(originalException),
                    out Arg <BusinessObjectPropertyAccessException> .Out(expectedException).Dummy))
            .Return(true);

            instance.PrepareException(originalException);

            var actualException = Assert.Throws <BusinessObjectPropertyAccessException> (() => propertyBase.GetValue(((IBusinessObject)instance)));

            Assert.That(actualException, Is.SameAs(expectedException));
        }