Skip to content

Commit

Permalink
Added end validation
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Apr 15, 2024
1 parent dca0944 commit b576d79
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
33 changes: 29 additions & 4 deletions AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ protected override ValidationResult Validate(string property)
{
ValidationStatus validationStatus = ValidationStatus.NoValidation;
List<ValidationMessage>? validationMessages = null;
//TODO: Validate end also
//TODO: Change validation of begin to this entitys
switch (property)
{
case nameof(Begin):
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}'!"
}
}
42 changes: 31 additions & 11 deletions AudioCuesheetEditorTests/Model/IO/Export/CuesheetSectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit b576d79

Please sign in to comment.