コード例 #1
0
        public void Should_throw_exception_when_converter_throws()
        {
            converter.Convert(Arg.Any <int>())
            .Throws(new ArgumentException(
                        "The number to be converted to a roman numeral is out of the accepted range! \r\nParameter name: input"));

            var ex = Assert.Throws <Exception>(() => service.Substitute("Some string to 123 search."));

            Assert.That(ex.InnerException.Message.Equals("The number to be converted to a roman numeral is out of the accepted range! \r\nParameter name: input"));
            Assert.That(ex.Message.Equals(@"There was an error during the substitution process.
			Please make sure that the pattern is matching integers and that the matched values are compatible with the converter.
			See inner exception for deatils"            ));
        }
コード例 #2
0
        public SubstitutionResult Substitute(string text)
        {
            var replacementCounter = 0;

            text = Regex.Replace(text, integerMatcher.Value, match =>
            {
                try
                {
                    var replacement     = converter.Convert(int.Parse(match.Value.ToString()));
                    replacementCounter += 1;
                    return(replacement);
                }
                catch (Exception e)
                {
                    var ex = new Exception(SubstitutionErrorMessage, e);
                    throw ex;
                }
            });

            return(new SubstitutionResult(text, replacementCounter));
        }
コード例 #3
0
 public string Convert(string numeral)
 {
     return(_numeralConverter.Convert(numeral));
 }
コード例 #4
0
 public void SetUp()
 {
     converter = Substitute.For <INumeralConverter <int, string> >();
     converter.Convert(Arg.Any <int>()).Returns("convertedNumeral");
     service = new IntegerSubstitutionService(IntegerMatcher.From1To3999, converter);
 }
コード例 #5
0
        public void Should_convert_arabic_to_roman_numerals_correctly(int input, string expectedOutput)
        {
            var actualOutput = converter.Convert(input);

            Assert.AreEqual(actualOutput, expectedOutput);
        }