Skip to main content

Hands on Test Driven Development Katas

In these days, Test Driven Development (TDD) is one of the most growing things in the technical world. Most of us are following Agile methodology where we would like to test our code within code.In this article, we will discuss all about TDD Katas and how we can get hands-on with

C# (10.0 MB)
 
 
 
 
 
5 Star
(1)
223 times
Add to favorites
12/24/2015
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace TDD_Katas_project.The_Natural_String_Sorting_Kata
{
    [TestFixture]
    [Category("The Natural String Kata")]
    public class NaturalStringSortingTest
    {
        #region Private Member Variables
        private NaturalStringSorting _naturalStringSorting;
        private string[] _strings;
        #endregion

        #region Setup/TearDown
        [TestFixtureSetUp]
        public void Setup()
        {
            _naturalStringSorting = new NaturalStringSorting();
            _strings = new[] { "a1", "1", "3", "2", "b1", "1a", "b3", "23", "z 21", "21 1", "z22", "0" };
        }
        [TestFixtureTearDown]
        public void TearDown()
        {
            _naturalStringSorting = null;
            _strings = null;
        }
        #endregion

        #region Test Methods

        [Test]
        public void CanSortStringDefaultOrder()
        {
            var sortString = _naturalStringSorting.SortString(_strings);
            string[] result = { "0", "1", "1a", "2", "3", "23", "21 1", "a1", "b1", "b3", "z 21", "z22" };
            Assert.That(sortString, Is.EqualTo(ToList(result)));
        }
        [Test]
        public void CanSortStringDesOrder()
        {
            var sortString = _naturalStringSorting.SortString(_strings, NaturalStringSorting.SortOrder.Descending);
            string[] result = { "z22", "z 21", "b3", "b1", "a1", "21 1", "23", "3", "2", "1a", "1", "0" };
            Assert.That(sortString, Is.EqualTo(ToList(result)));

        }
        #endregion

        #region Private Methods
        private static List<string> ToList(params string[] items)
        {
            return items.ToList();
        }

        #endregion
    }
}