예제 #1
0
        public void Given_I_Have_A_Value_Of_10_The_Unit_Converter_Should_be_called_once()
        {
            // Given I have the value 10
            int input = 10;

            // When I pass the value into the word converter
            // And I pass a mock IUnitConverter
            // And I pass a mock ITeensConverter
            // And I pass a mock ITensConverter
            // And I pass a mock IHundredConverter

            Mock <IUnitsConverter>   unitMock     = new Mock <IUnitsConverter>();
            Mock <ITeensConverter>   teensMock    = new Mock <ITeensConverter>();
            Mock <ITensConverter>    tensMocks    = new Mock <ITensConverter>();
            Mock <IHundredConverter> hundredMocks = new Mock <IHundredConverter>();

            INumberToWordConverter flow = new NumberToWordConverter
                                              (tensMocks.Object, teensMock.Object, unitMock.Object, hundredMocks.Object);

            flow.ConvertedNumberToWord(input);

            // Then verify that the unit converter is called once
            unitMock.Verify(m => m.ConvertSingleNumberToWord(It.IsAny <int>()), Times.Once);
            teensMock.Verify(m => m.ConvertTeenNumbersToWord(It.IsAny <int>()), Times.Never);
            tensMocks.Verify(m => m.ConvertTensToWords(It.IsAny <int>()), Times.Never);
            hundredMocks.Verify(m => m.ConvertValueHundredToWordHundred(), Times.Never);
        }
예제 #2
0
        private static NumberToWordConverter CreateNumberToWordConverter()
        {
            var digitExpandor = new DigitExpandor();
            var sut           = new NumberToWordConverter(digitExpandor);

            return(sut);
        }
예제 #3
0
        public void TestMethod_ConvertToWords_TwoDigit()
        {
            int    inputNumber    = 99;
            string expectedResult = "Ninety Nine Only";

            NumberToWordConverter numberToWordConverter = new NumberToWordConverter();
            string actualResult = numberToWordConverter.ConvertToWords(inputNumber);

            Assert.AreEqual(expectedResult, actualResult);
        }
예제 #4
0
 public void TwoDigitZeroes()
 {
     var converter = new NumberToWordConverter();
     Assert.Equal("twenty".Length, converter.GetNumberLengthInWords(20));
     Assert.Equal("thirty".Length, converter.GetNumberLengthInWords(30));
     Assert.Equal("forty".Length, converter.GetNumberLengthInWords(40));
     Assert.Equal("fifty".Length, converter.GetNumberLengthInWords(50));
     Assert.Equal("sixty".Length, converter.GetNumberLengthInWords(60));
     Assert.Equal("seventy".Length, converter.GetNumberLengthInWords(70));
     Assert.Equal("eighty".Length, converter.GetNumberLengthInWords(80));
     Assert.Equal("ninety".Length, converter.GetNumberLengthInWords(90));
 }
예제 #5
0
        public void TestMethod_ConvertToWords_ZeroAndOthers()
        {
            int    inputNumber1 = 0, inputNumber2 = 13456;
            string expectedOutput1 = "Zero Only";
            string expectedOutput2 = "Thirteen Thousand Four Hundred Fifty Six Only";

            NumberToWordConverter converter = new NumberToWordConverter();
            string actualOutput1            = converter.ConvertToWords(inputNumber1);
            string actualOutput2            = converter.ConvertToWords(inputNumber2);


            Assert.AreEqual(expectedOutput1, actualOutput1);
            Assert.AreEqual(expectedOutput2, actualOutput2);
        }
예제 #6
0
 public void SimpleDigitsTest()
 {
     var converter = new NumberToWordConverter();
     Assert.Equal(4, converter.GetNumberLengthInWords(0));
     Assert.Equal(3,converter.GetNumberLengthInWords(1));
     Assert.Equal(3, converter.GetNumberLengthInWords(2));
     Assert.Equal(5, converter.GetNumberLengthInWords(3));
     Assert.Equal(4, converter.GetNumberLengthInWords(4));
     Assert.Equal(4, converter.GetNumberLengthInWords(5));
     Assert.Equal(3, converter.GetNumberLengthInWords(6));
     Assert.Equal(5, converter.GetNumberLengthInWords(7));
     Assert.Equal(5, converter.GetNumberLengthInWords(8));
     Assert.Equal(4, converter.GetNumberLengthInWords(9));            
 }
예제 #7
0
 public void Tens()
 {
     var converter = new NumberToWordConverter();
     Assert.Equal("ten".Length, converter.GetNumberLengthInWords(10));
     Assert.Equal("eleven".Length, converter.GetNumberLengthInWords(11));
     Assert.Equal("twelve".Length, converter.GetNumberLengthInWords(12));
     Assert.Equal("thirteen".Length, converter.GetNumberLengthInWords(13));
     Assert.Equal("fourteen".Length, converter.GetNumberLengthInWords(14));
     Assert.Equal("fifteen".Length, converter.GetNumberLengthInWords(15));
     Assert.Equal("sixteen".Length, converter.GetNumberLengthInWords(16));
     Assert.Equal("seventeen".Length, converter.GetNumberLengthInWords(17));
     Assert.Equal("eighteen".Length, converter.GetNumberLengthInWords(18));
     Assert.Equal("nineteen".Length, converter.GetNumberLengthInWords(19));
 }
예제 #8
0
 public void LargeNumbers()
 {
     var converter = new NumberToWordConverter();
     Assert.Equal("onehundred".Length, converter.GetNumberLengthInWords(100));
     Assert.Equal("onethousand".Length, converter.GetNumberLengthInWords(1000));
 }
예제 #9
0
 public NumberToWordConverterTests()
 {
     _converter = new NumberToWordConverter();
 }