public void AndEveryDayOfWeek() { // Arrange var friday = new DateTime(2018, 2, 16); var monday = new DateTime(2018, 2, 19); var sunday = new DateTime(2018, 2, 25); var calculator = new TimeCalculator(); var run = new OnceSet(calculator); // Act run.AndEvery(DayOfWeek.Sunday); var calculated = calculator.Calculate(friday); // Assert var expected = new DateTime(2018, 2, 18); Assert.AreEqual(expected, calculated); //Act calculated = calculator.Calculate(monday); // Assert expected = new DateTime(2018, 2, 25); Assert.AreEqual(expected, calculated); // Act calculated = calculator.Calculate(sunday); // Assert Assert.AreEqual(sunday, calculated); }
/// <summary> /// Returns next fire time for campaign's schema. /// </summary> /// <param name="schema">Campaign schema. /// Instance of <see cref="Terrasoft.Core.Campaign.CampaignSchema"/></param> /// <param name="previousScheduledFireTime">Time of the previous campaign run. /// It can be null when need calculate next fire time relatively current time.</param> /// <returns>Returns instance of <see cref="CampaignFireTimeConfig"/> that contains /// all needed information for schedule next campaign job.</returns> public CampaignFireTimeConfig GetNextFireTime(CoreCampaignSchema schema, DateTime?previousScheduledFireTime) { var scheduledParameters = GetScheduledParameters(schema.EntityId); DefinesTimeParameters(schema, previousScheduledFireTime, scheduledParameters); var resultConfig = TimeCalculator.Calculate(schema, scheduledParameters, new CampaignFireTimeConfig()); resultConfig.Time = DateTime.SpecifyKind(RoundToSeconds(resultConfig.Time), DateTimeKind.Utc); return(resultConfig); }
public void Now() { // Arrange var now = DateTime.Now; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.Now(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now, calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(null, calculated); }
public void NowAndEvery() { // Arrange var now = DateTime.Now; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.Now().AndEvery(10).Seconds(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now, calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddSeconds(10), calculated); }
public void OnceIn() { // Arrange var now = DateTime.Today; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceIn(10).Seconds(); var actual = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddSeconds(10), actual); // Act actual = calculator.Calculate(now); // Assert Assert.AreEqual(null, actual); }
public void OnceAtDateTime() { // Arrange var now = DateTime.Now; var at = new DateTime(2000, 10, 10, 10, 10, 10); var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceAt(at); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(at, calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(null, calculated); }
public void OnceAtTimeSpan() { // Arrange var now = DateTime.Today; var at = new TimeSpan(13, 50, 0); var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceAt(at); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.Add(at), calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(null, calculated); }
public void OnceInTimeSpan() { // Arrange var now = DateTime.Today; var time = TimeSpan.FromSeconds(10); var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceIn(time); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.Add(time), calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(null, calculated); }
public void OnceAtAndEvery() { // Arrange var now = DateTime.Now; var at = new DateTime(2000, 10, 10, 10, 10, 10); var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceAt(at).AndEvery(10).Seconds(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(at, calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddSeconds(10), calculated); }
public void EveryInterval() { var now = DateTime.Today; var calculator = new TimeCalculator(); var run = new OnceSet(calculator); // Act run.AndEvery(10).Seconds(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddSeconds(10), calculated); }
public void OnceAtHoursMinutes() { // Arrange var now = DateTime.Today; var hours = 13; var minutes = 50; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.OnceAt(hours, minutes); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.Date.AddHours(hours).AddMinutes(minutes), calculated); // Act calculated = calculator.Calculate(now); // Assert Assert.AreEqual(null, calculated); }
/// <summary> /// Builds an OsmSharRoute. /// </summary> /// <param name="vehicle"></param> /// <param name="points"></param> /// <param name="tspSolution"></param> /// <param name="weight"></param> /// <returns></returns> public Route BuildRoute(Vehicle vehicle, RouterPoint[] points, IRoute tspSolution, double weight) { int[] solution = tspSolution.ToArray(); Route tsp = null; Route route; for (int idx = 0; idx < solution.Length - 1; idx++) { route = _router.Calculate(Vehicle.Car, points[solution[idx]], points[solution[idx + 1]]); if (tsp == null) { // first route = start tsp = route; } else { // concatenate. tsp = Route.Concatenate(tsp, route); } } if (tspSolution.IsRound) { // concatenate the route from the last to the first point again. route = _router.Calculate(Vehicle.Car, points[solution[solution.Length - 1]], points[solution[0]]); tsp = Route.Concatenate(tsp, route); } if (tsp != null) { tsp.Vehicle = vehicle; // set the correct vehicle type. if (_interpreter != null) { // there is an interpreter set: calculate time/distance. // calculate metrics. var calculator = new TimeCalculator(_interpreter); Dictionary <string, double> metrics = calculator.Calculate(tsp); tsp.TotalDistance = metrics[TimeCalculator.DISTANCE_KEY]; tsp.TotalTime = metrics[TimeCalculator.TIME_KEY]; } tsp.Tags = new RouteTags[1]; tsp.Tags[0] = new RouteTags(); tsp.Tags[0].Key = "internal_weight"; tsp.Tags[0].Value = weight.ToString(System.Globalization.CultureInfo.InvariantCulture); } return(tsp); }
public void Weeks() { // Arrange var now = DateTime.Now; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.Every(5).Weeks(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddDays(35), calculated.Value); }
public void Months() { // Arrange var now = DateTime.Now; var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); // Act run.Every(5).Months(); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.AddMonths(5).Month, calculated.Value.Month); }
public void On() { // Arrange var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); var now = DateTime.Now; var expectedDay = 3; // Act run.Every(1).Months().On(expectedDay); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(expectedDay, calculated.Value.Day); }
public void At() { // Arrange var calculator = new TimeCalculator(); var run = new PeriodOnceSet(calculator); var now = DateTime.Now; // Act run.At(now.Hour, now.Minute); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(now.Hour, calculated.Value.Hour); Assert.AreEqual(now.Minute, calculated.Value.Minute); }
public void OnTheFourthDay() { // Arrange var calculator = new TimeCalculator(); var run = new RunSpecifier(calculator); 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); }
public void AtTimeSpan() { // Arrange var calculator = new TimeCalculator(); var run = new PeriodOnceSet(calculator); var now = DateTime.Now; var timeSpan = new TimeSpan(12, 30, 0); // Act run.At(timeSpan); var calculated = calculator.Calculate(now); // Assert Assert.AreEqual(timeSpan.Hours, calculated.Value.Hour); Assert.AreEqual(timeSpan.Minutes, calculated.Value.Minute); }