Browse Source

Make ImageMetaData(ImageMetaData other) constructor private

Ensure we use the Clone() method. This also lets us remove the nullability check.
af/merge-core
Jason Nelson 8 years ago
parent
commit
bfc4a68551
  1. 4
      src/ImageSharp/MetaData/ImageMetaData.cs
  2. 18
      tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs

4
src/ImageSharp/MetaData/ImageMetaData.cs

@ -43,10 +43,8 @@ namespace SixLabors.ImageSharp.MetaData
/// <param name="other"> /// <param name="other">
/// The other <see cref="ImageMetaData"/> to create this instance from. /// The other <see cref="ImageMetaData"/> to create this instance from.
/// </param> /// </param>
internal ImageMetaData(ImageMetaData other) private ImageMetaData(ImageMetaData other)
{ {
DebugGuard.NotNull(other, nameof(other));
this.HorizontalResolution = other.HorizontalResolution; this.HorizontalResolution = other.HorizontalResolution;
this.VerticalResolution = other.VerticalResolution; this.VerticalResolution = other.VerticalResolution;
this.RepeatCount = other.RepeatCount; this.RepeatCount = other.RepeatCount;

18
tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs

@ -1,8 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -20,10 +18,10 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void ConstructorImageMetaData() public void ConstructorImageMetaData()
{ {
ImageMetaData metaData = new ImageMetaData(); var metaData = new ImageMetaData();
ExifProfile exifProfile = new ExifProfile(); var exifProfile = new ExifProfile();
ImageProperty imageProperty = new ImageProperty("name", "value"); var imageProperty = new ImageProperty("name", "value");
metaData.ExifProfile = exifProfile; metaData.ExifProfile = exifProfile;
metaData.HorizontalResolution = 4; metaData.HorizontalResolution = 4;
@ -31,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests
metaData.Properties.Add(imageProperty); metaData.Properties.Add(imageProperty);
metaData.RepeatCount = 1; metaData.RepeatCount = 1;
ImageMetaData clone = new ImageMetaData(metaData); ImageMetaData clone = metaData.Clone();
Assert.Equal(exifProfile.ToByteArray(), clone.ExifProfile.ToByteArray()); Assert.Equal(exifProfile.ToByteArray(), clone.ExifProfile.ToByteArray());
Assert.Equal(4, clone.HorizontalResolution); Assert.Equal(4, clone.HorizontalResolution);
@ -43,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void HorizontalResolution() public void HorizontalResolution()
{ {
ImageMetaData metaData = new ImageMetaData(); var metaData = new ImageMetaData();
Assert.Equal(96, metaData.HorizontalResolution); Assert.Equal(96, metaData.HorizontalResolution);
metaData.HorizontalResolution=0; metaData.HorizontalResolution=0;
@ -59,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void VerticalResolution() public void VerticalResolution()
{ {
ImageMetaData metaData = new ImageMetaData(); var metaData = new ImageMetaData();
Assert.Equal(96, metaData.VerticalResolution); Assert.Equal(96, metaData.VerticalResolution);
metaData.VerticalResolution = 0; metaData.VerticalResolution = 0;
@ -75,11 +73,11 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void SyncProfiles() public void SyncProfiles()
{ {
ExifProfile exifProfile = new ExifProfile(); var exifProfile = new ExifProfile();
exifProfile.SetValue(ExifTag.XResolution, new Rational(200)); exifProfile.SetValue(ExifTag.XResolution, new Rational(200));
exifProfile.SetValue(ExifTag.YResolution, new Rational(300)); exifProfile.SetValue(ExifTag.YResolution, new Rational(300));
Image<Rgba32> image = new Image<Rgba32>(1, 1); var image = new Image<Rgba32>(1, 1);
image.MetaData.ExifProfile = exifProfile; image.MetaData.ExifProfile = exifProfile;
image.MetaData.HorizontalResolution = 400; image.MetaData.HorizontalResolution = 400;
image.MetaData.VerticalResolution = 500; image.MetaData.VerticalResolution = 500;

Loading…
Cancel
Save