public IntranetExceptionBase Build()
        {
            ErrorCodeAttribute errorCodeAttribute = GetErrorCodeAttribute(_errorCode);

            string message = _argumentCollection == null
                ? errorCodeAttribute.Message
                : string.Format(errorCodeAttribute.Message, _argumentCollection.ToArray());

            IntranetExceptionBase intranetException = _innerException == null
                ? Build(errorCodeAttribute.ExceptionType, _errorCode, message)
                : Build(errorCodeAttribute.ExceptionType, _errorCode, message, _innerException);

            if (_methodBase != null)
            {
                AddMethodBase(intranetException, _methodBase);
            }

            if (_validatingType != null)
            {
                AddValidatingType(intranetException, _validatingType);
            }

            if (string.IsNullOrWhiteSpace(_validatingField))
            {
                return(intranetException);
            }

            AddValidatingField(intranetException, _validatingField);

            return(intranetException);
        }
コード例 #2
0
        public void Build_WhenCalledForIntranetQueryBusException_ReturnsIntranetQueryBusException()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.NoQueryHandlerSupportingQuery, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result, Is.TypeOf <IntranetQueryBusException>());
        }
コード例 #3
0
        public void Build_WhenCalledForIntranetRepositoryException_ReturnsIntranetRepositoryException()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.RepositoryError, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result, Is.TypeOf <IntranetRepositoryException>());
        }
コード例 #4
0
        public void Build_WhenCalledForIntranetValidationException_ReturnsIntranetValidationException()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ValueNotGreaterThanZero, _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result, Is.TypeOf <IntranetValidationException>());
        }
コード例 #5
0
        public void Build_WhenCalledForIntranetSystemException_ReturnsIntranetSystemException()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ObjectIsNull, _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result, Is.TypeOf <IntranetSystemException>());
        }
コード例 #6
0
        public void Build_WhenCalledForIntranetValidationExceptionWithoutInnerException_AssertInnerExceptionIsNull()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ValueNotGreaterThanZero, _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.InnerException, Is.Null);
        }
コード例 #7
0
        public void Build_WhenCalledForIntranetRepositoryExceptionWithoutInnerException_AssertInnerExceptionIsNull()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.RepositoryError, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.InnerException, Is.Null);
        }
コード例 #8
0
        public void Build_WhenCalledForIntranetQueryBusExceptionWithoutInnerException_AssertInnerExceptionIsNull()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.NoQueryHandlerSupportingQuery, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.InnerException, Is.Null);
        }
コード例 #9
0
        public void Build_WhenCalledForIntranetQueryBusExceptionWithInnerException_AssertInnerExceptionIsCorrect()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.NoQueryHandlerSupportingQuery, _fixture.Create <string>(), _fixture.Create <string>());

            Exception             innerException = _fixture.Create <Exception>();
            IntranetExceptionBase result         = sut.WithInnerException(innerException).Build();

            Assert.That(result.InnerException, Is.EqualTo(innerException));
        }
コード例 #10
0
        public void Build_WhenCalledForIntranetRepositoryExceptionWithInnerException_AssertInnerExceptionIsCorrect()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.RepositoryError, _fixture.Create <string>(), _fixture.Create <string>());

            Exception             innerException = _fixture.Create <Exception>();
            IntranetExceptionBase result         = sut.WithInnerException(innerException).Build();

            Assert.That(result.InnerException, Is.EqualTo(innerException));
        }
コード例 #11
0
        public void Build_WhenCalledForIntranetValidationExceptionWithInnerException_AssertInnerExceptionIsCorrect()
        {
            IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ValueNotGreaterThanZero, _fixture.Create <string>());

            Exception             innerException = _fixture.Create <Exception>();
            IntranetExceptionBase result         = sut.WithInnerException(innerException).Build();

            Assert.That(result.InnerException, Is.EqualTo(innerException));
        }
コード例 #12
0
        public void Build_WhenCalledForIntranetRepositoryException_AssertErrorCodeIsCorrect()
        {
            const ErrorCode errorCode = ErrorCode.RepositoryError;

            IIntranetExceptionBuilder sut = CreateSut(errorCode, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.ErrorCode, Is.EqualTo(errorCode));
        }
コード例 #13
0
        public void Build_WhenCalledForIntranetValidationException_AssertErrorCodeIsCorrect()
        {
            const ErrorCode errorCode = ErrorCode.ValueNotGreaterThanZero;

            IIntranetExceptionBuilder sut = CreateSut(errorCode, _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.ErrorCode, Is.EqualTo(errorCode));
        }
コード例 #14
0
        public void Build_WhenCalledForIntranetQueryBusException_AssertErrorCodeIsCorrect()
        {
            const ErrorCode errorCode = ErrorCode.NoQueryHandlerSupportingQuery;

            IIntranetExceptionBuilder sut = CreateSut(errorCode, _fixture.Create <string>(), _fixture.Create <string>());

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.ErrorCode, Is.EqualTo(errorCode));
        }
コード例 #15
0
        public void Build_WhenCalledForIntranetValidationException_AssertMessageIsCorrect()
        {
            const ErrorCode errorCode       = ErrorCode.ValueNotGreaterThanZero;
            string          validatingField = _fixture.Create <string>();

            ErrorCodeAttribute errorCodeAttribute = _errorCodeAttributeTestHelper.GetErrorCodeAttribute(errorCode);

            IIntranetExceptionBuilder sut = CreateSut(errorCode, validatingField);

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.Message, Is.EqualTo(string.Format(errorCodeAttribute.Message, validatingField)));
        }
コード例 #16
0
        public void Build_WhenCalledForIntranetSystemException_AssertMessageIsCorrect()
        {
            const ErrorCode errorCode       = ErrorCode.ObjectIsNull;
            string          commandTypeName = _fixture.Create <string>();

            ErrorCodeAttribute errorCodeAttribute = _errorCodeAttributeTestHelper.GetErrorCodeAttribute(errorCode);

            IIntranetExceptionBuilder sut = CreateSut(errorCode, commandTypeName);

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.Message, Is.EqualTo(string.Format(errorCodeAttribute.Message, commandTypeName)));
        }
コード例 #17
0
        public void Build_WhenCalledForIntranetCommandBusException_AssertMessageIsCorrect()
        {
            const ErrorCode errorCode       = ErrorCode.NoCommandHandlerSupportingCommandWithoutResultType;
            string          commandTypeName = _fixture.Create <string>();

            ErrorCodeAttribute errorCodeAttribute = _errorCodeAttributeTestHelper.GetErrorCodeAttribute(errorCode);

            IIntranetExceptionBuilder sut = CreateSut(errorCode, commandTypeName);

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.Message, Is.EqualTo(string.Format(errorCodeAttribute.Message, commandTypeName)));
        }
        private static void AddMethodBase(IntranetExceptionBase intranetException, MethodBase methodBase)
        {
            NullGuard.NotNull(intranetException, nameof(intranetException))
            .NotNull(methodBase, nameof(methodBase));

            IntranetRepositoryException intranetRepositoryException = intranetException as IntranetRepositoryException;

            if (intranetRepositoryException == null)
            {
                return;
            }

            intranetRepositoryException.MethodBase = methodBase;
        }
        private static void AddValidatingField(IntranetExceptionBase intranetException, string validatingField)
        {
            NullGuard.NotNull(intranetException, nameof(intranetException))
            .NotNullOrWhiteSpace(validatingField, nameof(validatingField));

            IntranetValidationException intranetValidationException = intranetException as IntranetValidationException;

            if (intranetValidationException == null)
            {
                return;
            }

            intranetValidationException.ValidatingField = validatingField;
        }
コード例 #20
0
        public void Build_WhenCalledForIntranetRepositoryException_AssertMessageIsCorrect()
        {
            const ErrorCode errorCode  = ErrorCode.RepositoryError;
            string          methodName = _fixture.Create <string>();
            string          error      = _fixture.Create <string>();

            ErrorCodeAttribute errorCodeAttribute = _errorCodeAttributeTestHelper.GetErrorCodeAttribute(errorCode);

            IIntranetExceptionBuilder sut = CreateSut(errorCode, methodName, error);

            IntranetExceptionBase result = sut.Build();

            Assert.That(result.Message, Is.EqualTo(string.Format(errorCodeAttribute.Message, methodName, error)));
        }
        private static void AddValidatingType(IntranetExceptionBase intranetException, Type validatingType)
        {
            NullGuard.NotNull(intranetException, nameof(intranetException))
            .NotNull(validatingType, nameof(validatingType));

            IntranetValidationException intranetValidationException = intranetException as IntranetValidationException;

            if (intranetValidationException == null)
            {
                return;
            }

            intranetValidationException.ValidatingType = validatingType;
        }
コード例 #22
0
        protected Exception Handle(AggregateException aggregateException, Func <Exception, IIntranetExceptionBuilder> intranetExceptionBuilder)
        {
            NullGuard.NotNull(aggregateException, nameof(aggregateException))
            .NotNull(intranetExceptionBuilder, nameof(intranetExceptionBuilder));

            Exception innerException = null;

            aggregateException.Handle(exception =>
            {
                innerException = exception;
                return(true);
            });

            IntranetExceptionBase intranetException = innerException as IntranetExceptionBase;

            return(intranetException ?? intranetExceptionBuilder(innerException).Build());
        }