private static void TestValue(IptcProfile profile, IptcTag tag, string expectedValue) { IptcValue value = profile.GetValue(tag); Assert.IsNotNull(value); Assert.AreEqual(expectedValue, value.Value); }
public void Encoding_SetToNull_NotChanged() { IptcValue value = GetIptcValue(); value.Encoding = null; Assert.IsNotNull(value.Encoding); }
public void Test_Properties() { IptcValue value = GetIptcValue(); Assert.AreEqual(IptcTag.Caption, value.Tag); Assert.AreEqual("Communications", value.ToString()); Assert.AreEqual("Communications", value.Value); Assert.AreEqual(14, value.ToByteArray().Length); }
public void Test_IEquatable() { IptcValue first = GetIptcValue(); IptcValue second = GetIptcValue(); Assert.IsTrue(first == second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(first.Equals((object)second)); }
public void IptcValue_CloneIsDeep() { // arrange var iptcValue = new IptcValue(IptcTag.Caption, System.Text.Encoding.UTF8, "test", true); // act IptcValue clone = iptcValue.DeepClone(); clone.Value = "changed"; // assert Assert.NotEqual(iptcValue.Value, clone.Value); }
public void CanDecodeImage_WithIptcDataAsLong <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { using Image <TPixel> image = provider.GetImage(TiffDecoder); IptcProfile iptcProfile = image.Frames.RootFrame.Metadata.IptcProfile; Assert.NotNull(iptcProfile); IptcValue byline = iptcProfile.Values.FirstOrDefault(data => data.Tag == IptcTag.Byline); Assert.NotNull(byline); Assert.Equal("Studio Mantyniemi", byline.Value); }
public void IptcProfile_SetDateValue_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var datetime = new DateTimeOffset(new DateTime(1994, 3, 17)); // act profile.SetDateTimeValue(tag, datetime); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal("19940317", actual.Value); }
public void Test_Encoding() { IptcValue value = GetIptcValue(); Assert.AreEqual("Communications", value.Value); value.Encoding = Encoding.UTF32; Assert.AreNotEqual("Communications", value.Value); value.Value = "Communications"; Assert.AreEqual("Communications", value.Value); value.Encoding = Encoding.UTF8; Assert.AreNotEqual("Communications", value.Value); }
public void IptcProfile_SetTimeValue_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var dateTimeUtc = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc); DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2)); // act profile.SetDateTimeValue(tag, dateTimeOffset); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal("161516+0200", actual.Value); }
public void IptcProfile_SetValue_WithStrictOption_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var value = new string('s', tag.MaxLength() + 1); var expectedLength = tag.MaxLength(); // act profile.SetValue(tag, value); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal(expectedLength, actual.Value.Length); }
public void Test_Encoding() { IptcValue value = GetIptcValue(); ExceptionAssert.Throws <ArgumentNullException>(delegate() { value.Encoding = null; }); Assert.AreEqual("Communications", value.Value); value.Encoding = Encoding.UTF32; Assert.AreNotEqual("Communications", value.Value); value.Value = "Communications"; Assert.AreEqual("Communications", value.Value); value.Encoding = Encoding.Default; Assert.AreNotEqual("Communications", value.Value); }
public void Test_ToString() { IptcValue value = GetIptcValue(); Assert.AreEqual("Communications", value.ToString()); Assert.AreEqual("Communications", value.ToString(Encoding.UTF8)); Assert.AreNotEqual("Communications", value.ToString(Encoding.UTF32)); value.Encoding = Encoding.UTF32; value.Value = "Test"; Assert.AreEqual("Test", value.ToString()); Assert.AreEqual("Test", value.ToString(Encoding.UTF32)); Assert.AreNotEqual("Test", value.ToString(Encoding.UTF8)); value.Value = ""; Assert.AreEqual("", value.ToString()); value.Value = "Test"; Assert.AreEqual("Test", value.ToString()); value.Value = null; Assert.AreEqual("", value.ToString()); }
public void Test_SetValue() { using (MemoryStream memStream = new MemoryStream()) { string credit = null; for (int i = 0; i < 255; i++) { credit += i.ToString() + "."; } using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG)) { IptcProfile profile = image.GetIptcProfile(); TestProfileValues(profile); IptcValue value = profile.GetValue(IptcTag.Title); TestValue(value, "Communications"); profile.SetValue(IptcTag.Title, "Magick.NET Title"); TestValue(value, "Magick.NET Title"); value = profile.GetValue(IptcTag.Title); TestValue(value, "Magick.NET Title"); value = profile.Values.FirstOrDefault(val => val.Tag == IptcTag.ReferenceNumber); Assert.IsNull(value); profile.SetValue(IptcTag.ReferenceNumber, "Magick.NET ReferenceNümber"); value = profile.GetValue(IptcTag.ReferenceNumber); TestValue(value, "Magick.NET ReferenceNümber"); profile.SetValue(IptcTag.Credit, credit); value = profile.GetValue(IptcTag.Credit); TestValue(value, credit); // Remove the 8bim profile so we can overwrite the iptc profile. image.RemoveProfile("8bim"); image.AddProfile(profile); image.Write(memStream); memStream.Position = 0; } using (IMagickImage image = new MagickImage(memStream)) { IptcProfile profile = image.GetIptcProfile(); TestProfileValues(profile, 19); IptcValue value = profile.GetValue(IptcTag.Title); TestValue(value, "Magick.NET Title"); value = profile.GetValue(IptcTag.ReferenceNumber); TestValue(value, "Magick.NET ReferenceNümber"); value = profile.GetValue(IptcTag.Credit); TestValue(value, credit); ExceptionAssert.Throws <ArgumentNullException>(delegate() { profile.SetValue(IptcTag.Caption, null, "Test"); }); profile.SetValue(IptcTag.Caption, "Test"); value = profile.Values.ElementAt(1); Assert.AreEqual("Test", value.Value); profile.SetValue(IptcTag.Caption, Encoding.UTF32, "Test"); Assert.AreEqual(Encoding.UTF32, value.Encoding); Assert.AreEqual("Test", value.Value); Assert.IsTrue(profile.RemoveValue(IptcTag.Caption)); Assert.IsFalse(profile.RemoveValue(IptcTag.Caption)); Assert.IsNull(profile.GetValue(IptcTag.Caption)); } } }
private static void TestValue(IptcValue value, string expected) { Assert.IsNotNull(value); Assert.AreEqual(expected, value.Value); }