From b576d79dad8c57a5eae87225690a1c1de840537b Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:27:39 +0200 Subject: [PATCH] Added end validation --- .../Model/IO/Export/CuesheetSection.cs | 33 +++++++++++++-- .../Localization/ValidationMessage/de.json | 5 ++- .../Localization/ValidationMessage/en.json | 5 ++- .../Model/IO/Export/CuesheetSectionTests.cs | 42 ++++++++++++++----- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs b/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs index 084e1307..4166b017 100644 --- a/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs +++ b/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs @@ -128,8 +128,6 @@ protected override ValidationResult Validate(string property) { ValidationStatus validationStatus = ValidationStatus.NoValidation; List? validationMessages = null; - //TODO: Validate end also - //TODO: Change validation of begin to this entitys switch (property) { case nameof(Begin): @@ -140,12 +138,39 @@ protected override ValidationResult Validate(string property) validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Begin))); } else + { + var minBegin = Cuesheet?.Tracks.Min(x => x.Begin); + if (Begin < minBegin) + { + validationMessages ??= []; + validationMessages.Add(new ValidationMessage("{0} should be greater than or equal '{1}'!", nameof(Begin), minBegin)); + } + if (Begin > End) + { + validationMessages ??= []; + validationMessages.Add(new ValidationMessage("{0} should be less than or equal '{1}'!", nameof(Begin), End)); + } + } + break; + case nameof(End): + validationStatus = ValidationStatus.Success; + if (End == null) + { + validationMessages ??= []; + validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(End))); + } + else { var maxEnd = Cuesheet?.Tracks.Max(x => x.End); - if (Begin > maxEnd) + if (End > maxEnd) + { + validationMessages ??= []; + validationMessages.Add(new ValidationMessage("{0} should be less than or equal '{1}'!", nameof(End), maxEnd)); + } + if (End < Begin) { validationMessages ??= []; - validationMessages.Add(new ValidationMessage("{0} should be equal or less to '{1}'!", nameof(Begin), maxEnd)); + validationMessages.Add(new ValidationMessage("{0} should be greater than or equal '{1}'!", nameof(End), Begin)); } } break; diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json index afdb290e..5d513fa6 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json @@ -34,12 +34,13 @@ "CuesheetFilename": "Cuesheet Dateiname", "RecordedAudiofilename": "Dateiname für aufgenommenes Audio", "ProjectFilename": "Projektdateiname", - "{0} should be equal or less to '{1}'!": "{0} sollte kleiner oder gleich '{1}' sein!", "Filename": "Dateiname", "Artist": "Künstler", "Title": "Titel", "Exportprofile": "Exportprofil", "ApplicationOptions": "Applikationsoptionen", - "AudiofileName": "Audiodatei" + "AudiofileName": "Audiodatei", + "{0} should be greater than or equal '{1}'!": "{0} sollte größer oder gleich '{1}' sein!", + "{0} should be less than or equal '{1}'!": "{0} sollte kleiner oder gleich '{1}' sein!" } } \ No newline at end of file diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json index 309d5fe4..588a2cc6 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json @@ -34,12 +34,13 @@ "CuesheetFilename": "Cuesheet filename", "RecordedAudiofilename": "Filename for recorded audio", "ProjectFilename": "Project filename", - "{0} should be equal or less to '{1}'!": "{0} should be equal or less to '{1}'!", "Filename": "Filename", "Artist": "Artist", "Title": "Title", "Exportprofile": "Exportprofile", "ApplicationOptions": "Application options", - "AudiofileName": "Audiofile" + "AudiofileName": "Audiofile", + "{0} should be greater than or equal '{1}'!": "{0} should be greater than or equal '{1}'!", + "{0} should be less than or equal '{1}'!": "{0} should be less than or equal '{1}'!" } } \ No newline at end of file diff --git a/AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs b/AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs index f44a40e0..e9810a3c 100644 --- a/AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs +++ b/AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs @@ -19,18 +19,38 @@ public void ValidationTest() var cuesheet = new Cuesheet(); var section = new CuesheetSection(cuesheet); Assert.IsNull(section.Begin); - var validationResult = section.Validate(x => x.Begin); - Assert.AreEqual(ValidationStatus.Error, validationResult.Status); - section.Begin = new TimeSpan(0, 30, 0); - validationResult = section.Validate(x => x.Begin); - Assert.AreEqual(ValidationStatus.Success, validationResult.Status); - cuesheet.AddTrack(new Track() { Position = 1}); + var beginValidationResult = section.Validate(x => x.Begin); + var endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Error, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status); + section.Begin = new TimeSpan(0, 0, 0); + beginValidationResult = section.Validate(x => x.Begin); + endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Success, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status); + cuesheet.AddTrack(new Track() { Position = 1, Begin = new TimeSpan(0, 0, 10) }); cuesheet.AddTrack(new Track() { Position = 2, Begin = new TimeSpan(0, 8, 43), End = new TimeSpan(0, 15, 43) }); - validationResult = section.Validate(x => x.Begin); - Assert.AreEqual(ValidationStatus.Error, validationResult.Status); - section.Begin = new TimeSpan(0, 15, 43); - validationResult = section.Validate(x => x.Begin); - Assert.AreEqual(ValidationStatus.Success, validationResult.Status); + beginValidationResult = section.Validate(x => x.Begin); + endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Error, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status); + section.Begin = new TimeSpan(0, 0, 10); + beginValidationResult = section.Validate(x => x.Begin); + endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Success, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status); + section.Begin = new TimeSpan(0, 10, 0); + section.End = new TimeSpan(0, 5, 0); + beginValidationResult = section.Validate(x => x.Begin); + endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Error, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status); + section.Begin = new TimeSpan(0, 10, 0); + section.End = new TimeSpan(0, 15, 0); + beginValidationResult = section.Validate(x => x.Begin); + endValidationResult = section.Validate(x => x.End); + Assert.AreEqual(ValidationStatus.Success, beginValidationResult.Status); + Assert.AreEqual(ValidationStatus.Success, endValidationResult.Status); } } } \ No newline at end of file