Skip to content

Commit

Permalink
Merge pull request #360 from NeoCoderMatrix86/349-track-validation-of…
Browse files Browse the repository at this point in the history
…-beginend-is-failing

Track validation of beginend is failing
  • Loading branch information
NeoCoderMatrix86 authored Jun 4, 2024
2 parents 00d2fe9 + 85dd504 commit c031151
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ protected override ValidationResult Validate(string property)
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must be equal or greater zero!", nameof(Begin)));
}
if (Begin > End)
{
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} should be less than or equal '{1}'!", nameof(Begin), nameof(End)));
}
}
break;
case nameof(End):
Expand All @@ -448,6 +453,11 @@ protected override ValidationResult Validate(string property)
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must be equal or greater zero!", nameof(End)));
}
if (End < Begin)
{
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} should be greater than or equal '{1}'!", nameof(End), nameof(Begin)));
}
}
break;
case nameof(Length):
Expand Down
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/Entity/IValidateable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<ValidationMessage>? ValidationMessages
set
{
validationMessages = value;
if ((validationMessages != null) && validationMessages.Any())
if ((validationMessages != null) && validationMessages.Count != 0)
{
Status = ValidationStatus.Error;
}
Expand Down
32 changes: 31 additions & 1 deletion AudioCuesheetEditorTests/Model/AudioCuesheet/TrackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void CopyValuesTest()
Assert.AreEqual(sourceTrack.End, destinyTrack.End);
Assert.AreEqual(sourceTrack.PreGap, destinyTrack.PreGap);
Assert.AreEqual(sourceTrack.PostGap, destinyTrack.PostGap);
var destinationTracks = new List<Track>() { new Track(), new Track(), new Track() };
var destinationTracks = new List<Track>() { new(), new(), new() };
destinationTracks.ForEach(x => x.CopyValues(sourceTrack, useInternalSetters: Track.AllPropertyNames));
Assert.IsTrue(destinationTracks.All(x => x.IsLinkedToPreviousTrack == sourceTrack.IsLinkedToPreviousTrack));
Assert.IsTrue(destinationTracks.All(x => x.Cuesheet == sourceTrack.Cuesheet));
Expand Down Expand Up @@ -223,5 +223,35 @@ public void SetCuesheetTest()
track.Cuesheet = null;
Assert.IsNull(track.Cuesheet);
}

[TestMethod()]
public void Validate_InvalidEnd_ReturnsValidationStatusError()
{
// Arrange
var track = new Track
{
Begin = new TimeSpan(0, 2, 32),
End = new TimeSpan(0, 1, 15)
};
// Act
var endValidationResult = track.Validate(x => x.End);
// Assert
Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status);
}

[TestMethod()]
public void Validate_InvalidBegin_ReturnsValidationStatusError()
{
// Arrange
var track = new Track
{
Begin = new TimeSpan(0, 4, 53),
End = new TimeSpan(0, 3, 15)
};
// Act
var endValidationResult = track.Validate(x => x.Begin);
// Assert
Assert.AreEqual(ValidationStatus.Error, endValidationResult.Status);
}
}
}

0 comments on commit c031151

Please sign in to comment.