Example #1
0
        public static void WorkingDayServiceWithMultipleSourcesReturnsFalseForAnyDayConsideredAWorkingDayByAtLeastOneSourcePassedToIsWorkingDay()
        {
            CorshamScience.Tools.WorkingDayService.WorkingDayService workingDayService = WorkingDayServiceBuilder.New()
                                                                                         .AddDaysOfTheWeekNonWorkingDaySource(DayOfWeek.Monday)
                                                                                         .AddDaysOfTheWeekNonWorkingDaySource(DayOfWeek.Tuesday);

            Assert.IsTrue(workingDayService.IsWorkingDay(new DateTime(2018, 5, 16)));
            Assert.IsTrue(workingDayService.IsWorkingDay(new DateTime(2018, 5, 17)));
        }
Example #2
0
 public static void WorkingDayServiceWithNoSourcesThrowsArgumentException()
 => Assert.Throws <ArgumentException>(() =>
 {     // ReSharper disable once UnusedVariable
     CorshamScience.Tools.WorkingDayService.WorkingDayService workingDayService = WorkingDayServiceBuilder.New();
 });
Example #3
0
 public static void WorkingDayServiceWithOneSourceReturnsFalseWhenIsWorkingDayIsCalledOnANonWorkingDay()
 => Assert.IsTrue(((CorshamScience.Tools.WorkingDayService.WorkingDayService)WorkingDayServiceBuilder.New().AddDaysOfTheWeekNonWorkingDaySource(DayOfWeek.Monday))
                  .IsNonWorkingDay(new DateTime(2018, 5, 14)));
 /// <summary>
 /// Configures a <see cref="WorkingDayServiceBuilder"/> to use a <see cref="StringNonWorkingDaySource{T}"/> in addition to any previously configured sources.
 /// </summary>
 /// <typeparam name="T">The type of the internal state of the <see cref="StringNonWorkingDaySource{T}"/>.</typeparam>
 /// <param name="builder">The Builder to configure.</param>
 /// <param name="source">The string content to be used to build the internal state of the <see cref="StringNonWorkingDaySource{T}"/>.</param>
 /// <param name="parseFileContentAction">The action used to build the internal state of the <see cref="StringNonWorkingDaySource{T}"/> from the provided string content.</param>
 /// <param name="checkAction">The action used to determine whether a given <see cref="DateTime"/> is on a non-Working Day (using the <see cref="StringNonWorkingDaySource{T}"/>, based on the provided string content).
 /// Should return <c>true</c> if the provided <see cref="DateTime"/> is on a Non-Working Day, and <c>false</c> if it is on a Working Day.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the new <see cref="StringNonWorkingDaySource{T}"/>, in addition to any previously configured sources.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddStringSource <T>(this WorkingDayServiceBuilder builder, string source, Func <string, T> parseFileContentAction, Func <DateTime, T, bool> checkAction)
 => builder.WithSource(new StringNonWorkingDaySource <T>(source, parseFileContentAction, checkAction));
Example #5
0
 /// <summary>
 /// Configures a <see cref="WorkingDayServiceBuilder"/> to use a <see cref="FileNonWorkingDaySource{T}"/> in addition to any current sources.
 /// </summary>
 /// <typeparam name="T">The type of the internal state of the <see cref="FileNonWorkingDaySource{T}"/>.</typeparam>
 /// <param name="builder">The Builder to configure.</param>
 /// <param name="filePath">The path to the file to which should be used to create the <see cref="FileNonWorkingDaySource{T}"/>'s internal state.</param>
 /// <param name="parseFileContentAction">The action to build the internal state of the <see cref="FileNonWorkingDaySource{T}"/> from the content of the file at the provided file path.</param>
 /// <param name="checkAction">The action used to determine whether a <see cref="DateTime"/> is on a Non-Working Day (based on the current state of the <see cref="FileNonWorkingDaySource{T}"/>).
 /// Should return <c>true</c> if the provided <see cref="DateTime"/> is on a Non-Working Day, and <c>false</c> if it is on a Working Day.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the new <see cref="FileNonWorkingDaySource{T}"/> configured with the file at the provided file path, as well as any previously configured sources.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddFileSource <T>(this WorkingDayServiceBuilder builder, string filePath, Func <string, T> parseFileContentAction, Func <DateTime, T, bool> checkAction)
 => builder.WithSource(new FileNonWorkingDaySource <T>(filePath, parseFileContentAction, checkAction));
Example #6
0
 /// <summary>
 /// Configures the <see cref="WorkingDayServiceBuilder"/> to use a <see cref="NonWorkingDaySource"/> based on the UK's Bank Holidays, as well as any previously configured sources.
 /// </summary>
 /// <remarks>
 /// The source is based on a <see cref="HttpNonWorkingDaySource{T}"/> created using the UK Government's Bank Holidays JSON API.
 /// </remarks>
 /// <param name="builder">The <see cref="WorkingDayServiceBuilder"/> to configure to use UK Bank Holidays for Non-Working Day detection.</param>
 /// <param name="refreshTime">The amount of time the <see cref="WorkingDayService"/> should wait between attempted refreshes of the Bank Holiday list (on failure to update, the state will not change).</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the UK Bank Holidays <see cref="NonWorkingDaySource"/>, as well as any previously configured sources.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddGovUkBankHolidayJsonSource(this WorkingDayServiceBuilder builder, TimeSpan refreshTime)
 => builder.WithSource(GovUkBankHolidayJsonSource(refreshTime));
 /// <summary>
 /// Configures a <see cref="WorkingDayServiceBuilder"/> to use a <see cref="HttpNonWorkingDaySource{T}"/>, in addition to any previously configured sources.
 /// </summary>
 /// <typeparam name="T">The Type of the internal state of the <see cref="HttpNonWorkingDaySource{T}"/>.</typeparam>
 /// <param name="builder">The <see cref="WorkingDayServiceBuilder"/> to configure.</param>
 /// <param name="request">The <see cref="HttpRequestMessage"/> to make to update the internal state of the <see cref="HttpNonWorkingDaySource{T}"/>.</param>
 /// <param name="parseAction">The <see cref="Func{TContent, TResult}"/> used to build the internal state of the <see cref="HttpNonWorkingDaySource{T}"/> from the content of the provided <see cref="HttpRequestMessage"/>'s <see cref="HttpResponseMessage"/>.</param>
 /// <param name="checkAction">The <see cref="Func{TDateTime, TState, TResult}"/> used to check whether a given <see cref="DateTime"/> is on a non-working day based on the current state of the <see cref="HttpNonWorkingDaySource{T}"/>.
 /// Should return <c>true</c> if the provided <see cref="DateTime"/> is on a Non-Working Day, and <c>false</c> if it is on a Working Day.</param>
 /// <param name="refreshTimer">The interval at which to make the provided HTTP Request to update the internal state.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the new <see cref="HttpNonWorkingDaySource{T}"/>, in addition to any previously configured sources.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddHttpSource <T>(this WorkingDayServiceBuilder builder, HttpRequestMessage request, Func <string, T> parseAction, Func <DateTime, T, bool> checkAction, TimeSpan refreshTimer)
 => builder.WithSource(new HttpNonWorkingDaySource <T>(request, parseAction, checkAction, refreshTimer));
Example #8
0
 /// <summary>
 /// Configures the <see cref="WorkingDayServiceBuilder"/> to use a <see cref="DaysOfTheWeekNonWorkingDaySource"/> which considers Monday -> Friday Working Days, and Saturday and Sunday to be Non-Working Days, as well as any previously configured <see cref="NonWorkingDaySource"/>s.
 /// </summary>
 /// <param name="builder">The Builder to configure.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> with the new <see cref="DaysOfTheWeekNonWorkingDaySource"/> added.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddWeekendNonWorkingDaySource(this WorkingDayServiceBuilder builder) => builder.WithSource(new DaysOfTheWeekNonWorkingDaySource(new HashSet <DayOfWeek> {
     DayOfWeek.Saturday, DayOfWeek.Sunday
 }));
Example #9
0
 /// <summary>
 /// Configures the <see cref="WorkingDayServiceBuilder"/> to use a <see cref="DaysOfTheWeekNonWorkingDaySource"/> which considers the provided days to be Non-Working days, as well as any previously configured sources.
 /// </summary>
 /// <param name="builder">The Builder to configure.</param>
 /// <param name="workingDays">The days to consider Non-Working Days.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the new <see cref="DaysOfTheWeekNonWorkingDaySource"/> configured with the provided days, as well as any previously configured <see cref="NonWorkingDaySource"/>s.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddDaysOfTheWeekNonWorkingDaySource(this WorkingDayServiceBuilder builder, params DayOfWeek[] workingDays) => builder.WithSource(new DaysOfTheWeekNonWorkingDaySource(workingDays));
Example #10
0
 /// <summary>
 /// Configures the <see cref="WorkingDayServiceBuilder"/> to use a <see cref="DaysOfTheWeekNonWorkingDaySource"/> which considers the provided days to be Non-Working days, as well as any previously configured sources.
 /// </summary>
 /// <param name="builder">The Builder to configure.</param>
 /// <param name="workingDays">The days to consider Non-Working Days.</param>
 /// <returns>The same instance of a <see cref="WorkingDayServiceBuilder"/> using the new <see cref="DaysOfTheWeekNonWorkingDaySource"/> configured with the provided days, as well as any previously configured <see cref="NonWorkingDaySource"/>s.</returns>
 // ReSharper disable once UnusedMember.Global
 public static WorkingDayServiceBuilder AddDaysOfTheWeekNonWorkingDaySource(this WorkingDayServiceBuilder builder, IEnumerable <DayOfWeek> workingDays) => builder.WithSource(new DaysOfTheWeekNonWorkingDaySource(workingDays));