Skip to content

Commit

Permalink
Removed OnTheFirst/Second/Third/Fourth functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorCioletti authored and tallesl committed May 5, 2020
1 parent dd9104d commit 834e0a1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,5 @@ public void On()
// Assert
Assert.AreEqual(expectedDay, calculated.Value.Day);
}

[TestMethod]
public void OnTheFirstDay()
{
// Arrange
var fluentCalculator = new FluentTimeCalculator();
var calculator = (ITimeCalculator)fluentCalculator;
var run = new RunSpecifier(fluentCalculator);

var now = new DateTime(2017, 10, 27);
var expectedDate = new DateTime(2017, 11, 3);

// Act
run.Every(1).Months().OnTheFirstDay(DayOfWeek.Friday);
var calculated = calculator.Calculate(now);

// Assert
Assert.AreEqual(DayOfWeek.Friday, calculated.Value.DayOfWeek);
Assert.AreEqual(expectedDate, calculated.Value.Date);
}

[TestMethod]
public void OnTheSecondDay()
{
// Arrange
var fluentCalculator = new FluentTimeCalculator();
var calculator = (ITimeCalculator)fluentCalculator;
var run = new RunSpecifier(fluentCalculator);

var now = new DateTime(2017, 10, 27);
var expectedDate = new DateTime(2017, 11, 10);

// Act
run.Every(1).Months().OnTheSecondDay(DayOfWeek.Friday);
var calculated = calculator.Calculate(now);

// Assert
Assert.AreEqual(DayOfWeek.Friday, calculated.Value.DayOfWeek);
Assert.AreEqual(expectedDate, calculated.Value.Date);
}

[TestMethod]
public void OnTheThirdDay()
{
// Arrange
var fluentCalculator = new FluentTimeCalculator();
var calculator = (ITimeCalculator)fluentCalculator;
var run = new RunSpecifier(fluentCalculator);

var now = new DateTime(2017, 10, 27);
var expectedDate = new DateTime(2017, 11, 17);

// Act
run.Every(1).Months().OnTheThirdDay(DayOfWeek.Friday);
var calculated = calculator.Calculate(now);

// Assert
Assert.AreEqual(DayOfWeek.Friday, calculated.Value.DayOfWeek);
Assert.AreEqual(expectedDate, calculated.Value.Date);
}

[TestMethod]
public void OnTheFourthDay()
{
// Arrange
var fluentCalculator = new FluentTimeCalculator();
var calculator = (ITimeCalculator)fluentCalculator;
var run = new RunSpecifier(fluentCalculator);

var now = new DateTime(2017, 10, 27);
var expectedDate = new DateTime(2017, 11, 24);

// Act
run.Every(1).Months().OnTheFourthDay(DayOfWeek.Friday);
var calculated = calculator.Calculate(now);

// Assert
Assert.AreEqual(DayOfWeek.Friday, calculated.Value.DayOfWeek);
Assert.AreEqual(expectedDate, calculated.Value.Date);
}
}
}
}
46 changes: 0 additions & 46 deletions FluentScheduler/Fluent/3 - Duration/Month/MonthUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,5 @@ public RestrictionUnit On(int day)

return new RestrictionUnit(_calculator);
}

/// <summary>
/// Runs the job on the given day of week on the first week of the month.
/// </summary>
/// <param name="day">The day of the week</param>
public RestrictionUnit OnTheFirstDay(DayOfWeek day)
{
_calculator.PeriodCalculations.Add(last => SelectNthDay(last.Date.Year, last.Date.Month, day, 1));
return new RestrictionUnit(_calculator);
}

/// <summary>
/// Runs the job on the given day of week on the second week of the month.
/// </summary>
/// <param name="day">The day of the week</param>
public RestrictionUnit OnTheSecondDay(DayOfWeek day)
{
_calculator.PeriodCalculations.Add(last => SelectNthDay(last.Date.Year, last.Date.Month, day, 2));
return new RestrictionUnit(_calculator);
}

/// <summary>
/// Runs the job on the given day of week on the third week of the month.
/// </summary>
/// <param name="day">The day of the week</param>
public RestrictionUnit OnTheThirdDay(DayOfWeek day)
{
_calculator.PeriodCalculations.Add(last => SelectNthDay(last.Date.Year, last.Date.Month, day, 3));
return new RestrictionUnit(_calculator);
}

/// <summary>
/// Runs the job on the given day of week on the fourth week of the month.
/// </summary>
/// <param name="day">The day of the week</param>
public RestrictionUnit OnTheFourthDay(DayOfWeek day)
{
_calculator.PeriodCalculations.Add(last => SelectNthDay(last.Date.Year, last.Date.Month, day, 4));
return new RestrictionUnit(_calculator);
}

private static DateTime SelectNthDay(int year, int month, DayOfWeek dayOfWeek, int occurrence) =>
Enumerable.Range(1, 7)
.Select(day => new DateTime(year, month, day))
.First(dateTime => dateTime.DayOfWeek == dayOfWeek)
.AddDays(7 * (occurrence - 1));
}
}

0 comments on commit 834e0a1

Please sign in to comment.