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); }
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>()); }
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>()); }
public void Build_WhenCalledForIntranetValidationException_ReturnsIntranetValidationException() { IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ValueNotGreaterThanZero, _fixture.Create <string>()); IntranetExceptionBase result = sut.Build(); Assert.That(result, Is.TypeOf <IntranetValidationException>()); }
public void Build_WhenCalledForIntranetSystemException_ReturnsIntranetSystemException() { IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ObjectIsNull, _fixture.Create <string>()); IntranetExceptionBase result = sut.Build(); Assert.That(result, Is.TypeOf <IntranetSystemException>()); }
public void Build_WhenCalledForIntranetValidationExceptionWithoutInnerException_AssertInnerExceptionIsNull() { IIntranetExceptionBuilder sut = CreateSut(ErrorCode.ValueNotGreaterThanZero, _fixture.Create <string>()); IntranetExceptionBase result = sut.Build(); Assert.That(result.InnerException, Is.Null); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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))); }
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))); }
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; }
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; }
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()); }