diff --git a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs index 68b4812272..ef5217c5c8 100644 --- a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs +++ b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs @@ -1067,7 +1067,7 @@ private static string GetShutterSpeedValue(List allExifItems) return shutterSpeedString; } - private static int GetIsoSpeedValue(List allExifItems) + internal static int GetIsoSpeedValue(List allExifItems) { var subIfdItem = allExifItems.OfType().FirstOrDefault(); diff --git a/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs b/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs index 9c9afccc8b..c00899f9c7 100644 --- a/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs +++ b/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs @@ -1,9 +1,15 @@ using System.Collections.Generic; +using System.IO; +using System.Linq; using MetadataExtractor; +using MetadataExtractor.Formats.Exif; +using MetadataExtractor.Formats.Exif.Makernotes; using MetadataExtractor.Formats.Xmp; using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.readmeta.ReadMetaHelpers; +using starskytest.FakeCreateAn; using XmpCore.Impl; +using Directory = MetadataExtractor.Directory; namespace starskytest.starsky.foundation.readmeta.ReadMetaHelpers; @@ -72,4 +78,75 @@ public void GetXmpGeoAlt_ZeroAltitude_ReturnsZeroAltitude() Assert.AreEqual(0, result, 0.001); // Use an appropriate tolerance } + [TestMethod] + public void GetIsoSpeedValue_FromExifSubIfd_ReturnsIsoSpeed() + { + // Arrange + var subIfdItem = new ExifSubIfdDirectory(); + subIfdItem.Set(ExifDirectoryBase.TagIsoEquivalent, "400"); + + var allExifItems = new List { subIfdItem }; + + // Act + var result = ReadMetaExif.GetIsoSpeedValue(allExifItems); + + // Assert + Assert.AreEqual(400, result); + } + + [TestMethod] + public void GetIsoSpeedValue_FromCanonMakerNote_ReturnsIsoSpeed() + { + // Arrange + var canonMakerNoteDirectory = new CanonMakernoteDirectory(); + + // Magic Numbers + // 19 = ISO 400 + canonMakerNoteDirectory.Set(CanonMakernoteDirectory.CameraSettings.TagIso, "19"); + + var allExifItems = new List { canonMakerNoteDirectory }; + + // Act + var result = ReadMetaExif.GetIsoSpeedValue(allExifItems); + + // Assert + Assert.AreEqual(400, result); + } + + [TestMethod] + public void GetIsoSpeedValue_FromCanonMakerNote_AutoIso_ReturnsCalculatedIsoSpeed() + { + // Arrange + var canonMakerNoteDirectory = new CanonMakernoteDirectory(); + + // 15 is magic number for auto + canonMakerNoteDirectory.Set(CanonMakernoteDirectory.CameraSettings.TagIso, "15"); + canonMakerNoteDirectory.Set(CanonMakernoteDirectory.ShotInfo.TagAutoIso, "200"); + canonMakerNoteDirectory.Set(CanonMakernoteDirectory.ShotInfo.TagBaseIso, "400"); + + var allExifItems = new List { canonMakerNoteDirectory }; + + // Act + var result = ReadMetaExif.GetIsoSpeedValue(allExifItems); + + // Assert + Assert.AreEqual(800, result); // 400 * 200 / 100 = 800 + } + + [TestMethod] + public void GetIsoSpeedValue_FromXmp_ReturnsIsoSpeed() + { + // Arrange + var xmpStream = new MemoryStream(CreateAnImageA6600.Bytes); + + var allExifItems = ImageMetadataReader.ReadMetadata(xmpStream).ToList(); + + // Act + var result = ReadMetaExif.GetIsoSpeedValue(allExifItems); + + // Assert + Assert.AreEqual(800, result); + + xmpStream.Dispose(); + } }