public void TestContains() { var rule = new MonthlyRecurrentTimeSlot(1, 31, new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 00)); Assert.IsTrue(rule.Contains(new System.DateTime(2015, 12, 1))); Assert.IsTrue(rule.Contains(new System.DateTime(2015, 12, 31))); Assert.IsTrue(rule.Contains(new System.DateTime(2015, 2, 28))); }
public ITimeSlot Build(string descriptor) { descriptor = Descriptor.Translate(descriptor, _culture, CultureInfo.InvariantCulture); if (descriptor == Descriptor.Keywords.Always) { return(new AlwaysTimeSlot()); } if (descriptor == Descriptor.Keywords.Never) { return(new NeverTimeSlot()); } var words = descriptor.Split(' ').ToList(); if (words.Contains(Descriptor.Keywords.Intersecting) || words.Contains(Descriptor.Keywords.Or) || words.Contains(Descriptor.Keywords.But) || descriptor.Contains("(") || descriptor.Contains(")")) { return(ComplexTimeSlot.FromDescriptor(descriptor, _aliasesProvider)); } if (descriptor.StartsWith(Descriptor.Keywords.Between)) { return(AbsoluteTimeSlot.FromDescriptor(descriptor)); } if (descriptor.StartsWith(":")) { return(AliasTimeSlot.FromDescriptor(descriptor, _aliasesProvider)); } if (!descriptor.StartsWith(Descriptor.Keywords.Every)) { throw new InvalidDescriptorException(descriptor); } if (words.Contains(Descriptor.Keywords.Day)) { return(DailyRecurrentTimeSlot.FromDescriptor(descriptor)); } if (words.Contains(Descriptor.Keywords.Month)) { return(MonthlyRecurrentTimeSlot.FromDescriptor(descriptor)); } if (words.Contains(Descriptor.Keywords.Week)) { return(WeeklyRecurrentTimeSlot.FromDescriptor(descriptor)); } if (words.Contains(Descriptor.Keywords.Year)) { return(YearlyRecurrentTimeSlot.FromDescriptor(descriptor)); } throw new InvalidDescriptorException(descriptor); }
public void TestToString() { { var instance = new MonthlyRecurrentTimeSlot(16, 24); const string proof = "EVERY MONTH BETWEEN 16 AND 24"; Assert.AreEqual(proof, instance.ToString()); } { var instance = new MonthlyRecurrentTimeSlot(1, 12, new TimeSpan(8, 30, 00), new TimeSpan(9, 15, 00)); const string proof = "EVERY MONTH BETWEEN 1 08:30 AND 12 09:15"; Assert.AreEqual(proof, instance.ToString()); } }
public void TestBuilder() { { var proof = new MonthlyRecurrentTimeSlot(16, 24); const string str = "EVERY MONTH BETWEEN 16 AND 24"; var builded = new TimeSlotBuilder(NoAliasProvider).Build(str); Assert.AreEqual(proof, builded); } { var proof = new MonthlyRecurrentTimeSlot(1, 12, new TimeSpan(8, 30, 00), new TimeSpan(9, 15, 00)); const string str = "EVERY MONTH BETWEEN 1 08:30 AND 12 09:15"; var builded = new TimeSlotBuilder(NoAliasProvider).Build(str); Assert.AreEqual(proof, builded); } }