示例#1
0
        public void FormatException_when_exceptionType_not_found_uses_baseType_Layout()
        {
            // Arrange
            var formatter = ExceptionFormatter.Create()
                            .AddExceptionLayout(new CustomerExceptionLayout());

            // Act
            var subClassException = new CustomerNotFoundException();
            var actual            = formatter.FormatException(subClassException);

            // Assert
            actual.Should().MatchEquivalentOf("CustomerExceptionLayout*");
        }
示例#2
0
    public static Customer EditCustomer(int Id)
    {
        // Pretend we look for the customer in our database
        // We can't find it, so we notify our caller in a way in
        // which they can't ignore us.
        string strMsg;

        strMsg = string.Format("The customer you requested by Id {0} could not be found.", Id);
        // Create the exception.
        CustomerNotFoundException exp = new CustomerNotFoundException(strMsg);

        // throw it to our caller
        throw exp;
    }
示例#3
0
        public void ShouldLocalizeException()
        {
            // Arrange
            var exception = new CustomerNotFoundException {
                CustomerId = "TestCustomerId"
            };

            // Act
            var textEn = exception.GetLocalizedErrorCode("en");
            var textDe = exception.GetLocalizedErrorCode("de");

            // Assert
            Assert.False(string.IsNullOrEmpty(textEn));
            Assert.False(string.IsNullOrEmpty(textDe));
        }