public void SetValue_WithExceptionHandledByPropertyAccessStrategy_ThrowsBusinessObjectPropertyAccessException()
        {
            var bindablePropertyWriteAccessStrategyStub = MockRepository.GenerateStub <IBindablePropertyWriteAccessStrategy>();

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

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

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

            bindablePropertyWriteAccessStrategyStub
            .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.SetValue((IBusinessObject)instance, new SimpleReferenceType()));

            Assert.That(actualException, Is.SameAs(expectedException));
        }
        public void GetValue_NoSetter()
        {
            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.SetValue(((IBusinessObject)instance), new object());
        }
        public void SetValue_PrivateAccessor()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "PrivateProperty");
            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();

            propertyBase.SetValue((IBusinessObject)instance, value);

            Assert.That(PrivateInvoke.GetNonPublicProperty(instance, "PrivateProperty"), Is.SameAs(value));
        }
        public void SetValue_WithExceptionNotHandledByPropertyAccessStrategy_RethrowsOriginalException()
        {
            var bindablePropertyWriteAccessStrategyStub = MockRepository.GenerateStub <IBindablePropertyWriteAccessStrategy>();

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

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

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

            bindablePropertyWriteAccessStrategyStub
            .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.SetValue((IBusinessObject)instance, new SimpleReferenceType()));

            Assert.That(actualException, Is.SameAs(originalException));
#if DEBUG
            Assert.That(
                originalException.StackTrace,
                Is.StringStarting("   at Remotion.ObjectBinding.UnitTests.TestDomain.ClassWithReferenceType`1.set_ThrowingProperty(T value)"));
#endif
        }