public void SetUp()
 {
     var rules = new List<IRule>();
     rules.Add(new IsEvenlyDivisible(3, "Fizz"));
     rules.Add(new IsEvenlyDivisible(5, "Buzz"));
     _fizzBuzz = new FizzBuzz(rules);
 }
        public void TestDivByZero(int lower, int higher)
        {
            try
            {
                var cases = GetNormalCases();
                //Add div by zero error
                cases.Cases.Add(new FizzBuzzCase() { Divisor = 0, Message = "Boink" });

                var fizzBuzz = new FizzBuzz(Cases);
                var result = fizzBuzz.Process(lower, higher);

            }
            catch (IndexOutOfRangeException ex )
            {
                var exType = ex.GetType();

                //The code should catch the key of 0 and fail the execution with an IndexOutOfRange.
                Assert.That(exType == typeof(IndexOutOfRangeException));
                return;
            }
            finally
            {
                TestingSetup();
            }
        }
        public void IgnoreCustomRule()
        {
            var rules = new List<IRule>();
            rules.Add(new CustomRule());
            var fizzBuzz = new FizzBuzz(rules);

            var sentence = fizzBuzz.GetSentenceFor(1787);
            sentence.Should().Be("1787");
        }
        public void ApplyCustomRule()
        {
            var rules = new List<IRule>();
            rules.Add(new CustomRule());
            var fizzBuzz = new FizzBuzz(rules);

            var sentence = fizzBuzz.GetSentenceFor(27772);
            sentence.Should().Be("Lucky");
        }
        /// <summary>
        /// The run fizz buzz.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event argument.</param>
        private void RunFizzBuzz(object sender, RoutedEventArgs e)
        {
            var fizzbuzz = new FizzBuzz();

            for (int i = 1; i <= 100; i++)
            {
                var result = fizzbuzz.GetFizzBuzzFormattedString(i);
                this.FizzBuzzListBox.Items.Add(result);
            }
        }
        public void TestFizzBuzzForSuccess(int lower, int higher)
        {
            var fizzBuzz = new FizzBuzz(Cases);
            var result = fizzBuzz.Process(lower, higher);

            var array = result.ToArray();
            Assert.That(array[0].Contains("Two") == false);
            Assert.That(array[1].Contains("Two"));
            Assert.That(array[2].Contains("Three"));
            Assert.That(array[3].Contains("Two"));
            Assert.That(array[5].Contains("Two Three Bazinga"));
        }
        public static void Main(string[] args)
        {
            var rules = new List<IRule>();
            rules.Add(new IsEvenlyDivisible(3, "Fizz"));
            rules.Add(new IsEvenlyDivisible(5, "Buzz"));
            rules.Add(new NonStandardCustomerRule());

            _fizzBuzz = new FizzBuzz(rules);
            //PrintFizzBuzzUpTo(Int32.MaxValue);
            PrintFizzBuzzUpTo(46);

            Console.ReadKey();
        }
 public void TestValidationofCall(int lower, int higher)
 {
     try
     {
         var fizzBuzz = new FizzBuzz(Cases);
         var result = fizzBuzz.Process(lower, higher);
     }
     catch(IndexOutOfRangeException )
     {
         //Expecting IndexOutOfRange....
         return;
     }
     throw new InvalidProgramException("The code should have exited by now!");
 }
 public void ValueContainsDigitTest(ValueContainsDigitTestData testData)
 {
     var fizzBuzz = new FizzBuzz();
     Assert.AreEqual(testData.ExpectedResult, fizzBuzz.ValueContainsDigit(testData.Value, testData.Digit));
 }
 public void IsValueMultipleFromDividerTest(IsValueMultipleFromDividerTestData testData)
 {
     var fizzBuzz = new FizzBuzz();
     Assert.AreEqual(testData.ExpectedResult, fizzBuzz.IsValueMultipleFromDivider(testData.Value, testData.Divider));
 }
 public void GetFizzBuzzFormattedStringTest(GetFizzBuzzFormattedStringTestData testData)
 {
     var fizzBuzz = new FizzBuzz();
     Assert.AreEqual(testData.ExpectedResult, fizzBuzz.GetFizzBuzzFormattedString(testData.Value));
 }