From ffcad81af8570d1f5067fef8ac55e1c044358b8e Mon Sep 17 00:00:00 2001 From: sandreas <2050604+sandreas@users.noreply.github.com> Date: Sat, 9 Mar 2024 11:36:09 +0100 Subject: [PATCH] Fixed issue with movement removal --- .../AudioMetadata/MetadataTrackTest.cs | 25 +++++++++++++------ .../AudioMetadata/IMetadataExtensions.cs | 5 ++++ .../AudioMetadata/MetadataTrack.cs | 4 +++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Sandreas.AudioMetadata.Tests/AudioMetadata/MetadataTrackTest.cs b/Sandreas.AudioMetadata.Tests/AudioMetadata/MetadataTrackTest.cs index c34b954..9b9b015 100644 --- a/Sandreas.AudioMetadata.Tests/AudioMetadata/MetadataTrackTest.cs +++ b/Sandreas.AudioMetadata.Tests/AudioMetadata/MetadataTrackTest.cs @@ -3,15 +3,24 @@ namespace Sandreas.AudioMetadata.Tests.AudioMetadata; public class MetadataTrackTest { [Fact] - public void TestMappedProperties() + public void TestRemoveMovement() { - var exception = Record.Exception(() => + var t = new MetadataTrack { - var track = new MetadataTrack - { - EncodingTool = "testing" - }; - }); - Assert.Null(exception); + Movement = "1" + }; + t.RemoveMetadataPropertyValue(MetadataProperty.Movement); + Assert.Null(t.Movement); + } + + [Fact] + public void TestRecordingDate() + { + var t = new MetadataTrack + { + RecordingDate = DateTime.Today + }; + t.RemoveMetadataPropertyValue(MetadataProperty.RecordingDate); + Assert.True(t.RecordingDate <= DateTime.MinValue); } } \ No newline at end of file diff --git a/Sandreas.AudioMetadata/AudioMetadata/IMetadataExtensions.cs b/Sandreas.AudioMetadata/AudioMetadata/IMetadataExtensions.cs index 60b64ea..5a379dd 100644 --- a/Sandreas.AudioMetadata/AudioMetadata/IMetadataExtensions.cs +++ b/Sandreas.AudioMetadata/AudioMetadata/IMetadataExtensions.cs @@ -175,6 +175,11 @@ public static void SetMetadataPropertyValue(this IMetadata metadata, MetadataPro /// private static object? GetPropertyValueThatLeadsToRemoval(this IMetadata metadata, MetadataProperty property) { + if (property == MetadataProperty.Movement) + { + return null; + } + if (metadata.GetMetadataPropertyType(property) == typeof(string)) { return ""; diff --git a/Sandreas.AudioMetadata/AudioMetadata/MetadataTrack.cs b/Sandreas.AudioMetadata/AudioMetadata/MetadataTrack.cs index 5cc201a..2980d2d 100644 --- a/Sandreas.AudioMetadata/AudioMetadata/MetadataTrack.cs +++ b/Sandreas.AudioMetadata/AudioMetadata/MetadataTrack.cs @@ -118,6 +118,10 @@ public string? Movement set { // movement MUST contain an integer value, which leads to an exception, if a string like 1.5 is stored // to store a non-integer value, use Part instead + if (value == "") + { + value = null; + } if (value == null || int.TryParse(value, out _)) { SeriesPart = value;