static void

UK Bank Holidays Tests

NUnit tests for UK Bank Holiday class

using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace PublicHoliday
{
    
/// <summary>
    /// Test the UK Bank Holidays
    /// </summary>
    [TestFixture]
    
public class TestUKBankHoliday
    {

        
/// <summary>
        /// Test Easter
        /// </summary>
        [Test]
        
public void TestEasterMonday()
        {
            
DateTime expected = new DateTime(2006, 4, 17);
            
DateTime actual = UKBankHoliday.EasterMonday(2006);
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Test Spring with Golden Jubilee variation
        /// </summary>
        [Test]
        
public void TestSpring()
        {
            
DateTime expected = new DateTime(2002, 6, 4);
            
DateTime actual = UKBankHoliday.Spring(2002);
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Test May Day
        /// </summary>
        [Test]
        
public void TestMayDayPre78()
        {
            
DateTime? actual = UKBankHoliday.MayDay(1977);
            Assert.IsNull(actual);
        }

        
/// <summary>
        /// Test May Day (on Monday)
        /// </summary>
        [Test]
        
public void TestMayDayPost78()
        {
            
DateTime expected = new DateTime(1978, 5, 1);
            
DateTime? actual = UKBankHoliday.MayDay(1978);
            Assert.AreEqual(expected, actual.Value);
        }

        
/// <summary>
        /// Test May Day (on Tuesday)
        /// </summary>
        [Test]
        
public void TestMayDay79()
        {
            
DateTime expected = new DateTime(1979, 5, 7);
            
DateTime? actual = UKBankHoliday.MayDay(1979);
            Assert.AreEqual(expected, actual.Value);
        }

        
/// <summary>
        /// New Year is a Sunday, so bank holiday is Monday
        /// </summary>
        [Test]
        
public void TestWeekendNotHoliday()
        {
            Assert.IsFalse(
UKBankHoliday.IsBankHoliday(new DateTime(2006, 1, 1)));
        }

        
/// <summary>
        /// New Year is a Sunday, so bank holiday is Monday
        /// </summary>
        [Test]
        
public void TestHolidayInLieu()
        {
            Assert.IsTrue(
UKBankHoliday.IsBankHoliday(new DateTime(2006, 1, 2)));
        }

        
/// <summary>
        /// New Year is a Sunday, so bank holiday is Monday and day after is normal day
        /// </summary>
        [Test]
        
public void TestAfterHolidayInLieu()
        {
            Assert.IsFalse(
UKBankHoliday.IsBankHoliday(new DateTime(2006, 1, 3)));
        }

        
/// <summary>
        /// Sat, no hols
        /// </summary>
        [Test]
        
public void TestNextWorkingDaySat()
        {
            
DateTime expected = new DateTime(2006, 12, 18);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 16));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Sun before bhol
        /// </summary>
        [Test]
        
public void TestNextWorkingDaySunday()
        {
            
DateTime expected = new DateTime(2006, 12, 27);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 24));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// bhol with another following
        /// </summary>
        [Test]
        
public void TestNextWorkingDayXmas()
        {
            
DateTime expected = new DateTime(2006, 12, 27);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 25));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Boxing Day
        /// </summary>
        [Test]
        
public void TestNextWorkingDayBoxingDay()
        {
            
DateTime expected = new DateTime(2006, 12, 27);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 26));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Working Day after Holiday
        /// </summary>
        [Test]
        
public void TestNextWorkingDayAfterHoliday()
        {
            
DateTime expected = new DateTime(2006, 12, 27);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 27));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// Sat before bhol
        /// </summary>
        [Test]
        
public void TestNextWorkingDayOverNewYear()
        {
            
DateTime expected = new DateTime(2007, 1, 2);
            
DateTime actual = UKBankHoliday.NextWorkingDay(new DateTime(2006, 12, 30));
            Assert.AreEqual(expected, actual);
        }

        
/// <summary>
        /// There are 8 bank holidays
        /// </summary>
        [Test]
        
public void TestHolidayCount()
        {
            
List<DateTime> BankHolidays = UKBankHoliday.BankHolidays(2006);
            Assert.AreEqual(BankHolidays.Count, 8);
        }

        
/// <summary>
        /// There are 9 bank holidays in 2002
        /// </summary>
        [Test]
        
public void TestHolidayCount2002()
        {
            
List<DateTime> BankHolidays = UKBankHoliday.BankHolidays(2002);
            Assert.AreEqual(BankHolidays.Count, 9);
        }

        
/// <summary>
        /// There are 7 bank holidays in 1977
        /// </summary>
        [Test]
        
public void TestHolidayCount1977()
        {
            
List<DateTime> BankHolidays = UKBankHoliday.BankHolidays(1977);
            Assert.AreEqual(BankHolidays.Count, 7);
        }
    }
}