コード例 #1
0
        public bool IsPropertyAccessException(
            IBusinessObject businessObject,
            PropertyBase bindableProperty,
            Exception exception,
            out BusinessObjectPropertyAccessException propertyAccessException)
        {
            ArgumentUtility.DebugCheckNotNull("businessObject", businessObject);
            ArgumentUtility.DebugCheckNotNull("bindableProperty", bindableProperty);
            ArgumentUtility.DebugCheckNotNull("exception", exception);

            var isPropertyAccessException = exception is ObjectInvalidException ||
                                            exception is ObjectDeletedException ||
                                            exception is ObjectsNotFoundException;

            if (isPropertyAccessException && businessObject is DomainObject)
            {
                ArgumentUtility.CheckNotNull("bindableProperty", bindableProperty);

                var message = string.Format(
                    "An {0} occured while getting the value of property '{1}' for business object with ID '{2}'.",
                    exception.GetType().Name,
                    bindableProperty.Identifier,
                    ((DomainObject)businessObject).ID);
                propertyAccessException = new BusinessObjectPropertyAccessException(message, exception);
                return(true);
            }
            propertyAccessException = null;
            return(false);
        }
コード例 #2
0
        public bool IsPropertyAccessException(
            IBusinessObject businessObject,
            PropertyBase bindableProperty,
            Exception exception,
            out BusinessObjectPropertyAccessException propertyAccessException)
        {
            ArgumentUtility.DebugCheckNotNull("businessObject", businessObject);
            ArgumentUtility.DebugCheckNotNull("bindableProperty", bindableProperty);
            ArgumentUtility.DebugCheckNotNull("exception", exception);

            if (exception is PermissionDeniedException)
            {
                ArgumentUtility.CheckNotNull("businessObject", businessObject);
                ArgumentUtility.CheckNotNull("bindableProperty", bindableProperty);

                var classOrInstance = businessObject is IBusinessObjectWithIdentity
            ? string.Format("for business object with ID '{0}'", ((IBusinessObjectWithIdentity)businessObject).UniqueIdentifier)
            : string.Format("for business object type '{0}'", businessObject.BusinessObjectClass.Identifier);

                var message = string.Format(
                    "A PermissionDeniedException occured while getting the value of property '{0}' {1}.",
                    bindableProperty.Identifier,
                    classOrInstance);

                propertyAccessException = new BusinessObjectPropertyAccessException(message, exception);
                return(true);
            }

            propertyAccessException = null;
            return(false);
        }
コード例 #3
0
        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 Initialize()
        {
            Exception expectedException = new Exception("The Exception");
            var       exception         = new BusinessObjectPropertyAccessException("The Message", expectedException);

            Assert.That(exception.Message, Is.EqualTo("The Message"));
            Assert.That(exception.InnerException, Is.SameAs(expectedException));
        }
        public void Serialization()
        {
            Exception expectedException = new Exception("The Exception");
            var       exception         = new BusinessObjectPropertyAccessException("The Message", expectedException);

            var deserialized = Serializer.SerializeAndDeserialize(exception);

            Assert.That(deserialized.Message, Is.EqualTo("The Message"));
            Assert.That(deserialized.InnerException, Is.Not.Null);
            Assert.That(deserialized.InnerException.Message, Is.EqualTo("The Exception"));
        }
        public void IsPropertyAccessException_WithOneStrategyReturningTrue_ReturnsTrue_SetsResultValue_AndAbortsChecks()
        {
            var exception         = new Exception();
            var expectedException = new BusinessObjectPropertyAccessException("The Message", null);

            using (_mockRepository.Ordered())
            {
                _innerStrategy1
                .Expect(
                    mock => mock.IsPropertyAccessException(
                        Arg.Is(_businessObject),
                        Arg.Is(_property),
                        Arg.Is(exception),
                        out Arg <BusinessObjectPropertyAccessException> .Out(null).Dummy))
                .Return(false);
                _innerStrategy2
                .Expect(
                    mock => mock.IsPropertyAccessException(
                        Arg.Is(_businessObject),
                        Arg.Is(_property),
                        Arg.Is(exception),
                        out Arg <BusinessObjectPropertyAccessException> .Out(expectedException).Dummy))
                .Return(true);
                _innerStrategy3.Expect(
                    mock => mock.IsPropertyAccessException(
                        Arg.Is(_businessObject),
                        Arg.Is(_property),
                        Arg.Is(exception),
                        out Arg <BusinessObjectPropertyAccessException> .Out(null).Dummy))
                .Repeat.Never();
            }
            _mockRepository.ReplayAll();

            BusinessObjectPropertyAccessException actualException;
            var result = _strategy.IsPropertyAccessException(_businessObject, _property, exception, out actualException);

            Assert.That(result, Is.True);
            Assert.That(actualException, Is.SameAs(expectedException));

            _mockRepository.VerifyAll();
        }
コード例 #7
0
        public bool IsPropertyAccessException(
            IBusinessObject businessObject,
            PropertyBase bindableProperty,
            Exception exception,
            out BusinessObjectPropertyAccessException propertyAccessException)
        {
            ArgumentUtility.DebugCheckNotNull("businessObject", businessObject);
            ArgumentUtility.DebugCheckNotNull("bindableProperty", bindableProperty);
            ArgumentUtility.DebugCheckNotNull("exception", exception);

            // This section does represent an inherrent hot-path but the for-loop is chosen for symmetry with the CanRead()-method.
            // ReSharper disable once ForCanBeConvertedToForeach
            for (int i = 0; i < _bindablePropertyReadAccessStrategies.Length; i++)
            {
                var bindablePropertyReadAccessStrategy = _bindablePropertyReadAccessStrategies[i];
                if (bindablePropertyReadAccessStrategy.IsPropertyAccessException(businessObject, bindableProperty, exception, out propertyAccessException))
                {
                    return(true);
                }
            }
            propertyAccessException = null;
            return(false);
        }