From 18fa128a42ee8756c98541a43237faadc1f6cb78 Mon Sep 17 00:00:00 2001 From: amsga <49681949+amsga@users.noreply.github.com> Date: Sat, 22 Feb 2025 09:42:00 +0800 Subject: [PATCH 1/2] Changed Classes to static with private fields. --- CHANGELOG.md | 7 + UUIDUtil/UUIDUtil.csproj | 2 +- UUIDUtil/UUIDv1.cs | 16 +- UUIDUtil/UUIDv3.cs | 6 +- UUIDUtil/UUIDv4.cs | 6 +- UUIDUtil/UUIDv5.cs | 6 +- UUIDUtil/UUIDv6.cs | 14 +- UUIDUtil/UUIDv7.cs | 12 +- UUIDUtil/Uuid.cs | 16 +- XUnitTestProjectUUID/UnitTestUuid.cs | 185 ++++++++++++++++-- .../XUnitTestProjectUUID.csproj | 6 +- 11 files changed, 200 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f73175a..97d1dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v2.1.0] - 2024-06-05 +[v2.1.0](https://github.com/TensionDev/UUIDUtil/releases/tag/v2.1.0) + +### Changed +- Changed Classes to static with private fields. + + ## [v2.1.0] - 2024-06-05 [v2.1.0](https://github.com/TensionDev/UUIDUtil/releases/tag/v2.1.0) diff --git a/UUIDUtil/UUIDUtil.csproj b/UUIDUtil/UUIDUtil.csproj index d1ea94e..dd2a301 100644 --- a/UUIDUtil/UUIDUtil.csproj +++ b/UUIDUtil/UUIDUtil.csproj @@ -7,7 +7,7 @@ true true TensionDev.UUID - 2.1.1 + 2.2.0 TensionDev amsga TensionDev TensionDev.UUID diff --git a/UUIDUtil/UUIDv1.cs b/UUIDUtil/UUIDv1.cs index c581caa..4ebf114 100644 --- a/UUIDUtil/UUIDv1.cs +++ b/UUIDUtil/UUIDv1.cs @@ -21,18 +21,14 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 1 (date-time and MAC address). /// - public class UUIDv1 + public static class UUIDv1 { - protected internal static System.Net.NetworkInformation.PhysicalAddress s_physicalAddress = System.Net.NetworkInformation.PhysicalAddress.None; - protected internal static Int32 s_clock = Int32.MinValue; - protected internal static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc); + private static System.Net.NetworkInformation.PhysicalAddress s_physicalAddress = System.Net.NetworkInformation.PhysicalAddress.None; + private static Int32 s_clock = Int32.MinValue; + private static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc); - protected internal static readonly Object s_initLock = new Object(); - protected internal static readonly Object s_clockLock = new Object(); - - protected UUIDv1() - { - } + private static readonly Object s_initLock = new Object(); + private static readonly Object s_clockLock = new Object(); /// /// Initialises a new GUID/UUID based on Version 1 (date-time and MAC address) diff --git a/UUIDUtil/UUIDv3.cs b/UUIDUtil/UUIDv3.cs index 8a4d0c5..78782a0 100644 --- a/UUIDUtil/UUIDv3.cs +++ b/UUIDUtil/UUIDv3.cs @@ -23,12 +23,8 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 3 (MD5 namespace name-based). /// - public class UUIDv3 + public static class UUIDv3 { - protected UUIDv3() - { - } - /// /// Initialises a new GUID/UUID based on Version 3 (MD5 namespace name-based) /// diff --git a/UUIDUtil/UUIDv4.cs b/UUIDUtil/UUIDv4.cs index 91f1a0a..ba5d12c 100644 --- a/UUIDUtil/UUIDv4.cs +++ b/UUIDUtil/UUIDv4.cs @@ -21,12 +21,8 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 4 (random). /// - public class UUIDv4 + public static class UUIDv4 { - protected UUIDv4() - { - } - /// /// Initialises a new GUID/UUID based on Version 4 (random) /// diff --git a/UUIDUtil/UUIDv5.cs b/UUIDUtil/UUIDv5.cs index e7d86f9..89935f0 100644 --- a/UUIDUtil/UUIDv5.cs +++ b/UUIDUtil/UUIDv5.cs @@ -23,12 +23,8 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 5 (SHA-1 namespace name-based). /// - public class UUIDv5 + public static class UUIDv5 { - protected UUIDv5() - { - } - /// /// Initialises a new GUID/UUID based on Version 5 (SHA-1 namespace name-based) /// diff --git a/UUIDUtil/UUIDv6.cs b/UUIDUtil/UUIDv6.cs index 2d052b8..07a23e8 100644 --- a/UUIDUtil/UUIDv6.cs +++ b/UUIDUtil/UUIDv6.cs @@ -21,17 +21,13 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 6 (date-time). /// - public class UUIDv6 + public static class UUIDv6 { - protected internal static Int32 s_clock = Int32.MinValue; - protected internal static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc); + private static Int32 s_clock = Int32.MinValue; + private static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc); - protected internal static readonly Object s_initLock = new Object(); - protected internal static readonly Object s_clockLock = new Object(); - - protected UUIDv6() - { - } + private static readonly Object s_initLock = new Object(); + private static readonly Object s_clockLock = new Object(); /// /// Initialises a new GUID/UUID based on Version 6 (date-time) diff --git a/UUIDUtil/UUIDv7.cs b/UUIDUtil/UUIDv7.cs index 90f08f9..0080baf 100644 --- a/UUIDUtil/UUIDv7.cs +++ b/UUIDUtil/UUIDv7.cs @@ -22,16 +22,12 @@ namespace TensionDev.UUID /// /// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 7 (date-time). /// - public class UUIDv7 + public static class UUIDv7 { - protected internal static readonly DateTime s_epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime s_epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - protected internal static UInt16 s_counter = 0; - protected internal static readonly Object s_counterLock = new Object(); - - protected UUIDv7() - { - } + private static UInt16 s_counter = 0; + private static readonly Object s_counterLock = new Object(); public enum GenerationMethod { diff --git a/UUIDUtil/Uuid.cs b/UUIDUtil/Uuid.cs index 9b2426b..b16e68b 100644 --- a/UUIDUtil/Uuid.cs +++ b/UUIDUtil/Uuid.cs @@ -27,7 +27,7 @@ public sealed class Uuid : IComparable, IEquatable private readonly uint _time_low; private readonly ushort _time_mid; private readonly ushort _time_hi_and_version; - private byte _clock_seq_hi_and_reserved; + private readonly byte _clock_seq_hi_and_reserved; private readonly byte _clock_seq_low; private readonly byte[] _node; @@ -355,10 +355,9 @@ public Guid ToVariant2() { byte newClockSeq = (byte)(_clock_seq_hi_and_reserved & 0x1F); newClockSeq = (byte)(newClockSeq | 0xC0); - Uuid variant2 = new Uuid(this.ToByteArray()) - { - _clock_seq_hi_and_reserved = newClockSeq - }; + byte[] array = ToByteArray(); + array[8] = newClockSeq; + Uuid variant2 = new Uuid(array); return variant2.ToGuid(); } @@ -373,10 +372,9 @@ public static Uuid ToVariant1(Guid guid) Uuid variant2 = new Uuid(guid.ToString()); byte newClockSeq = (byte)(variant2._clock_seq_hi_and_reserved & 0x3F); newClockSeq = (byte)(newClockSeq | 0x80); - Uuid variant1 = new Uuid(variant2.ToByteArray()) - { - _clock_seq_hi_and_reserved = newClockSeq - }; + byte[] array = variant2.ToByteArray(); + array[8] = newClockSeq; + Uuid variant1 = new Uuid(array); return variant1; } diff --git a/XUnitTestProjectUUID/UnitTestUuid.cs b/XUnitTestProjectUUID/UnitTestUuid.cs index a56fc4d..3075658 100644 --- a/XUnitTestProjectUUID/UnitTestUuid.cs +++ b/XUnitTestProjectUUID/UnitTestUuid.cs @@ -1,4 +1,5 @@ using System; +using TensionDev.UUID; using Xunit; namespace XUnitTestProjectUUID @@ -27,21 +28,21 @@ public void TestMaxUUID() public void TestConstructorByteArray1() { byte[] vs = null; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(vs); }); } [Fact] public void TestConstructorByteArray2() { byte[] vs = new byte[17]; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(vs); }); } [Fact] public void TestConstructorByteArray3() { string expectedUUID = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); Assert.Equal(expectedUUID, uuid.ToString()); @@ -51,14 +52,14 @@ public void TestConstructorByteArray3() public void TestConstructorString1() { string vs = null; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(vs); }); } [Fact] public void TestConstructorString2() { string vs = "(7d444840-9dc0-11d1-b245-5ffdce74fad2}"; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(vs); }); } [Fact] @@ -80,7 +81,7 @@ public void TestConstructorComponents1() byte d = byte.MaxValue; byte e = byte.MaxValue; byte[] f = null; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(a, b, c, d, e, f); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(a, b, c, d, e, f); }); } [Fact] @@ -92,7 +93,7 @@ public void TestConstructorComponents2() byte d = byte.MinValue; byte e = byte.MinValue; byte[] f = new byte[5]; - Assert.Throws(() => { TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(a, b, c, d, e, f); }); + Assert.Throws(() => { new TensionDev.UUID.Uuid(a, b, c, d, e, f); }); } [Fact] @@ -104,7 +105,7 @@ public void TestConstructorComponents3() ushort c = 4561; byte d = 178; byte e = 69; - byte[] f = new byte[] { 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] f = [0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(a, b, c, d, e, f); Assert.Equal(expectedUUID, uuid.ToString()); @@ -161,19 +162,30 @@ public void TestTryParse2() } [Fact] - public void TestCompareTo1() + public void TestCompareToObject() { - int expectedResult = 1; object other = new object(); string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; TensionDev.UUID.Uuid uuid = TensionDev.UUID.Uuid.Parse(vs); + int actualResult = uuid.CompareTo(other); + Assert.True(actualResult > 0); + } + + [Fact] + public void TestCompareToUUIDObject() + { + int expectedResult = 0; + string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; + object other = TensionDev.UUID.Uuid.Parse(vs); + TensionDev.UUID.Uuid uuid = TensionDev.UUID.Uuid.Parse(vs); + int actualResult = uuid.CompareTo(other); Assert.Equal(expectedResult, actualResult); } [Fact] - public void TestCompareTo2() + public void TestCompareToUUID() { int expectedResult = 0; string vs = "7d4448409dc011d1b2455ffdce74fad2"; @@ -184,6 +196,116 @@ public void TestCompareTo2() Assert.Equal(expectedResult, actualResult); } + [Fact] + public void TestCompareToTimeLow() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448309dc011d1b2455ffdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToTimeMid() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dd011d1b2455ffdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult > 0); + } + + [Fact] + public void TestCompareToTimeHigh() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011c1b2455ffdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToClockHigh() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1a2455ffdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToClockLow() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2555ffdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult > 0); + } + + [Fact] + public void TestCompareToNode1() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455efdce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToNode2() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffcce74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToNode3() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdcd74fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToNode4() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce73fad2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult < 0); + } + + [Fact] + public void TestCompareToNode5() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fbd2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult > 0); + } + + [Fact] + public void TestCompareToNode6() + { + TensionDev.UUID.Uuid uuid1 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74faf2"); + TensionDev.UUID.Uuid uuid2 = TensionDev.UUID.Uuid.Parse("7d4448409dc011d1b2455ffdce74fad2"); + + int actualResult = uuid1.CompareTo(uuid2); + Assert.True(actualResult > 0); + } + [Fact] public void TestEquals1() { @@ -209,7 +331,7 @@ public void TestEquals2() [Fact] public void TestToByteArray3() { - byte[] expected = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] expected = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); @@ -251,7 +373,7 @@ public void TestToVariant1() public void TestToString1() { string expected = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString(); @@ -262,7 +384,7 @@ public void TestToString1() public void TestToString2() { string expected = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString(null); @@ -273,7 +395,7 @@ public void TestToString2() public void TestToString3() { string expected = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString(String.Empty); @@ -284,7 +406,7 @@ public void TestToString3() public void TestToHexString4() { string expected = "7d4448409dc011d1b2455ffdce74fad2"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString("N"); @@ -295,7 +417,7 @@ public void TestToHexString4() public void TestToString5() { string expected = "{7d444840-9dc0-11d1-b245-5ffdce74fad2}"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString("B"); @@ -306,7 +428,7 @@ public void TestToString5() public void TestToString6() { string expected = "(7d444840-9dc0-11d1-b245-5ffdce74fad2)"; - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); string actual = uuid.ToString("P"); @@ -316,7 +438,7 @@ public void TestToString6() [Fact] public void TestToString7() { - byte[] vs = new byte[] { 0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2 }; + byte[] vs = [0x7d, 0x44, 0x48, 0x40, 0x9d, 0xc0, 0x11, 0xd1, 0xb2, 0x45, 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2]; TensionDev.UUID.Uuid uuid = new TensionDev.UUID.Uuid(vs); Assert.Throws(() => { uuid.ToString("C"); }); @@ -329,7 +451,7 @@ public void TestOperatorEquals1() string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; TensionDev.UUID.Uuid uuid = TensionDev.UUID.Uuid.Parse(vs); - bool actualResult = uuid == other; + bool actualResult = (uuid == other); Assert.False(actualResult); } @@ -348,13 +470,34 @@ public void TestOperatorEquals2() public void TestOperatorEquals3() { TensionDev.UUID.Uuid other = null; + TensionDev.UUID.Uuid uuid = null; + + bool actualResult = uuid == other; + Assert.True(actualResult); + } + + [Fact] + public void TestOperatorEquals4() + { string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; + TensionDev.UUID.Uuid other = null; TensionDev.UUID.Uuid uuid = TensionDev.UUID.Uuid.Parse(vs); bool actualResult = uuid == other; Assert.False(actualResult); } + [Fact] + public void TestOperatorEquals5() + { + string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; + TensionDev.UUID.Uuid other = TensionDev.UUID.Uuid.Parse(vs); + TensionDev.UUID.Uuid uuid = null; + + bool actualResult = uuid == other; + Assert.False(actualResult); + } + [Fact] public void TestOperatorNotEquals1() { @@ -362,7 +505,7 @@ public void TestOperatorNotEquals1() string vs = "7d444840-9dc0-11d1-b245-5ffdce74fad2"; TensionDev.UUID.Uuid uuid = TensionDev.UUID.Uuid.Parse(vs); - bool actualResult = uuid != other; + bool actualResult = (uuid != other); Assert.True(actualResult); } diff --git a/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj b/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj index 5cab2af..46b58ae 100644 --- a/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj +++ b/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj @@ -8,12 +8,12 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From dd8efc436387ee3734f9317c7577bde61d226495 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 22 Feb 2025 01:44:01 +0000 Subject: [PATCH 2/2] Bump Microsoft.NET.Test.Sdk from 17.12.0 to 17.13.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.12.0 to 17.13.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.12.0...v17.13.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- XUnitTestProjectUUID/XUnitTestProjectUUID.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj b/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj index 46b58ae..84b124e 100644 --- a/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj +++ b/XUnitTestProjectUUID/XUnitTestProjectUUID.csproj @@ -7,7 +7,7 @@ - + all