From 6a5c04f7dde2a40ada2e0556e8571d52c974485c Mon Sep 17 00:00:00 2001 From: Gerard Gunnewijk Date: Tue, 22 Feb 2022 18:30:58 +0100 Subject: [PATCH] Fix default value of unitdesignation --- src/Synercoding.Primitives/PackageDetails.props | 8 +------- src/Synercoding.Primitives/UnitDesignation.cs | 10 +++++----- src/Synercoding.Primitives/Value.cs | 2 +- .../UnitDesignationTests.cs | 13 +++++++++++++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Synercoding.Primitives/PackageDetails.props b/src/Synercoding.Primitives/PackageDetails.props index 5d32ba5..14af0c7 100644 --- a/src/Synercoding.Primitives/PackageDetails.props +++ b/src/Synercoding.Primitives/PackageDetails.props @@ -10,13 +10,7 @@ Synercoding.Primitives Synercoding.Primitives Primitives with units attached (think mm, cm, in, px) that can be used for 2D graphics. - - Added extra default UnitDesignation to indicate a value is not properly initialized. - - Removed support for .NET 4.5.2 & .NET Core 2.1 - - Added support for .NET 4.8 & .NET 6.0 - - Improved XML docs. - - Added extra constructor to Spacing - - Added Pixels to ValueCreator - - Added Parse and TryParse methods to: Unit & Value + - Fix default value of unitdesignation \ No newline at end of file diff --git a/src/Synercoding.Primitives/UnitDesignation.cs b/src/Synercoding.Primitives/UnitDesignation.cs index 92e51b6..e5f579f 100644 --- a/src/Synercoding.Primitives/UnitDesignation.cs +++ b/src/Synercoding.Primitives/UnitDesignation.cs @@ -8,21 +8,21 @@ public enum UnitDesignation : byte /// /// Points, 72 per inch /// - Points, + Points = 1, /// /// Millimeters, 25.4 per inch /// - Millimeters, + Millimeters = 2, /// /// Centimeters, 2.54 per inch /// - Centimeters, + Centimeters = 3, /// /// Pixels, dependent on DPI /// - Pixels, + Pixels = 4, /// /// Inches /// - Inches + Inches = 5 } diff --git a/src/Synercoding.Primitives/Value.cs b/src/Synercoding.Primitives/Value.cs index 4d8224f..8280d40 100644 --- a/src/Synercoding.Primitives/Value.cs +++ b/src/Synercoding.Primitives/Value.cs @@ -37,7 +37,7 @@ public Value(double value, Unit unit) /// public Value ConvertTo(Unit unit) { - if ((byte)unit.Designation == 0) + if (unit.Designation == 0) throw new ArgumentException("The provided unit was not initialized.", nameof(unit)); if (Unit == unit) diff --git a/tests/Synercoding.Primitives.Tests/UnitDesignationTests.cs b/tests/Synercoding.Primitives.Tests/UnitDesignationTests.cs index 4bbc058..baeea32 100644 --- a/tests/Synercoding.Primitives.Tests/UnitDesignationTests.cs +++ b/tests/Synercoding.Primitives.Tests/UnitDesignationTests.cs @@ -20,4 +20,17 @@ public void Shortform_AllEnums_HaveShortform() // Assert // No NotImplementedException thrown! Jeej } + + [Fact] + public void DefaultValueIsNotDefined() + { + // Arrange + UnitDesignation value = 0; + + // Act + var result = Enum.IsDefined(value); + + // Assert + Assert.False(result); + } }