private PreviousTbHistory ExtractPreviousTbHistory(MigrationDbNotification rawNotification) { var details = new PreviousTbHistory(); details.PreviouslyHadTb = Converter.GetStatusFromString(rawNotification.PreviouslyHadTb); details.PreviousTbDiagnosisYear = rawNotification.PreviousTbDiagnosisYear; details.PreviouslyTreated = Converter.GetStatusFromString(rawNotification.PreviouslyTreated); details.PreviousTreatmentCountryId = rawNotification.PreviousTreatmentCountryId; return(details); }
protected override async Task ValidateAndSave() { UpdateFlags(); PreviousTbHistory.SetValidationContext(Notification); PreviousTbHistory.DobYear = Notification.PatientDetails.Dob?.Year; TryValidateModel(PreviousTbHistory, nameof(PreviousTbHistory)); if (ModelState.IsValid) { await Service.UpdatePreviousTbHistoryAsync(Notification, PreviousTbHistory); } }
protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted) { var countries = await _referenceDataRepository.GetAllCountriesAsync(); Countries = new SelectList(countries, nameof(Country.CountryId), nameof(Country.Name)); PreviousTbHistory = Notification.PreviousTbHistory; await SetNotificationProperties(isBeingSubmitted, PreviousTbHistory); if (PreviousTbHistory.ShouldValidateFull) { TryValidateModel(PreviousTbHistory, PreviousTbHistory.GetType().Name); } return(Page()); }
public void SettingInvalidYears_ReturnsCorrectErrorMessage(int year, string errorMessage) { // Arrange var validationResults = new List <ValidationResult>(); var details = new PreviousTbHistory { ShouldValidateFull = false, DobYear = 2000, PreviouslyHadTb = Status.Yes, PreviousTbDiagnosisYear = year, }; // Act var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true); // Assert Assert.Contains(validationResults, r => r.ErrorMessage == errorMessage); Assert.False(isValid, "Expected details to be invalid"); }
public async Task UpdatePreviousTbHistoryAsync(Notification notification, PreviousTbHistory tBHistory) { _context.SetValues(notification.PreviousTbHistory, tBHistory); await _notificationRepository.SaveChangesAsync(); }