public void ShouldGetTodayAsNearestFridayIfTodayIsSunday() { _mockTimeProvider.Setup(o => o.Today()).Returns(new DateTime(2016, 08, 07)); DateCalculator dateCalculator = new DateCalculator(_mockTimeProvider.Object); dateCalculator.NearestFriday().Should().Be("2016-08-07"); }
public void Calculate_DateDifferenceCorrectly_When_DatesAreCorrect(string date1, string date2, int difference) { var dateCalculator = new DateCalculator(); var calculatedDifference = dateCalculator.Calculate(date1, date2); Assert.Equal(difference, calculatedDifference); }
public void DateCalculatorVerifyFebuaryDaysPerMonth(int year, int expectedDays) { int month = 2; int days = DateCalculator.DaysPerMonth(month, year); Assert.AreEqual(expectedDays, days, "Verify that the days matches the expected value for month ", month); }
public void ShouldReturnAllDatesWhen90DatesSelected() { var dates = DateCalculator.GenerateDates(); dates.Count.ShouldBe(90); dates.First().ShouldBe(DateTime.Today); }
public void WhenEndEqualToStartExceptionIsThrown() { DateTime start = DateTime.Now; DateTime end = start; Assert.Throws <ArgumentException>(() => DateCalculator.GetWorkingDays(start, end)); }
/// <summary> /// Initializes data that is needed fot this class. /// </summary> internal void Initialize() { // Initialize other stuff. this.database = FileSystem.FindDatabaseFile(); this.AllDaysInMonth = new ObservableCollection <WorkdayViewModel>(); this.GetAllDays(DateTime.Now.Year, DateTime.Now.Month); var todayDate = DateTime.Now.Date; this.Today = this.AllDaysInMonth.Single(day => day.StartTime.Date == todayDate); if (this.Today.StartTime.TimeOfDay.Equals(DateTime.MinValue.TimeOfDay)) { var logon = UserInfo.GetLastLogOnToMachine(this.Today.StartTime.Date); this.Today.StartTime = logon; } this.Today = this.AllDaysInMonth.Single(day => DateTime.Now.Date.Equals(day.StartTime.Date)); this.AppVersion = GetPublishedVersion(); this.UpdateCommand = new RelayCommand( () => { this.Today.RemainingTime = DateCalculator.GetDeltaTime(this.Today, DateTime.Now); }); }
public App() { InitializeComponent(); MainPage = new TabController(); dateCalc = new DateCalculator(); }
public GroupControllerTest() { _filteredUrl = new Mock <IFilteredUrl>(); _logger = new Mock <ILogger <GroupsController> >(); var emailLogger = new Mock <ILogger <GroupEmailBuilder> >(); var eventEmailLogger = new Mock <ILogger <EventEmailBuilder> >(); var emailClient = new Mock <IHttpEmailClient>(); var emailConfig = new Mock <IApplicationConfiguration>(); emailConfig.Setup(a => a.GetEmailEmailFrom(It.IsAny <string>())) .Returns(AppSetting.GetAppSetting("GroupSubmissionEmail")); _groupEmailBuilder = new Mock <GroupEmailBuilder>(emailLogger.Object, emailClient.Object, emailConfig.Object, new BusinessId("BusinessId")); _eventEmailBuilder = new Mock <EventEmailBuilder>(eventEmailLogger.Object, emailClient.Object, emailConfig.Object, new BusinessId("BusinessId")); var mockTime = new Mock <ITimeProvider>(); var viewHelper = new ViewHelpers(mockTime.Object); datetimeCalculator = new DateCalculator(mockTime.Object); http = new Mock <IHttpContextAccessor>(); var cookies = new FakeCookie(true); http.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies); _groupController = new GroupsController(_processedRepository.Object, _repository.Object, _groupEmailBuilder.Object, _eventEmailBuilder.Object, _filteredUrl.Object, _logger.Object, _configuration.Object, _markdownWrapper.Object, viewHelper, datetimeCalculator, _loggedInHelper.Object, _groupsService.Object, _cookiesHelper.Object, new StockportWebapp.FeatureToggling.FeatureToggles()); // setup mocks _groupsService.Setup(o => o.GetGroupCategories()).ReturnsAsync(groupCategories); _groupsService.Setup(o => o.GetGroupHomepage()).ReturnsAsync(groupHomepage); _groupsService.Setup(o => o.GetAvailableGroupCategories()).ReturnsAsync(new List <string>()); _groupsService.Setup(o => o.GetErrorsFromModelState(It.IsAny <ModelStateDictionary>())).Returns(""); }
private void StoreEntry(MemoInfo memoInfo) { TimeSpan timeSpan = DateTime.Now - CreateTime; string minStr = timeSpan.Minutes == 0 ? string.Empty : string.Format(@"{0}'", timeSpan.Minutes); string secStr = timeSpan.Seconds == 0 ? string.Empty : string.Format(@"{0}s", timeSpan.Seconds); if (!(string.IsNullOrEmpty(minStr) && string.IsNullOrEmpty(secStr))) { Entry entry = new Entry { EntryId = System.Guid.NewGuid().ToString(), EntryType = EntryType.Memo.ToString(), CreateTime = CreateTime, StartTime = StartTime, ExpirationTime = DateCalculator.LastTime(StartTime), RepeatType = RepeatType.NotRepeated.ToString(), ExtraInfo = minStr + secStr, AlarmOn = false, AlarmTime = DateTime.Now, AttachmentFile = memoInfo.FileName }; EntryDataContext.Instance.EntryTable.InsertOnSubmit(entry); EntryDataContext.Instance.SubmitChanges(); } }
public HttpResponseMessage Get(string id, Frequency frequency, int day, decimal time, RunStatus lastRunStatus, int depth) { var trace = new GenericLoggingService("Details"); try { var calculator = new DateCalculator(DateTime.UtcNow, trace); var nextRunDate = calculator.Calculate(frequency, day, time, lastRunStatus, depth); if (!nextRunDate.HasValue) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new SchedulingResult { Message = "Unable to Calculate Next Run Date, ensure you have specified valid scheduling attributes" })); } return(Request.CreateResponse(HttpStatusCode.OK, new SchedulingResult { NextRunDate = nextRunDate.Value.UtcDateTime })); } catch (Exception exp) { var message = $"Error calculating next run date. {exp.Message}"; trace.Trace(TraceEventType.Error, (int)EventId.ScheduleApiError, message, exp); return(Request.CreateResponse(HttpStatusCode.InternalServerError, new SchedulingResult { Message = message })); } }
public void ShouldGetNearestMonday() { _mockTimeProvider.Setup(o => o.Today()).Returns(new DateTime(2016, 08, 02)); DateCalculator dateCalculator = new DateCalculator(_mockTimeProvider.Object); dateCalculator.NearestMonday().Should().Be("2016-08-08"); }
public void Should_return_current_year_after_cutoff() { // July first is this year when today is after the cutoff var calculator = new DateCalculator(Month.July, 1); var date = calculator.SchoolYearDate(Month.July, 1, new DateTime(2000, 7, 1)); Assert.AreEqual(2000, date.Year); }
/// <summary> /// Processes the current values to update the displayed values. /// </summary> private void UpdateTimeValues() { var currentTime = DateCalculator.GetCurrentTime(this); this.RemainingTime = DateCalculator.GetDeltaTime(this, currentTime); this.TargetTime = DateCalculator.GetTargetTime(this.StartTime, this.DefaultWorkLength, this.TotalBreakLength); }
public void Should_return_previous_year_before_cutoff() { // July first is last year when today is before the cutoff var calculator = new DateCalculator(Month.July, 1); var date = calculator.SchoolYearDate(Month.July, 1, new DateTime(2000, 6, 30)); Assert.AreEqual(1999, date.Year); }
public void TestdatesForIndex() { var test = DateCalculator.datesForIndex(0); Assert.AreEqual("Calendario Judaico: 15, Tevet, 5751", test[0]); Assert.AreEqual("Calendario Muçulmano: 14, Jumada t-Tania, 1411", test[1]); Assert.AreEqual("Calendario Chinês: 16, Ding-Chou, 4688 - Animal: Cavalo", test[2]); }
public void ShouldReturnSelectedDaysWhenSpecifiedDaysOfWeekSelected(string day) { string[] days = { day }; var dates = DateCalculator.GenerateDates(days); dates.All(date => date.DayOfWeek.ToString() == day).ShouldBeTrue(); }
public void RecalculateDate() { ItemData.daysUntilExp = DateCalculator.SubtractDate(ItemData.expYear, ItemData.expMonth, ItemData.expDay); expirationMark.Text = DateCalculator.SubtractDateStringed(ItemData.expYear, ItemData.expMonth, ItemData.expDay); if (ItemData.daysUntilExp == 0) { expirationMark.Text = "Exp"; } }
private void cmbDates_SelectedIndexChanged(object sender, EventArgs e) { ltbDatesEq.Items.Clear(); var dates = DateCalculator.datesForIndex(cmbDates.SelectedIndex); ltbDatesEq.Items.Add(dates[0]); ltbDatesEq.Items.Add(dates[1]); ltbDatesEq.Items.Add(dates[2]); }
static void Main(string[] args) { RawDate rawDate = new RawDate(); while (true) { Console.WriteLine("--> Please enter a date with the format DD/MM/YYYY"); string date = Console.ReadLine(); bool isValidDate = rawDate.IsDateValid(date); if (isValidDate) { Console.WriteLine("You entered the date: " + date); Console.WriteLine(); Console.WriteLine("--> Please enter the amount of days to add"); string daysToAdd = Console.ReadLine(); int i; if (int.TryParse(daysToAdd, out i)) { if (i < 1) { Console.WriteLine("XXX INVALID NUMBER OF DAYS XXX"); continue; } rawDate = new RawDate() { rawDate = date }; DateCalculator dateCalculator = new DateCalculator(); RawDate result = dateCalculator.AddDays(rawDate, int.Parse(daysToAdd)); Console.WriteLine("New Date: " + result.rawDate); } else { Console.WriteLine("XXX INVALID NUMBER OF DAYS XXX"); } Console.WriteLine(); } else { Console.WriteLine("XXX INVALID DATE XXX"); } Console.WriteLine("----------------------"); Console.WriteLine(); } }
public void ShouldReturnEmptyStringForEmptyKey() { _mockTimeProvider.Setup(o => o.Today()).Returns(new DateTime(2017, 12, 25)); var dateCalculator = new DateCalculator(_mockTimeProvider.Object); var value = dateCalculator.ReturnDisplayNameForFilter(string.Empty); value.Should().Be(string.Empty); }
public void ShouldGetValueForKeyForFilterIfKeyExistsForAnotherKey() { _mockTimeProvider.Setup(o => o.Today()).Returns(new DateTime(2017, 12, 25)); var dateCalculator = new DateCalculator(_mockTimeProvider.Object); var value = dateCalculator.ReturnDisplayNameForFilter("thisweekend"); value.Should().Be("This weekend"); }
public void WhenDaily_AndCurrentTimeBeforeScheduleTime_ReturnsTodayAtScheduledTime(RunStatus lastRunStatus) { var date = new DateCalculator(new DateTime(2017, 06, 09, 1, 1, 1, DateTimeKind.Utc), trace).Calculate( Frequency.Daily, 10, 21.30M, lastRunStatus, 1); Assert.That(date.Value.Month, Is.EqualTo(6)); Assert.That(date.Value.Day, Is.EqualTo(9)); Assert.That(date.Value.Hour, Is.EqualTo(21)); Assert.That(date.Value.Minute, Is.EqualTo(30)); }
public void ShouldNotGiveAValueForNoExistantKey() { _mockTimeProvider.Setup(o => o.Today()).Returns(new DateTime(2017, 12, 25)); var dateCalculator = new DateCalculator(_mockTimeProvider.Object); var value = dateCalculator.ReturnDisplayNameForFilter("none"); value.Should().Be(string.Empty); }
public void AddDays_10101972_Minus1_RawDateNull() { DateCalculator dateCalculator = new DateCalculator(); RawDate rawDate = new RawDate() { rawDate = "10/10/1972" }; RawDate result = dateCalculator.AddDays(rawDate, -1); Assert.IsNull(result.rawDate); }
public void WhenMontly_AndDay31_AndNextMonthHas30Days_ShouldReturn30thDay(RunStatus lastRunStatus) { var date = new DateCalculator(new DateTime(2017, 05, 31, 22, 1, 1, DateTimeKind.Utc), trace).Calculate(Frequency.Monthly, 30, 21.30M, lastRunStatus, 1); Assert.That(date.Value.Month, Is.EqualTo(6)); Assert.That(date.Value.Day, Is.EqualTo(30)); Assert.That(date.Value.Hour, Is.EqualTo(21)); Assert.That(date.Value.Minute, Is.EqualTo(30)); }
public void WhenMontly_AndDay10_AndLastRunNotNull_ShouldReturnNextMonth_On10thDay(RunStatus lastRunStatus) { var date = new DateCalculator(new DateTime(2017, 06, 11, 1, 1, 1, DateTimeKind.Utc), trace).Calculate(Frequency.Monthly, 10, 21.30M, lastRunStatus, 1); Assert.That(date.Value.Month, Is.EqualTo(7)); Assert.That(date.Value.Day, Is.EqualTo(10)); Assert.That(date.Value.Hour, Is.EqualTo(21)); Assert.That(date.Value.Minute, Is.EqualTo(30)); }
public void WhenWeekly_AndDay1_ReturnsNextMonday(RunStatus lastRunStatus) { var date = new DateCalculator(new DateTime(2017, 06, 09, 1, 1, 1, DateTimeKind.Utc), trace).Calculate(Frequency.Weekly, 1, 21.30M, lastRunStatus, 1); Assert.That(date.Value.Month, Is.EqualTo(6)); Assert.That(date.Value.Day, Is.EqualTo(12)); Assert.That(date.Value.Hour, Is.EqualTo(21)); Assert.That(date.Value.Minute, Is.EqualTo(30)); }
public void AddDays_RawDate_rawDate_IsStringEmpty() { DateCalculator dateCalculator = new DateCalculator(); RawDate rawDate = new RawDate() { rawDate = "" }; RawDate returnedRawDate = dateCalculator.AddDays(rawDate, 0); Assert.IsEmpty(returnedRawDate.rawDate); }
public void DownRoundingShouldWorkFineTest() { var calculator = new DateCalculator(); var testTime = new DateTime(2000, 10, 10, 12, 23, 29); DateTime result = calculator.CalculateEndTime(testTime); var expected = new DateTime(2000, 10, 10, 12, 30, 0); Assert.AreEqual(expected, result); }
public void AddDays_RawDateNotNull() { DateCalculator dateCalculator = new DateCalculator(); RawDate rawDate = new RawDate() { rawDate = "" }; RawDate returnedRawDate = dateCalculator.AddDays(rawDate, 0); Assert.IsNotNull(returnedRawDate); }