From 492cf1b1bba9a0c6bd3dc2e566762315b014e0d0 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 29 Oct 2017 17:26:04 -0400 Subject: [PATCH] New: FormatAudioChannelsFixture.cs --- .../FormatAudioChannelsFixture.cs | 149 ++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 1 + 2 files changed, 150 insertions(+) create mode 100644 src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs diff --git a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs new file mode 100644 index 000000000..5de655cd5 --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs @@ -0,0 +1,149 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.MediaFiles.MediaInfo; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests +{ + [TestFixture] + public class FormatAudioChannelsFixture : TestBase + { + [Test] + public void should_subtract_one_from_AudioChannels_as_total_channels_if_LFE_in_AudioChannelPositionsText() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 6, + AudioChannelPositions = null, + AudioChannelPositionsText = "Front: L C R, Side: L R, LFE" + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m); + } + + [Test] + public void should_use_AudioChannels_as_total_channels_if_LFE_not_in_AudioChannelPositionsText() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = null, + AudioChannelPositionsText = "Front: L R" + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2); + } + + [Test] + public void should_return_0_if_schema_revision_is_less_than_3_and_other_properties_are_null() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = null, + AudioChannelPositionsText = null, + SchemaRevision = 2 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(0); + } + + [Test] + public void should_use_AudioChannels_if_schema_revision_is_3_and_other_properties_are_null() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = null, + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2); + } + + [Test] + public void should_sum_AudioChannelPositions() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = "2/0/0", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2); + } + + [Test] + public void should_sum_AudioChannelPositions_including_decimal() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = "3/2/0.1", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m); + } + + [Test] + public void should_cleanup_extraneous_text_from_AudioChannelPositions() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = "Object Based / 3/2/2.1", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m); + } + + [Test] + public void should_skip_empty_groups_in_AudioChannelPositions() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = " / 2/0/0.0", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2); + } + + [Test] + public void should_sum_first_series_of_numbers_from_AudioChannelPositions() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = "3/2/2.1 / 3/2/2.1", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m); + } + + [Test] + public void should_sum_dual_mono_representation_AudioChannelPositions() + { + var mediaInfoModel = new MediaInfoModel + { + AudioChannels = 2, + AudioChannelPositions = "1+1", + AudioChannelPositionsText = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2.0m); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index a887a3346..f28437013 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -253,6 +253,7 @@ +