public Task <Guid> PostCreateViewModelAsync(ProviderApplicationsReportCreateEditModel model, VacancyUser user) { DateTime fromDate; DateTime toDate = _timeProvider.Today; switch (model.DateRange) { case DateRangeType.Last7Days: fromDate = _timeProvider.Today.AddDays(-7); break; case DateRangeType.Last14Days: fromDate = _timeProvider.Today.AddDays(-14); break; case DateRangeType.Last30Days: fromDate = _timeProvider.Today.AddDays(-30); break; case DateRangeType.Custom: fromDate = model.FromDate.AsDateTimeUk().Value.ToUniversalTime(); toDate = model.ToDate.AsDateTimeUk().Value.ToUniversalTime(); break; default: throw new NotImplementedException($"Cannot handle this date range type:{model.DateRange.ToString()}"); } var reportName = $"{fromDate.ToUkTime().AsGdsDate()} to {toDate.ToUkTime().AsGdsDate()}"; DateTime toDateInclusive = toDate.AddDays(1).AddTicks(-1); return(_client.CreateProviderApplicationsReportAsync(model.Ukprn, fromDate, toDateInclusive, user, reportName)); }
[InlineData("1", "4", "2018", "20", "4", "2019")] //BST public async Task PostCreateViewModelAsync_ShouldUseCustomTimespan(string fromDay, string fromMonth, string fromYear, string toDay, string toMonth, string toYear) { long ukprn = 12345678; var model = new ProviderApplicationsReportCreateEditModel { Ukprn = ukprn, DateRange = DateRangeType.Custom, FromDay = fromDay, FromMonth = fromMonth, FromYear = fromYear, ToDay = toDay, ToMonth = toMonth, ToYear = toYear, }; var user = new VacancyUser(); var mockClient = new Mock <IProviderVacancyClient>(); var orchestrator = GetOrchestrator(mockClient.Object, "2019-12-05Z"); var fromDateUtc = DateTimeOffset.Parse($"{fromYear}-{fromMonth}-{fromDay}Z").UtcDateTime; var toDateUtc = DateTimeOffset.Parse($"{toYear}-{toMonth}-{toDay}Z").UtcDateTime; await orchestrator.PostCreateViewModelAsync(model, user); string expectedReportName = $"{fromDateUtc.AsGdsDate()} to {toDateUtc.AsGdsDate()}"; mockClient.Verify(c => c.CreateProviderApplicationsReportAsync( ukprn, fromDateUtc, toDateUtc.AddDays(1).AddTicks(-1), user, expectedReportName), Times.Once); }
[InlineData(DateRangeType.Last30Days, "2019-04-01Z", "2019-05-01Z")] //BST public async Task PostCreateViewModelAsync_ShouldUseCorrectTimespan(DateRangeType dateRangeType, string fromDate, string toDate) { var mockClient = new Mock <IProviderVacancyClient>(); var orchestrator = GetOrchestrator(mockClient.Object, $"{toDate}"); var fromDateUtc = DateTimeOffset.Parse(fromDate).UtcDateTime; var toDateUtc = DateTimeOffset.Parse(toDate).UtcDateTime; long ukprn = 12345678; var model = new ProviderApplicationsReportCreateEditModel { Ukprn = ukprn, DateRange = dateRangeType }; var user = new VacancyUser(); await orchestrator.PostCreateViewModelAsync(model, user); string expectedReportName = $"{fromDateUtc.AsGdsDate()} to {toDateUtc.AsGdsDate()}"; mockClient.Verify(c => c.CreateProviderApplicationsReportAsync( ukprn, fromDateUtc, toDateUtc.AddDays(1).AddTicks(-1), user, expectedReportName), Times.Once); }
public void ShouldValidateDateRange() { var m = new ProviderApplicationsReportCreateEditModel { DateRange = null }; var validator = GetValidator(); var result = validator.Validate(m); result.Errors.Count.Should().Be(1); result.Errors[0].ErrorMessage.Should().Be("You must select the time period for the report"); }
public ProviderApplicationsReportCreateViewModel GetCreateViewModel(ProviderApplicationsReportCreateEditModel model) { var vm = GetCreateViewModel(); vm.DateRange = model.DateRange; vm.FromDay = model.FromDay; vm.FromMonth = model.FromMonth; vm.FromYear = model.FromYear; vm.ToDay = model.ToDay; vm.ToMonth = model.ToMonth; vm.ToYear = model.ToYear; return(vm); }
public async Task <IActionResult> Create(ProviderApplicationsReportCreateEditModel m) { if (ModelState.IsValid == false) { var vm = _orchestrator.GetCreateViewModel(m); return(View(vm)); } var reportId = await _orchestrator.PostCreateViewModelAsync(m, User.ToVacancyUser()); return(RedirectToRoute(RouteNames.ReportConfirmation_Get, new ReportRouteModel { ReportId = reportId, Ukprn = m.Ukprn })); }
public void ShouldValidateToDateIsNotGreaterThanToday() { var m = new ProviderApplicationsReportCreateEditModel { DateRange = DateRangeType.Custom, FromDay = "1", FromMonth = "2", FromYear = "2019", ToDay = "06", ToMonth = "03", ToYear = "2019" }; var validator = GetValidator(); var result = validator.Validate(m); result.Errors.Count.Should().Be(1); result.Errors[0].ErrorMessage.Should().Be("Date to cannot be in the future"); }
public void ShouldValidateToDate(string day, string month, string year) { var m = new ProviderApplicationsReportCreateEditModel { DateRange = DateRangeType.Custom, ToDay = day, ToMonth = month, ToYear = year, FromDay = "1", FromMonth = "2", FromYear = "2019" }; var validator = GetValidator(); var result = validator.Validate(m); result.Errors.Count.Should().Be(1); result.Errors[0].ErrorMessage.Should().Be("Date to format should be dd/mm/yyyy"); }
public void ShouldValidateToDateIsGreaterThanFromDate() { var m = new ProviderApplicationsReportCreateEditModel { DateRange = DateRangeType.Custom, FromDay = "05", FromMonth = "03", FromYear = "2019", ToDay = "05", ToMonth = "03", ToYear = "2019" }; var validator = GetValidator(); var result = validator.Validate(m); result.Errors.Count.Should().Be(1); result.Errors[0].ErrorMessage.Should().Be("Date from must be earlier than Date to"); }