Question test cases for the function”Validate”

Marcel Ionut

New member
Joined
Apr 17, 2023
Messages
1
Programming Experience
Beginner
Hello. I am a beginner in C sharp and I have job assignment to evaluate and create test cases for the function”Validate”. The function takes as input the order date (firstDay) and the manual calculated delivery date from the agent (lastDay) and a list of holidays. The function returns the no of business days between these two dates. If this is different to 4 the sales agent knows that he has incorrectly calculated the delivery date and can recalculate a new delivery date and test this again.
How to start working on this? Any hints or test flows similar to my use case are very welcome. Thank you!


C#:
public static bool Validate(DateTime firstDay, DateTime lastDay, IList<DateTime> bankHolidays){
 string sectionName = string.Empty;
 string keyName = string.Empty;
 string keyValue = string.Empty;
 string strFullIniFile = string.Empty;
       sectionName = "OrderManager";
       keyName = "LogPath";
       keyValue = "";
       strFullIniFile = AppDomain.CurrentDomain.BaseDirectory+"\\OrderManager.ini";
                WINAPI32.API_VBGetPrivateProfileString(ref sectionName, ref keyName, ref keyValue, ref strFullIniFile); 
                LOGFILE.LGF_WriteLog(keyValue, "The Order date is" + firstDay +"and the delivery date is"  + lastDay, LOGFILE.INFO_INDICATOR); 

if (GetBusinessdays(firstDay, lastDay, listBankHolidays) != 4){
    sectionName = "OrderManager";
    keyName = "LogPath";
    keyValue = "";
    strFullIniFile = AppDomain.CurrentDomain.BaseDirectory+"\\OrderManager.ini";
                    WINAPI32.API_VBGetPrivateProfileString(ref sectionName, ref keyName, ref keyValue, ref strFullIniFile);                   LOGFILE.LGF_WriteLog(keyValue, "The Order date is" + firstDay +"and the delivery date is" + lastDay + "are not 4", LOGFILE.INFO_INDICATOR); 
        return false;
}else{
    sectionName = "OrderManager";
    keyName = "LogPath";
    keyValue = "";
    strFullIniFile = AppDomain.CurrentDomain.BaseDirectory+"\\OrderManager.ini";
                WINAPI32.API_VBGetPrivateProfileString(ref sectionName, ref keyName, ref keyValue, ref strFullIniFile);                 LOGFILE.LGF_WriteLog(keyValue, "The Order date is" + firstDay +"and the delivery date is"+ lastDay + "are OK", LOGFILE.INFO_INDICATOR);
       return true;
   }
}
bankHolidays)

public static int GetBusinessdays(DateTime firstDay, DateTime lastDay, IList<DateTime> {
    firstDay = firstDay.Date;
    lastDay = lastDay.Date;
    if (firstDay > lastDay)
    {
        throw new ArgumentException("Incorrect last day " + lastDay);
    }
TimeSpan span = lastDay - firstDay;
int businessDays = span.Days + 1;
int fullWeekCount = businessDays / 7;
// find out if there are weekends during the time exceedng the full weeks if (businessDays > fullWeekCount * 7)
{
//The following method is a part of the Validation
// we are here to find out if there is a 1-day or 2-days weekend
// in the time interval remaining after subtracting the complete weeks
int firstDayOfWeek = firstDay.DayOfWeek == DayOfWeek.Sunday ? 7 : 48 (int)firstDay.DayOfWeek;

    int lastDayOfWeek = lastDay.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)lastDay.DayOfWeek;
    if (lastDayOfWeek < firstDayOfWeek)
    {
        lastDayOfWeek += 7;
    }
    if (firstDayOfWeek <= 6)
    {
        if (lastDayOfWeek >= 7)
        {
            // Both Saturday and Sunday are in the remaining time interval
            businessDays -= 2;
        }
        else if (lastDayOfWeek >= 6)
        {
// Only Saturday is in the remaining time interval
            businessDays -= 1;
        }
    }
    else if (firstDayOfWeek <= 7 && lastDayOfWeek >= 7)
    {
        // Only Sunday is in the remaining time interval
        businessDays -= 1;
    }
}
// subtract the weekends during the full weeks in the interval
businessDays -= fullWeekCount + fullWeekCount;
// subtract the number of bank holidays during the time interval
foreach (DateTime bankHoliday in bankHolidays)
{
DateTime bh = bankHoliday.Date;
if (firstDay <= bh && bh <= lastDay) {
            --businessDays;
        }
}
    return businessDays;
}
 
Last edited by a moderator:
Solution
Test the happy path first: Good known dates.

Next test the edge cases. What happens when DateTime.MinValue and DateTime.MaxValue are passed in? Or when the list is empty, or the list has Int32.Max items in it?

Next test the odd cases like when when the startDay is after the lastDay[licode], or when none of the bank holidays fall between the startDay and lastDay. Also test when [icode]lastDay = startDay.AddSeconds(1).

Next test the various start days and end days the straddle a weekend, or begin or end in a weekend.

Next test the various start days and end days that straddle a bank holiday, or begin or end on a bank holiday.

Next test leap years.

Next test start days and end days that don't start and end at midnight.

And then...
Test the happy path first: Good known dates.

Next test the edge cases. What happens when DateTime.MinValue and DateTime.MaxValue are passed in? Or when the list is empty, or the list has Int32.Max items in it?

Next test the odd cases like when when the startDay is after the lastDay[licode], or when none of the bank holidays fall between the startDay and lastDay. Also test when [icode]lastDay = startDay.AddSeconds(1).

Next test the various start days and end days the straddle a weekend, or begin or end in a weekend.

Next test the various start days and end days that straddle a bank holiday, or begin or end on a bank holiday.

Next test leap years.

Next test start days and end days that don't start and end at midnight.

And then since you are doing whitebox testing, you can see that the code accesses some files. What happens when those files do not exist, are readonly, or are locked by another process? What happens when the contents of those files are corrupt?
 
Solution
Back
Top Bottom