diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
index 47c8012..569151b 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -54,10 +54,10 @@ jobs:
fi
echo "version_with_suffix_dst=${version_with_suffix}" >> $GITHUB_ENV
echo "has_suffix_dst=${has_suffix}" >> $GITHUB_ENV
- - name: Setup .NET Core SDK 8.0.101
+ - name: Setup .NET Core SDK 9.0.100
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.101
+ dotnet-version: 9.0.100
- name: Checkout source branch back
uses: actions/checkout@v4
with:
@@ -69,7 +69,7 @@ jobs:
shell: bash
run: |
dotnet publish -c Release ./tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj
- source_more_than_target=$(dotnet ./tools/Dodo.Primitives.Tools.CompareVersions/bin/Release/net8.0/publish/Dodo.Primitives.Tools.CompareVersions.dll "${source_version}" "${target_version}")
+ source_more_than_target=$(dotnet ./tools/Dodo.Primitives.Tools.CompareVersions/bin/Release/net9.0/publish/Dodo.Primitives.Tools.CompareVersions.dll "${source_version}" "${target_version}")
last_exit_code=$(printf "%d" $?)
source_more_than_target=$(printf "%s" $source_more_than_target)
if [ "$last_exit_code" -ne 0 ]
@@ -107,14 +107,18 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- - name: Setup .NET Core SDK 6.0.418
+ - name: Setup .NET Core SDK 6.0.428
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 6.0.418
- - name: Setup .NET Core SDK 8.0.101
+ dotnet-version: 6.0.428
+ - name: Setup .NET Core SDK 8.0.404
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.101
+ dotnet-version: 8.0.404
+ - name: Setup .NET Core SDK 9.0.100
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 9.0.100
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
@@ -136,7 +140,15 @@ jobs:
PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw"
echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV
- echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV
+ echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9nohw"
+ echo "cover_net9_nohw=${PATH_NET9_NOHW}" >> $GITHUB_ENV
+ echo "cover_net9_nohw_merge=${PATH_NET9_NOHW}.net9.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9hw"
+ echo "cover_net9_hw=${PATH_NET9_HW}" >> $GITHUB_ENV
+ echo "cover_net9_hw_merge=${PATH_NET9_HW}.net9.0.info" >> $GITHUB_ENV
- name: Run .NET 6 tests without Hardware Intrinsics
shell: bash
run: |
@@ -184,9 +196,34 @@ jobs:
export CoverletOutput=${{ env.cover_net8_hw }}
export MergeWith=${{ env.cover_net8_nohw_merge }}
dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0
+ - name: Run .NET 9 tests without Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=0
+ export DOTNET_EnableHWIntrinsic=0
+ export COMPlus_ReadyToRun=0
+ export DOTNET_ReadyToRun=0
+ export CollectCoverage=true
+ export CoverletOutputFormat=json
+ export CoverletOutput=${{ env.cover_net9_nohw }}
+ export MergeWith=${{ env.cover_net8_hw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
+ - name: Run .NET 9 tests with Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=1
+ export DOTNET_EnableHWIntrinsic=1
+ unset COMPlus_ReadyToRun
+ unset DOTNET_ReadyToRun
+ export CollectCoverage=true
+ export CoverletOutputFormat=lcov
+ export CoverletOutput=${{ env.cover_net9_hw }}
+ export MergeWith=${{ env.cover_net9_nohw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
- name: Upload coverage reports to Codecov
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
- files: ${{ env.cover_net8_hw_merge }}
\ No newline at end of file
+ fail_ci_if_error: true
+ files: ${{ env.cover_net9_hw_merge }}
\ No newline at end of file
diff --git a/.github/workflows/push_to_main.yml b/.github/workflows/push_to_main.yml
index 8b91bf7..d7b2114 100644
--- a/.github/workflows/push_to_main.yml
+++ b/.github/workflows/push_to_main.yml
@@ -44,14 +44,18 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- - name: Setup .NET Core SDK 6.0.418
+ - name: Setup .NET Core SDK 6.0.428
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 6.0.418
- - name: Setup .NET Core SDK 8.0.101
+ dotnet-version: 6.0.428
+ - name: Setup .NET Core SDK 8.0.404
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.101
+ dotnet-version: 8.0.404
+ - name: Setup .NET Core SDK 9.0.100
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 9.0.100
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
@@ -73,7 +77,15 @@ jobs:
PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw"
echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV
- echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV
+ echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9nohw"
+ echo "cover_net9_nohw=${PATH_NET9_NOHW}" >> $GITHUB_ENV
+ echo "cover_net9_nohw_merge=${PATH_NET9_NOHW}.net9.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9hw"
+ echo "cover_net9_hw=${PATH_NET9_HW}" >> $GITHUB_ENV
+ echo "cover_net9_hw_merge=${PATH_NET9_HW}.net9.0.info" >> $GITHUB_ENV
- name: Run .NET 6 tests without Hardware Intrinsics
shell: bash
run: |
@@ -121,12 +133,37 @@ jobs:
export CoverletOutput=${{ env.cover_net8_hw }}
export MergeWith=${{ env.cover_net8_nohw_merge }}
dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0
+ - name: Run .NET 9 tests without Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=0
+ export DOTNET_EnableHWIntrinsic=0
+ export COMPlus_ReadyToRun=0
+ export DOTNET_ReadyToRun=0
+ export CollectCoverage=true
+ export CoverletOutputFormat=json
+ export CoverletOutput=${{ env.cover_net9_nohw }}
+ export MergeWith=${{ env.cover_net8_hw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
+ - name: Run .NET 9 tests with Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=1
+ export DOTNET_EnableHWIntrinsic=1
+ unset COMPlus_ReadyToRun
+ unset DOTNET_ReadyToRun
+ export CollectCoverage=true
+ export CoverletOutputFormat=lcov
+ export CoverletOutput=${{ env.cover_net9_hw }}
+ export MergeWith=${{ env.cover_net9_nohw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
- name: Upload coverage reports to Codecov
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
- files: ${{ env.cover_net8_hw_merge }}
+ fail_ci_if_error: true
+ files: ${{ env.cover_net9_hw_merge }}
release:
name: Create release
runs-on: ubuntu-latest
@@ -155,12 +192,12 @@ jobs:
echo "release_version_with_suffix=${version_with_suffix}" >> $GITHUB_ENV
echo "release_has_suffix=${has_suffix}" >> $GITHUB_ENV
- name: Create release
- uses: ncipollo/release-action@v1.13.0
+ uses: ncipollo/release-action@v1.14.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ env.release_version_with_suffix }}
- release_name: Release ${{ env.release_version_with_suffix }}
+ name: Release ${{ env.release_version_with_suffix }}
draft: true
prerelease: ${{ env.release_has_suffix }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7431191..a70ebfd 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -14,14 +14,18 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- - name: Setup .NET Core SDK 6.0.418
+ - name: Setup .NET Core SDK 6.0.428
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 6.0.418
- - name: Setup .NET Core SDK 8.0.101
+ dotnet-version: 6.0.428
+ - name: Setup .NET Core SDK 8.0.404
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 8.0.101
+ dotnet-version: 8.0.404
+ - name: Setup .NET Core SDK 9.0.100
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 9.0.100
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
@@ -43,7 +47,15 @@ jobs:
PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw"
echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV
- echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV
+ echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9nohw"
+ echo "cover_net9_nohw=${PATH_NET9_NOHW}" >> $GITHUB_ENV
+ echo "cover_net9_nohw_merge=${PATH_NET9_NOHW}.net9.0.json" >> $GITHUB_ENV
+
+ PATH_NET9_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net9hw"
+ echo "cover_net9_hw=${PATH_NET9_HW}" >> $GITHUB_ENV
+ echo "cover_net9_hw_merge=${PATH_NET9_HW}.net9.0.info" >> $GITHUB_ENV
- name: Run .NET 6 tests without Hardware Intrinsics
shell: bash
run: |
@@ -91,46 +103,45 @@ jobs:
export CoverletOutput=${{ env.cover_net8_hw }}
export MergeWith=${{ env.cover_net8_nohw_merge }}
dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0
+ - name: Run .NET 9 tests without Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=0
+ export DOTNET_EnableHWIntrinsic=0
+ export COMPlus_ReadyToRun=0
+ export DOTNET_ReadyToRun=0
+ export CollectCoverage=true
+ export CoverletOutputFormat=json
+ export CoverletOutput=${{ env.cover_net9_nohw }}
+ export MergeWith=${{ env.cover_net8_hw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
+ - name: Run .NET 9 tests with Hardware Intrinsics
+ shell: bash
+ run: |
+ export COMPlus_EnableHWIntrinsic=1
+ export DOTNET_EnableHWIntrinsic=1
+ unset COMPlus_ReadyToRun
+ unset DOTNET_ReadyToRun
+ export CollectCoverage=true
+ export CoverletOutputFormat=lcov
+ export CoverletOutput=${{ env.cover_net9_hw }}
+ export MergeWith=${{ env.cover_net9_nohw_merge }}
+ dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net9.0
- name: Upload coverage reports to Codecov
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
- files: ${{ env.cover_net8_hw_merge }}
+ fail_ci_if_error: true
+ files: ${{ env.cover_net9_hw_merge }}
- name: Build and publish library to NuGet
shell: bash
run: |
dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net6.0
dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net8.0
- dotnet pack -c Release --no-restore --no-build --output out ./src/Dodo.Primitives/Dodo.Primitives.csproj
+ dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net9.0
+ dotnet pack -c Release --output out ./src/Dodo.Primitives/Dodo.Primitives.csproj
rm ./out/*.symbols.nupkg
PATH_TO_PACKAGE=$(readlink -f ./out/*.nupkg)
dotnet nuget push "$PATH_TO_PACKAGE" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
- - uses: actions/upload-artifact@v4
- with:
- name: NuGet package
- path: out/
- upload-release-assets:
- name: Upload release assets
- runs-on: ubuntu-latest
- needs: build-test-and-publish
- steps:
- - uses: actions/download-artifact@v4
- with:
- name: NuGet package
- path: out
- - name: Get package
- shell: bash
- run: |
- OUT_PACKAGE_NAME="$(ls out/)"
- echo "out_package_name=$OUT_PACKAGE_NAME" >> $GITHUB_ENV
- - name: Upload release assets
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ github.event.release.upload_url }}
- asset_path: ./out/${{ env.out_package_name }}
- asset_name: ${{ env.out_package_name }}
- asset_content_type: application/zip
diff --git a/global.json b/global.json
index cb33872..712ccf1 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "8.0.101",
+ "version": "9.0.100",
"rollForward": "latestPatch"
}
}
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 8e60057..baaf847 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -1,6 +1,6 @@
- 3.0.0
-
+ 4.0.0
+ beta1
diff --git a/src/Dodo.Primitives.Benchmarks/Benchmarks/GeneratorBenchmarks.cs b/src/Dodo.Primitives.Benchmarks/Benchmarks/GeneratorBenchmarks.cs
index 3564f40..2a78531 100644
--- a/src/Dodo.Primitives.Benchmarks/Benchmarks/GeneratorBenchmarks.cs
+++ b/src/Dodo.Primitives.Benchmarks/Benchmarks/GeneratorBenchmarks.cs
@@ -13,20 +13,14 @@ namespace Dodo.Primitives.Benchmarks.Benchmarks;
public class GeneratorBenchmarks
{
[Benchmark]
- public Guid guid_New()
+ public Guid guid_CreateVersion7()
{
- return Guid.NewGuid();
+ return Guid.CreateVersion7();
}
[Benchmark]
- public Uuid uuid_NewTimeBased()
+ public Uuid uuid_CreateVersion7()
{
- return Uuid.NewTimeBased();
- }
-
- [Benchmark]
- public Uuid uuid_NewMySqlOptimized()
- {
- return Uuid.NewMySqlOptimized();
+ return Uuid.CreateVersion7();
}
}
diff --git a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj
index 0890069..0d8e575 100644
--- a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj
+++ b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj
@@ -2,7 +2,7 @@
Exe
- net8.0
+ net9.0
288ccf26-65fb-4cc8-932b-01f0a458940a
enable
disable
@@ -15,7 +15,7 @@
-
+
diff --git a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj
index 263a062..4a57e64 100644
--- a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj
+++ b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj
@@ -1,7 +1,7 @@
- net6.0;net8.0
+ net6.0;net8.0;net9.0
4c9485a5-fcb5-4361-8c46-c99669d5b22e
11.0
enable
@@ -13,16 +13,19 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/src/Dodo.Primitives.Tests/Hex/HexTests.cs b/src/Dodo.Primitives.Tests/Hex/HexTests.cs
deleted file mode 100644
index 4c2cff4..0000000
--- a/src/Dodo.Primitives.Tests/Hex/HexTests.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-using System;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-
-namespace Dodo.Primitives.Tests.Hex;
-
-public class HexTests
-{
- #region IsHexString
-
- [TestCaseSource(typeof(HexTestsData), nameof(HexTestsData.ValidHexStrings))]
- public void IsHexStringCorrect(string validHexString)
- {
- Assert.True(Primitives.Hex.IsHexString(validHexString));
- }
-
- [Test]
- public void IsHexStringReturnFalseWhenNull()
- {
- Assert.False(Primitives.Hex.IsHexString(null));
- }
-
- [Test]
- public void IsHexStringReturnFalseWhenOddStringLength()
- {
- Assert.False(Primitives.Hex.IsHexString("F"));
- }
-
- [TestCaseSource(typeof(HexTestsData), nameof(HexTestsData.BrokenHexStrings))]
- public void IsHexStringReturnFalseWithBrokenStrings(string brokenHexString)
- {
- Assert.False(Primitives.Hex.IsHexString(brokenHexString));
- }
-
- #endregion
-
- #region GetBytes
-
- [TestCaseSource(typeof(HexTestsData), nameof(HexTestsData.ValidHexStrings))]
- public void CanGetBytesCorrect(string validHexString)
- {
- byte[] expected = HexStringToByteArrayNaive(validHexString);
- byte[]? actual = Primitives.Hex.GetBytes(validHexString);
- Assert.Multiple(() =>
- {
- Assert.NotNull(expected);
- Assert.NotNull(actual);
- Assert.True(expected!.Length == actual!.Length);
- Assert.True(expected.SequenceEqual(actual));
- });
- }
-
- [Test]
- public void CanGetBytesReturnNullWhenNull()
- {
- Assert.Null(Primitives.Hex.GetBytes(null!));
- }
-
- [Test]
- public void CanGetBytesReturnNullWhenOddStringLength()
- {
- Assert.Null(Primitives.Hex.GetBytes("fff"));
- }
-
- [TestCaseSource(typeof(HexTestsData), nameof(HexTestsData.BrokenHexStrings))]
- public void CanGetBytesReturnNullWithBrokenStrings(string brokenHexString)
- {
- Assert.Null(Primitives.Hex.GetBytes(brokenHexString));
- }
-
- #endregion
-
- #region GetString
-
- [TestCaseSource(typeof(HexTestsData), nameof(HexTestsData.ValidByteArrays))]
- public void CanGetStringCorrect(byte[] bytesToHex)
- {
- string expected = ByteArrayToHexStringNaive(bytesToHex);
- string? actual = Primitives.Hex.GetString(bytesToHex);
- Assert.AreEqual(expected, actual);
- }
-
- [Test]
- public void CanGetStringReturnNullWhenArrayIsNull()
- {
- Assert.Null(Primitives.Hex.GetString(null!));
- }
-
- [Test]
- public void CanGetStringReturnEmptyStringWhenArrayIsEmpty()
- {
- Assert.AreEqual(string.Empty, Primitives.Hex.GetString(new byte[] { }));
- }
-
- #endregion
-
- #region Utils
-
- private static byte[] HexStringToByteArrayNaive(string hex)
- {
- return Enumerable.Range(0, hex.Length)
- .Where(x => x % 2 == 0)
- .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
- .ToArray();
- }
-
- private static string ByteArrayToHexStringNaive(byte[] bytes)
- {
- var builder = new StringBuilder(bytes.Length * 2);
- foreach (byte b in bytes)
- {
- builder.AppendFormat("{0:x2}", b);
- }
-
- return builder.ToString();
- }
-
- #endregion
-}
diff --git a/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs b/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs
deleted file mode 100644
index f31bd4a..0000000
--- a/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-
-namespace Dodo.Primitives.Tests.Hex;
-
-[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
-public static class HexTestsData
-{
- public static readonly string[] ValidHexStrings =
- {
- "De",
- "Dead",
- "DeadBeef1337",
- "1B6f",
- "1b6f",
- "1B6F",
- "9C045ABE1B6211EA978F2E728CE88125",
- "9c045abe1b6211ea978f2e728ce88125"
- };
-
- public static readonly string[] BrokenHexStrings = GetBrokenHexStrings(ValidHexStrings);
-
- public static readonly byte[][] ValidByteArrays =
- {
- new byte[]
- {
- 13,
- 37,
- 42
- },
- new byte[]
- {
- 42,
- 43,
- 43,
- 34,
- 35,
- 9,
- 12,
- 19,
- 93
- },
- Enumerable.Repeat((byte) 42, 17935).Select((b, index) =>
- {
- byte result;
- unchecked
- {
- result = (byte) (b + (byte) (index % byte.MaxValue));
- }
-
- return result;
- }).ToArray()
- };
-
- private static unsafe string[] GetBrokenHexStrings(string[] strings)
- {
- var resultStrings = new string[strings.Length];
- for (var i = 0; i < strings.Length; i++)
- {
- var brokenString = new string(strings[i].ToCharArray());
- fixed (char* brokenPtr = brokenString)
- {
- var bytePtr = (byte*) brokenPtr;
- int problemType = i % 3;
- switch (problemType)
- {
- case 0:
- bytePtr[0] = 47;
- break;
- case 1:
- bytePtr[0] = 104;
- break;
- default:
- bytePtr[1] = 47;
- break;
- }
- }
-
- resultStrings[i] = brokenString;
- }
-
- return resultStrings;
- }
-}
diff --git a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs
index 1e6441e..7fa37fc 100644
--- a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs
@@ -1895,6 +1895,85 @@ public static object[] RightLessThanLeft()
return results.ToArray();
}
+ public static object[] GetAllUuidVersions()
+ {
+ return new object[]
+ {
+ new object[]
+ {
+ "C232AB00-9414-11EC-B3C8-9F6BDECED846",
+ 1
+ },
+ new object[]
+ {
+ "000003e8-a2bd-21ef-8f00-325096b39f47",
+ 2
+ },
+ new object[]
+ {
+ "5df41881-3aed-3515-88a7-2f4a814cf09e",
+ 3
+ },
+ new object[]
+ {
+ "919108f7-52d1-4320-9bac-f847db4148a8",
+ 4
+ },
+ new object[]
+ {
+ "2ed6657d-e927-568b-95e1-2665a8aea6a2",
+ 5
+ },
+ new object[]
+ {
+ "1EC9414C-232A-6B00-B3C8-9F6BDECED846",
+ 6
+ },
+ new object[]
+ {
+ "017F22E2-79B0-7CC3-98C4-DC0C0C07398F",
+ 7
+ },
+ new object[]
+ {
+ "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0",
+ 8
+ }
+ };
+ }
+
+ public static object[] GetAllUuidVariants()
+ {
+ return new object[]
+ {
+ new object[]
+ {
+ "01932c7c3db674000f1aa8ecd44dba8e",
+ 0 //0b[0000]1111 >> 4 = 0b[0000] aka [ 0 x x x ] - Reserved. Network Computing System (NCS) backward compatibility, and includes Nil UUID as per Section 5.9 (RFC9562).
+ },
+ new object[]
+ {
+ "01932c7db4f974c78f4112fec6261162",
+ 8 //0b[1000]1111 >> 4 = 0b[1000] aka [ 1 0 x x ] - The variant specified in this document (RFC9562).
+ },
+ new object[]
+ {
+ "01932c7e84f2701bcf01138af0833ce7",
+ 12 //0b[1100]1111 >> 4 = 0b[1100] aka [ 1 1 0 x ] - Reserved. Microsoft Corporation backward compatibility (RFC9562).
+ },
+ new object[]
+ {
+ "01932c7fafd776a2efd103f756df5a38",
+ 14 //0b[1110]1111 >> 4 = 0b[1110] aka [ 1 1 1 x ] - Reserved for future definition and includes Max UUID as per Section 5.10 (RFC9562).
+ },
+ new object[]
+ {
+ "01932c834499700bff144503c6259bdc",
+ 15 //0b[1111]1111 >> 4 = 0b[1111] aka [ 1 1 1 x ] - Reserved for future definition and includes Max UUID as per Section 5.10 (RFC9562).
+ }
+ };
+ }
+
// ReSharper disable once InconsistentNaming
public static class Formats
{
diff --git a/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs
index 535d320..6a9d2a3 100644
--- a/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs
@@ -22,11 +22,14 @@ public async Task ReadCorrectDictionaryPropertyUuid()
stream,
options
);
- Assert.NotNull(result);
+ Assert.That(result, Is.Not.Null);
if (result != null)
{
- Assert.IsTrue(result.ContainsKey(expectedUuid));
- Assert.AreEqual(1, result[expectedUuid]);
+ Assert.Multiple(() =>
+ {
+ Assert.That(result.ContainsKey(expectedUuid));
+ Assert.That(result[expectedUuid], Is.EqualTo(1));
+ });
}
}
@@ -45,7 +48,7 @@ public void WriteCorrectDictionaryPropertyUuid()
string actualValue = JsonSerializer.Serialize(target, options);
- Assert.AreEqual(expectedValue, actualValue);
+ Assert.That(actualValue, Is.EqualTo(expectedValue));
}
public static Stream GenerateStreamFromString(string s)
diff --git a/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterTests.cs b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterTests.cs
index 60f845a..4f0e47b 100644
--- a/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterTests.cs
@@ -20,7 +20,7 @@ public void ReadCorrect()
Uuid actualUuid = converter.Read(ref reader, typeof(Uuid), null);
#pragma warning restore 8625
- Assert.AreEqual(expectedUuid, actualUuid);
+ Assert.That(actualUuid, Is.EqualTo(expectedUuid));
}
[Test]
@@ -38,6 +38,6 @@ public void WriteCorrect()
writer.Flush();
string actualValue = Encoding.UTF8.GetString(stream.ToArray());
- Assert.AreEqual(expectedValue, actualValue);
+ Assert.That(actualValue, Is.EqualTo(expectedValue));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/Utf8JsonReaderUuidExtensionsTests.cs b/src/Dodo.Primitives.Tests/Uuids/Utf8JsonReaderUuidExtensionsTests.cs
index 36c5d1a..081b21e 100644
--- a/src/Dodo.Primitives.Tests/Uuids/Utf8JsonReaderUuidExtensionsTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/Utf8JsonReaderUuidExtensionsTests.cs
@@ -26,7 +26,7 @@ public void GetUuidTokenTypeStringButNotUuidThrowsFormatException()
reader.Read(); // "hsadgfhygsdaf"
reader.GetUuid();
});
- Assert.AreEqual("System.Text.Json.Rethrowable", ex?.Source);
+ Assert.That(ex?.Source, Is.EqualTo("System.Text.Json.Rethrowable"));
}
[Test]
@@ -39,7 +39,7 @@ public void TryGetUuidTokenTypeStartObjectThrowsInvalidOperationException()
reader.Read();
reader.TryGetUuid(out _);
});
- Assert.AreEqual("System.Text.Json.Rethrowable", ex?.Source);
+ Assert.That(ex?.Source, Is.EqualTo("System.Text.Json.Rethrowable"));
}
[Test]
@@ -61,8 +61,8 @@ public void TryGetUuidTooLongInputStringWithValueSequenceNotParsed()
reader.Read(); // "value"
reader.Read(); // UuidTooLongEscapedValue
- Assert.False(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(Uuid.Empty, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.False);
+ Assert.That(actualUuid, Is.EqualTo(Uuid.Empty));
}
[Test]
@@ -80,8 +80,8 @@ public void TryGetUuidCorrectUnescapedStringNoValueSequence()
reader.Read(); // "value"
reader.Read(); // UuidEscapedValue
- Assert.True(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(expectedUuid, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.True);
+ Assert.That(actualUuid, Is.EqualTo(expectedUuid));
}
});
}
@@ -101,8 +101,8 @@ public void TryGetUuidCorrectEscapedStringNoValueSequence()
reader.Read(); // "value"
reader.Read(); // UuidEscapedValue
- Assert.True(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(expectedUuid, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.True);
+ Assert.That(actualUuid, Is.EqualTo(expectedUuid));
}
});
}
@@ -124,8 +124,8 @@ public void TryGetUuidCorrectUnescapedStringWithValueSequence()
reader.Read(); // "value"
reader.Read(); // UuidEscapedValue
- Assert.True(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(expectedUuid, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.True);
+ Assert.That(actualUuid, Is.EqualTo(expectedUuid));
}
});
}
@@ -147,8 +147,8 @@ public void TryGetUuidCorrectEscapedStringWithValueSequence()
reader.Read(); // "value"
reader.Read(); // UuidEscapedValue
- Assert.True(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(expectedUuid, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid));
+ Assert.That(actualUuid, Is.EqualTo(expectedUuid));
}
});
}
@@ -196,8 +196,8 @@ public void TryGetUuidTooLongEscapedStringAfterUnescapeNotParsed()
reader.Read(); // "value"
reader.Read(); // UuidTooLongEscapedValue
- Assert.False(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(Uuid.Empty, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.False);
+ Assert.That(actualUuid, Is.EqualTo(Uuid.Empty));
}
[Test]
@@ -217,8 +217,8 @@ public void TryGetUuidTooLongInputStringNotParsed()
reader.Read(); // "value"
reader.Read(); // UuidTooLongEscapedValue
- Assert.False(reader.TryGetUuid(out Uuid actualUuid));
- Assert.AreEqual(Uuid.Empty, actualUuid);
+ Assert.That(reader.TryGetUuid(out Uuid actualUuid), Is.False);
+ Assert.That(actualUuid, Is.EqualTo(Uuid.Empty));
}
internal class MemorySegment : ReadOnlySequenceSegment
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs
index 86aa8c5..9272f8f 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs
@@ -17,7 +17,7 @@ public void CompareToObjectCorrect(
int compareResult = uuid.CompareTo(uuidToCompareAsObject);
- Assert.AreEqual(expectedResult, compareResult);
+ Assert.That(compareResult, Is.EqualTo(expectedResult));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -27,7 +27,7 @@ public void CompareToObjectNullShouldReturn1(byte[] correctBytes)
int compareResult = uuid.CompareTo(null);
- Assert.AreEqual(1, compareResult);
+ Assert.That(compareResult, Is.EqualTo(1));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -52,6 +52,6 @@ public void CompareToUuidCorrect(
int compareResult = uuid.CompareTo(uuidToCompareAsObject);
- Assert.AreEqual(expectedResult, compareResult);
+ Assert.That(compareResult, Is.EqualTo(expectedResult));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidCreateVersion7Tests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidCreateVersion7Tests.cs
new file mode 100644
index 0000000..7671c1b
--- /dev/null
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidCreateVersion7Tests.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Buffers.Binary;
+using NUnit.Framework;
+
+namespace Dodo.Primitives.Tests.Uuids;
+
+public class UuidCreateVersion7Tests
+{
+ [Test]
+ public void CreateVersion7WithDateTimeOffset()
+ {
+ DateTimeOffset startDate = DateTimeOffset.FromUnixTimeMilliseconds(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
+ Assert.Multiple(() =>
+ {
+ long startTicks = startDate.UtcTicks;
+ for (var i = 0; i <= TimeSpan.TicksPerMillisecond; i++)
+ {
+ long ticks = startTicks + i;
+ var expectedDate = new DateTimeOffset(ticks, TimeSpan.Zero);
+ var uuid = Uuid.CreateVersion7(expectedDate);
+ DateTimeOffset actualDate = ExtractDateTimeOffset(uuid);
+ Assert.That(actualDate, Is.EqualTo(expectedDate));
+ }
+ });
+ }
+
+ [Test]
+ public void CreateVersion7WithDateTimeOffset_ShouldThrows_WhenDateTimeOffsetIsLowerThanUnixEpoch()
+ {
+ long ticks = DateTimeOffset.UnixEpoch.UtcTicks - 1;
+ Assert.Throws(() =>
+ Uuid.CreateVersion7(new DateTimeOffset(ticks, TimeSpan.Zero)));
+ }
+
+ [Test]
+ public void CreateVersion7WithDateTimeOffset_DoesNotThrows_WhenDateTimeOffsetExactUnixEpoch()
+ {
+ long ticks = DateTimeOffset.UnixEpoch.UtcTicks;
+ Assert.DoesNotThrow(() =>
+ {
+ Uuid.CreateVersion7(new DateTimeOffset(ticks, TimeSpan.Zero));
+ });
+ }
+
+ [Test]
+ public void CreateVersion7WithDateTimeOffset_DoesNotThrows_WhenDateTimeOffsetIsMax()
+ {
+ long ticks = DateTimeOffset.MaxValue.UtcTicks;
+ Assert.DoesNotThrow(() =>
+ {
+ Uuid.CreateVersion7(new DateTimeOffset(ticks, TimeSpan.Zero));
+ });
+ }
+
+ [Test]
+ public void CreateVersion7WithoutDateTimeOffset()
+ {
+ DateTimeOffset startDate = DateTimeOffset.UtcNow;
+ var uuid = Uuid.CreateVersion7();
+ DateTimeOffset endDate = DateTimeOffset.UtcNow;
+
+ DateTimeOffset actualDate = ExtractDateTimeOffset(uuid);
+ Assert.That(actualDate.UtcTicks >= startDate.UtcTicks && actualDate.UtcTicks <= endDate.UtcTicks, Is.True);
+ }
+
+ private static DateTimeOffset ExtractDateTimeOffset(Uuid uuid)
+ {
+ const long unixEpochTicks = 621_355_968_000_000_000L;
+
+ Span bytes = stackalloc byte[16];
+ uuid.TryWriteBytes(bytes);
+ Span unixTsMsBuffer = stackalloc byte[8];
+ bytes[..6].CopyTo(unixTsMsBuffer);
+ long unixTsMs = (long) BinaryPrimitives.ReadUInt64BigEndian(unixTsMsBuffer) >> 16;
+ Span randABuffer = stackalloc byte[2];
+ bytes.Slice(6, 2).CopyTo(randABuffer);
+ randABuffer[0] = (byte) (randABuffer[0] & 0b00001111);
+ var randA = (ushort) (BinaryPrimitives.ReadUInt16BigEndian(randABuffer) << 2);
+ var ticksNotFitInRandA = (ushort) ((byte) (bytes[8] & 0b00110000) >> 4);
+ var remainTicks = (long) (ushort) (randA | ticksNotFitInRandA);
+ long unixTimeTicks = (unixTsMs * TimeSpan.TicksPerMillisecond) + remainTicks;
+ long utcTicks = unixEpochTicks + unixTimeTicks;
+ return new DateTimeOffset(utcTicks, TimeSpan.Zero);
+ }
+}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs
index 370d81d..fad829e 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs
@@ -20,7 +20,7 @@ public unsafe void CtorFromByteArrayCorrectBytes(byte[] correctBytes)
*(Uuid*) pinnedUuidArray = uuid;
}
- Assert.AreEqual(correctBytes, uuidBytes);
+ Assert.That(uuidBytes, Is.EqualTo(correctBytes));
}
[Test]
@@ -48,26 +48,6 @@ public void CtorFromByteArrayNot16BytesShouldThrows()
});
}
- [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
- public unsafe void CtorFromPtrCorrectData(byte[] correctBytes)
- {
- byte* bytePtr = stackalloc byte[correctBytes.Length];
- for (var i = 0; i < correctBytes.Length; i++)
- {
- bytePtr[i] = correctBytes[i];
- }
-
- var uuid = new Uuid(bytePtr);
-
- var uuidBytes = new byte[16];
- fixed (byte* pinnedUuidArray = uuidBytes)
- {
- *(Uuid*) pinnedUuidArray = uuid;
- }
-
- Assert.AreEqual(correctBytes, uuidBytes);
- }
-
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
public unsafe void CtorFromReadOnlySpanCorrectBytes(byte[] correctBytes)
{
@@ -80,7 +60,7 @@ public unsafe void CtorFromReadOnlySpanCorrectBytes(byte[] correctBytes)
*(Uuid*) pinnedUuidArray = uuid;
}
- Assert.AreEqual(correctBytes, uuidBytes);
+ Assert.That(uuidBytes, Is.EqualTo(correctBytes));
}
[Test]
@@ -151,7 +131,7 @@ public unsafe void CtorFromStringCorrectNString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -174,7 +154,7 @@ public unsafe void CtorFromCharSpanCorrectN()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -201,7 +181,7 @@ public unsafe void CtorFromStringCorrectDString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -224,7 +204,7 @@ public unsafe void CtorFromCharSpanCorrectD()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -251,7 +231,7 @@ public unsafe void CtorFromStringCorrectBString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -274,7 +254,7 @@ public unsafe void CtorFromCharSpanCorrectB()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -301,7 +281,7 @@ public unsafe void CtorFromStringCorrectPString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -324,7 +304,7 @@ public unsafe void CtorFromCharSpanCorrectP()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -351,7 +331,7 @@ public unsafe void CtorFromStringCorrectXString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -374,7 +354,7 @@ public unsafe void CtorFromCharSpanCorrectX()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs
index 36c0321..d365793 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs
@@ -12,7 +12,7 @@ public void EqualsWithObjectNullReturnFalse(byte[] correctBytes)
bool isEquals = uuid.Equals(null);
- Assert.False(isEquals);
+ Assert.That(isEquals, Is.False);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -23,7 +23,7 @@ public void EqualsWithObjectOtherTypeReturnFalse(byte[] correctBytes)
bool isEquals = uuid.Equals(objectWithAnotherType);
- Assert.False(isEquals);
+ Assert.That(isEquals, Is.False);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectEqualsToBytesAndResult))]
@@ -37,7 +37,7 @@ public void EqualsWithObjectUuid(
bool isEquals = uuid.Equals(objectUuid);
- Assert.AreEqual(expectedResult, isEquals);
+ Assert.That(isEquals, Is.EqualTo(expectedResult));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectEqualsToBytesAndResult))]
@@ -51,6 +51,6 @@ public void EqualsWithOtherUuid(
bool isEquals = uuid.Equals(otherUuid);
- Assert.AreEqual(expectedResult, isEquals);
+ Assert.That(isEquals, Is.EqualTo(expectedResult));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs
index 8394b4a..47d847d 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs
@@ -17,7 +17,9 @@ public class UuidGeneratorTests
public unsafe void NewTimeBased()
{
DateTimeOffset startDate = DateTimeOffset.UtcNow;
+#pragma warning disable CS0618 // Type or member is obsolete
var uuid = Uuid.NewTimeBased();
+#pragma warning restore CS0618 // Type or member is obsolete
DateTimeOffset endDate = DateTimeOffset.UtcNow;
var uuidPtr = (byte*) &uuid;
long ticks = (endDate - startDate).Ticks + 1;
@@ -39,7 +41,9 @@ public unsafe void NewTimeBased()
public unsafe void NewMySqlOptimized()
{
DateTimeOffset startDate = DateTimeOffset.UtcNow;
+#pragma warning disable CS0618 // Type or member is obsolete
var uuid = Uuid.NewMySqlOptimized();
+#pragma warning restore CS0618 // Type or member is obsolete
DateTimeOffset endDate = DateTimeOffset.UtcNow;
var uuidPtr = (byte*) &uuid;
long ticks = (endDate - startDate).Ticks + 1;
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs
index e9b7747..2fe1740 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs
@@ -20,6 +20,6 @@ public unsafe void GetHashCode(byte[] correctBytes)
int actualHashCode = uuid.GetHashCode();
- Assert.AreEqual(expectedHashCode, actualHashCode);
+ Assert.That(actualHashCode, Is.EqualTo(expectedHashCode));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidOperatorsTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidOperatorsTests.cs
index aefecea..d0469f3 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidOperatorsTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidOperatorsTests.cs
@@ -18,7 +18,7 @@ public void EqualsOperator(
bool isEquals = uuid == otherUuid;
- Assert.AreEqual(expectedResult, isEquals);
+ Assert.That(isEquals, Is.EqualTo(expectedResult));
}
#endregion
@@ -37,7 +37,7 @@ public void NotEqualsOperator(
bool isEquals = uuid != otherUuid;
- Assert.AreEqual(expectedResult, isEquals);
+ Assert.That(isEquals, Is.EqualTo(expectedResult));
}
#endregion
@@ -48,7 +48,7 @@ public void NotEqualsOperator(
public void LessThan_ReturnsTrue_WhenLeftLessThanRight(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left < right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[Test]
@@ -60,14 +60,14 @@ public void LessThan_ReturnsFalse_WhenLeftEqualsToRight()
bool isLeftLessThatRight = left < right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.RightLessThanLeft))]
public void LessThan_ReturnsFalse_WhenRightLessThanLeft(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left < right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
#endregion
@@ -78,7 +78,7 @@ public void LessThan_ReturnsFalse_WhenRightLessThanLeft(Uuid left, Uuid right)
public void LessThanOrEqual_ReturnsTrue_WhenLeftLessThanRight(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left <= right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[Test]
@@ -90,14 +90,14 @@ public void LessThanOrEqual_ReturnsTrue_WhenLeftEqualsToRight()
bool isLeftLessThatRight = left <= right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.RightLessThanLeft))]
public void LessThanOrEqual_ReturnsFalse_WhenRightLessThanLeft(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left <= right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
#endregion
@@ -108,7 +108,7 @@ public void LessThanOrEqual_ReturnsFalse_WhenRightLessThanLeft(Uuid left, Uuid r
public void GreaterThan_ReturnsTrue_WhenLeftGreaterThanRight(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left > right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[Test]
@@ -120,14 +120,14 @@ public void GreaterThan_ReturnsFalse_WhenLeftEqualsToRight()
bool isLeftLessThatRight = left > right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.LeftLessThanRight))]
public void GreaterThan_ReturnsFalse_WhenRightGreaterThanLeft(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left > right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
#endregion
@@ -138,7 +138,7 @@ public void GreaterThan_ReturnsFalse_WhenRightGreaterThanLeft(Uuid left, Uuid ri
public void GreaterThanOrEqual_ReturnsTrue_WhenLeftGreaterThanRight(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left >= right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[Test]
@@ -150,14 +150,14 @@ public void GreaterThanOrEqual_ReturnsFalse_WhenLeftEqualsToRight()
bool isLeftLessThatRight = left >= right;
- Assert.True(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.True);
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.LeftLessThanRight))]
public void GreaterThanOrEqual_ReturnsFalse_WhenRightGreaterThanLeft(Uuid left, Uuid right)
{
bool isLeftLessThatRight = left >= right;
- Assert.False(isLeftLessThatRight);
+ Assert.That(isLeftLessThatRight, Is.False);
}
#endregion
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs
index ea5fc1f..9f6617e 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs
@@ -158,7 +158,7 @@ public unsafe void ParseExactCorrectNCorrectFormat()
foreach (byte[] result in results)
{
- Assert.AreEqual(correctNString.Bytes, result);
+ Assert.That(result, Is.EqualTo(correctNString.Bytes));
}
}
});
@@ -272,7 +272,7 @@ public unsafe void ParseExactCorrectDCorrectFormat()
foreach (byte[] result in results)
{
- Assert.AreEqual(correctDString.Bytes, result);
+ Assert.That(result, Is.EqualTo(correctDString.Bytes));
}
}
});
@@ -386,7 +386,7 @@ public unsafe void ParseExactCorrectBCorrectFormat()
foreach (byte[] result in results)
{
- Assert.AreEqual(correctBString.Bytes, result);
+ Assert.That(result, Is.EqualTo(correctBString.Bytes));
}
}
});
@@ -500,7 +500,7 @@ public unsafe void ParseExactCorrectPCorrectFormat()
foreach (byte[] result in results)
{
- Assert.AreEqual(correctPString.Bytes, result);
+ Assert.That(result, Is.EqualTo(correctPString.Bytes));
}
}
});
@@ -614,7 +614,7 @@ public unsafe void ParseExactCorrectXCorrectFormat()
foreach (byte[] result in results)
{
- Assert.AreEqual(correctXString.Bytes, result);
+ Assert.That(result, Is.EqualTo(correctXString.Bytes));
}
}
});
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs
index 70bcd13..b53c76a 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs
@@ -58,7 +58,7 @@ public unsafe void ParseCorrectNString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -81,7 +81,7 @@ public unsafe void ParseCorrectNSpan()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -201,7 +201,7 @@ public unsafe void ParseCorrectDString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -224,7 +224,7 @@ public unsafe void ParseCorrectDSpan()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -344,7 +344,7 @@ public unsafe void ParseCorrectBString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -367,7 +367,7 @@ public unsafe void ParseCorrectBSpan()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -487,7 +487,7 @@ public unsafe void ParseCorrectPString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -510,7 +510,7 @@ public unsafe void ParseCorrectPSpan()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -630,7 +630,7 @@ public unsafe void ParseCorrectXString()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -653,7 +653,7 @@ public unsafe void ParseCorrectXSpan()
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs
index c5aaba7..d5c27d7 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs
@@ -69,7 +69,7 @@ public unsafe void ParseCorrectNString([ValueSource(nameof(GetFormatProviders))]
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -92,7 +92,7 @@ public unsafe void ParseCorrectNSpan([ValueSource(nameof(GetFormatProviders))] I
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -212,7 +212,7 @@ public unsafe void ParseCorrectDString([ValueSource(nameof(GetFormatProviders))]
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -235,7 +235,7 @@ public unsafe void ParseCorrectDSpan([ValueSource(nameof(GetFormatProviders))] I
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -355,7 +355,7 @@ public unsafe void ParseCorrectBString([ValueSource(nameof(GetFormatProviders))]
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -378,7 +378,7 @@ public unsafe void ParseCorrectBSpan([ValueSource(nameof(GetFormatProviders))] I
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -498,7 +498,7 @@ public unsafe void ParseCorrectPString([ValueSource(nameof(GetFormatProviders))]
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -521,7 +521,7 @@ public unsafe void ParseCorrectPSpan([ValueSource(nameof(GetFormatProviders))] I
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -641,7 +641,7 @@ public unsafe void ParseCorrectXString([ValueSource(nameof(GetFormatProviders))]
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -664,7 +664,7 @@ public unsafe void ParseCorrectXSpan([ValueSource(nameof(GetFormatProviders))] I
*(Uuid*) pinnedActualBytes = parsedUuid;
}
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidPropertiesTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidPropertiesTests.cs
new file mode 100644
index 0000000..93418ac
--- /dev/null
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidPropertiesTests.cs
@@ -0,0 +1,43 @@
+using System;
+using Dodo.Primitives.Tests.Uuids.Data;
+using NUnit.Framework;
+
+namespace Dodo.Primitives.Tests.Uuids;
+
+public class UuidPropertiesTests
+{
+ [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.GetAllUuidVersions))]
+ public void VersionHasCorrectValue(string uuidString, int expectedVersion)
+ {
+ var uuid = new Uuid(uuidString);
+ Assert.That(uuid.Version, Is.EqualTo(expectedVersion));
+ }
+
+ [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.GetAllUuidVariants))]
+ public void VariantHasCorrectValue(string uuidString, int expectedVariant)
+ {
+ var uuid = new Uuid(uuidString);
+ Assert.That(uuid.Variant, Is.EqualTo(expectedVariant));
+ }
+
+#if NET9_0_OR_GREATER
+
+ [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.GetAllUuidVersions))]
+ public void VersionHasCorrectValueThatMathGuidOnNet9(string uuidString, int expectedVersion)
+ {
+ var uuid = new Uuid(uuidString);
+ var guid = new Guid(uuidString);
+ Assert.That(uuid.Version, Is.EqualTo(expectedVersion));
+ Assert.That(uuid.Version, Is.EqualTo(guid.Version));
+ }
+
+ [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.GetAllUuidVariants))]
+ public void VariantHasCorrectValueThatMathGuidOnNet9(string uuidString, int expectedVariant)
+ {
+ var uuid = new Uuid(uuidString);
+ var guid = new Guid(uuidString);
+ Assert.That(uuid.Variant, Is.EqualTo(expectedVariant));
+ Assert.That(uuid.Variant, Is.EqualTo(guid.Variant));
+ }
+#endif
+}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidStaticPropertiesTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidStaticPropertiesTests.cs
new file mode 100644
index 0000000..7ee6bcd
--- /dev/null
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidStaticPropertiesTests.cs
@@ -0,0 +1,19 @@
+using NUnit.Framework;
+
+namespace Dodo.Primitives.Tests.Uuids;
+
+public class UuidStaticPropertiesTests
+{
+ [Test]
+ public void AllBitsSetReturnsUuidWithByteMaxValues()
+ {
+ var expected = new byte[16];
+ for (var i = 0; i < expected.Length; i++)
+ {
+ expected[i] = 0xFF;
+ }
+
+ byte[] actual = Uuid.AllBitsSet.ToByteArray();
+ Assert.That(actual, Is.EquivalentTo(expected));
+ }
+}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidToByteArrayTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidToByteArrayTests.cs
index 5026020..a9d4004 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidToByteArrayTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidToByteArrayTests.cs
@@ -12,6 +12,6 @@ public void ToByteArray(byte[] correctBytes)
byte[] uuidBytes = uuid.ToByteArray();
- Assert.AreEqual(correctBytes, uuidBytes);
+ Assert.That(uuidBytes, Is.EqualTo(correctBytes));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidToGuidTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidToGuidTests.cs
index 5198972..7bfa258 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidToGuidTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidToGuidTests.cs
@@ -15,11 +15,13 @@ public void ToGuidByteLayout()
foreach (UuidStringWithBytes nString in UuidTestData.CorrectNStrings)
{
var uuid = new Uuid(nString.Bytes);
+#pragma warning disable CS0618 // Type or member is obsolete
Guid guid = uuid.ToGuidByteLayout();
+#pragma warning restore CS0618 // Type or member is obsolete
byte[] expectedBytes = uuid.ToByteArray();
byte[] actualBytes = guid.ToByteArray();
- string? expectedGuidString = Primitives.Hex.GetString(new[]
+ string? expectedGuidString = Convert.ToHexString(new[]
{
nString.Bytes[3],
nString.Bytes[2],
@@ -40,8 +42,46 @@ public void ToGuidByteLayout()
});
var actualGuidString = guid.ToString("N");
- Assert.AreEqual(expectedBytes, actualBytes);
- Assert.True(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
+ Assert.That(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
+ }
+ });
+ }
+
+ [Test]
+ public void ToGuidLittleEndianLayout()
+ {
+ Assert.Multiple(() =>
+ {
+ foreach (UuidStringWithBytes nString in UuidTestData.CorrectNStrings)
+ {
+ var uuid = new Uuid(nString.Bytes);
+ Guid guid = uuid.ToGuidLittleEndian();
+ byte[] expectedBytes = uuid.ToByteArray();
+ byte[] actualBytes = guid.ToByteArray();
+ string? expectedGuidString = Convert.ToHexString(new[]
+ {
+ nString.Bytes[3],
+ nString.Bytes[2],
+ nString.Bytes[1],
+ nString.Bytes[0],
+ nString.Bytes[5],
+ nString.Bytes[4],
+ nString.Bytes[7],
+ nString.Bytes[6],
+ nString.Bytes[8],
+ nString.Bytes[9],
+ nString.Bytes[10],
+ nString.Bytes[11],
+ nString.Bytes[12],
+ nString.Bytes[13],
+ nString.Bytes[14],
+ nString.Bytes[15]
+ });
+ var actualGuidString = guid.ToString("N");
+
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
+ Assert.That(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
}
});
}
@@ -54,7 +94,9 @@ public void ToGuidStringLayout()
foreach (UuidStringWithBytes nString in UuidTestData.CorrectNStrings)
{
var uuid = new Uuid(nString.Bytes);
+#pragma warning disable CS0618 // Type or member is obsolete
Guid guid = uuid.ToGuidStringLayout();
+#pragma warning restore CS0618 // Type or member is obsolete
byte[] expectedBytes =
{
@@ -79,8 +121,46 @@ public void ToGuidStringLayout()
var expectedGuidString = uuid.ToString("N");
var actualGuidString = guid.ToString("N");
- Assert.AreEqual(expectedBytes, actualBytes);
- Assert.True(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
+ Assert.That(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
+ }
+ });
+ }
+
+ [Test]
+ public void ToGuidBigEndianLayout()
+ {
+ Assert.Multiple(() =>
+ {
+ foreach (UuidStringWithBytes nString in UuidTestData.CorrectNStrings)
+ {
+ var uuid = new Uuid(nString.Bytes);
+ Guid guid = uuid.ToGuidBigEndian();
+ byte[] expectedBytes =
+ {
+ nString.Bytes[3],
+ nString.Bytes[2],
+ nString.Bytes[1],
+ nString.Bytes[0],
+ nString.Bytes[5],
+ nString.Bytes[4],
+ nString.Bytes[7],
+ nString.Bytes[6],
+ nString.Bytes[8],
+ nString.Bytes[9],
+ nString.Bytes[10],
+ nString.Bytes[11],
+ nString.Bytes[12],
+ nString.Bytes[13],
+ nString.Bytes[14],
+ nString.Bytes[15]
+ };
+ byte[] actualBytes = guid.ToByteArray();
+ var expectedGuidString = uuid.ToString("N");
+ var actualGuidString = guid.ToString("N");
+
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
+ Assert.That(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidToStringTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidToStringTests.cs
index 44e9375..9a195a3 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidToStringTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidToStringTests.cs
@@ -14,7 +14,7 @@ public void ToString(byte[] correctBytes)
var actualString = uuid.ToString();
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -25,7 +25,7 @@ public void ToStringNullFormat(byte[] correctBytes)
var actualString = uuid.ToString(null);
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -36,7 +36,7 @@ public void ToStringEmptyFormat(byte[] correctBytes)
var actualString = uuid.ToString(string.Empty);
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -69,7 +69,7 @@ public void ToStringN(byte[] correctBytes)
var actualString = uuid.ToString("N");
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -80,7 +80,7 @@ public void ToStringD(byte[] correctBytes)
var actualString = uuid.ToString("D");
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -91,7 +91,7 @@ public void ToStringB(byte[] correctBytes)
var actualString = uuid.ToString("B");
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -102,7 +102,7 @@ public void ToStringP(byte[] correctBytes)
var actualString = uuid.ToString("P");
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -113,6 +113,6 @@ public void ToStringX(byte[] correctBytes)
var actualString = uuid.ToString("X");
- Assert.AreEqual(expectedString, actualString);
+ Assert.That(actualString, Is.EqualTo(expectedString));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs
index 9f99811..4140c84 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs
@@ -16,9 +16,9 @@ public void TryFormatNullFormat(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
char* bufferPtr = stackalloc char[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 32));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(new string(bufferPtr, 0, 32), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -28,9 +28,9 @@ public void TryFormatEmptyFormat(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
char* bufferPtr = stackalloc char[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 32));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(new string(bufferPtr, 0, 32), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -38,8 +38,8 @@ public void TryFormatIncorrectFormat(byte[] correctBytes)
{
var uuid = new Uuid(correctBytes);
Span buffer = stackalloc char[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan()));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan()), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -47,8 +47,8 @@ public void TryFormatTooLongFormat(byte[] correctBytes)
{
var uuid = new Uuid(correctBytes);
Span buffer = stackalloc char[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan()));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan()), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -58,9 +58,9 @@ public void TryFormatNCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
char* bufferPtr = stackalloc char[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' })));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 32));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' })), Is.True);
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(new string(bufferPtr, 0, 32), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -70,9 +70,9 @@ public void TryFormatDCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringD(correctBytes);
char* bufferPtr = stackalloc char[36];
var spanBuffer = new Span(bufferPtr, 36);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' })));
- Assert.AreEqual(36, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 36));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' })), Is.True);
+ Assert.That(charsWritten, Is.EqualTo(36));
+ Assert.That(new string(bufferPtr, 0, 36), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -82,9 +82,9 @@ public void TryFormatBCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringB(correctBytes);
char* bufferPtr = stackalloc char[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' })));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 38));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' })), Is.True);
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(new string(bufferPtr, 0, 38), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -94,9 +94,9 @@ public void TryFormatPCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringP(correctBytes);
char* bufferPtr = stackalloc char[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' })));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 38));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' })), Is.True);
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(new string(bufferPtr, 0, 38), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -106,9 +106,9 @@ public void TryFormatXCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringX(correctBytes);
char* bufferPtr = stackalloc char[68];
var spanBuffer = new Span(bufferPtr, 68);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' })));
- Assert.AreEqual(68, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 68));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' })), Is.True);
+ Assert.That(charsWritten, Is.EqualTo(68));
+ Assert.That(new string(bufferPtr, 0, 68), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -133,8 +133,8 @@ public void TryFormatSmallDestination(byte[] correctBytes)
};
foreach (char format in formats)
{
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format })));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format })), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
});
}
@@ -150,9 +150,9 @@ public void SpanFormattableTryFormatEmptyFormat(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
char* bufferPtr = stackalloc char[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty, null));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 32));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty, null));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(new string(bufferPtr, 0, 32), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -160,8 +160,8 @@ public void SpanFormattableTryFormatIncorrectFormat(byte[] correctBytes)
{
ISpanFormattable uuid = new Uuid(correctBytes);
Span buffer = stackalloc char[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan(), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan(), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -169,8 +169,8 @@ public void SpanFormattableTryFormatTooLongFormat(byte[] correctBytes)
{
ISpanFormattable uuid = new Uuid(correctBytes);
Span buffer = stackalloc char[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan(), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan(), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -180,9 +180,9 @@ public void SpanFormattableTryFormatNCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
char* bufferPtr = stackalloc char[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' }), null));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 32));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' }), null));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(new string(bufferPtr, 0, 32), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -192,9 +192,9 @@ public void SpanFormattableTryFormatDCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringD(correctBytes);
char* bufferPtr = stackalloc char[36];
var spanBuffer = new Span(bufferPtr, 36);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' }), null));
- Assert.AreEqual(36, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 36));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' }), null));
+ Assert.That(charsWritten, Is.EqualTo(36));
+ Assert.That(new string(bufferPtr, 0, 36), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -204,9 +204,9 @@ public void SpanFormattableTryFormatBCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringB(correctBytes);
char* bufferPtr = stackalloc char[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' }), null));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 38));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' }), null));
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(new string(bufferPtr, 0, 38), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -216,9 +216,9 @@ public void SpanFormattableTryFormatPCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringP(correctBytes);
char* bufferPtr = stackalloc char[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' }), null));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 38));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' }), null));
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(new string(bufferPtr, 0, 38), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -228,9 +228,9 @@ public void SpanFormattableTryFormatXCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringX(correctBytes);
char* bufferPtr = stackalloc char[68];
var spanBuffer = new Span(bufferPtr, 68);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' }), null));
- Assert.AreEqual(68, charsWritten);
- Assert.AreEqual(expectedString, new string(bufferPtr, 0, 68));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' }), null));
+ Assert.That(charsWritten, Is.EqualTo(68));
+ Assert.That(new string(bufferPtr, 0, 68), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -255,8 +255,8 @@ public void SpanFormattableTryFormatSmallDestination(byte[] correctBytes)
};
foreach (char format in formats)
{
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format }), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format }), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
});
}
@@ -272,9 +272,9 @@ public void Utf8SpanFormattableTryFormatEmptyFormat(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
byte* bufferPtr = stackalloc byte[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty, null));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty, null));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
@@ -283,8 +283,8 @@ public void Utf8SpanFormattableTryFormatIncorrectFormat(byte[] correctBytes)
{
var uuid = new Uuid(correctBytes);
Span buffer = stackalloc byte[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan(), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan(), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
@@ -293,8 +293,8 @@ public void Utf8SpanFormattableTryFormatTooLongFormat(byte[] correctBytes)
{
var uuid = new Uuid(correctBytes);
Span buffer = stackalloc byte[68];
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan(), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan(), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -304,9 +304,9 @@ public void Utf8SpanFormattableTryFormatNCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringN(correctBytes);
byte* bufferPtr = stackalloc byte[32];
var spanBuffer = new Span(bufferPtr, 32);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' }), null));
- Assert.AreEqual(32, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' }), null));
+ Assert.That(charsWritten, Is.EqualTo(32));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -316,9 +316,9 @@ public void Utf8SpanFormattableTryFormatDCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringD(correctBytes);
byte* bufferPtr = stackalloc byte[36];
var spanBuffer = new Span(bufferPtr, 36);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' }), null));
- Assert.AreEqual(36, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' }), null));
+ Assert.That(charsWritten, Is.EqualTo(36));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -328,9 +328,9 @@ public void Utf8SpanFormattableTryFormatBCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringB(correctBytes);
byte* bufferPtr = stackalloc byte[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' }), null));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' }), null));
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -340,9 +340,9 @@ public void Utf8SpanFormattableTryFormatPCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringP(correctBytes);
byte* bufferPtr = stackalloc byte[38];
var spanBuffer = new Span(bufferPtr, 38);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' }), null));
- Assert.AreEqual(38, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' }), null));
+ Assert.That(charsWritten, Is.EqualTo(38));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -352,9 +352,9 @@ public void Utf8SpanFormattableTryFormatXCorrect(byte[] correctBytes)
string expectedString = UuidTestsUtils.GetStringX(correctBytes);
byte* bufferPtr = stackalloc byte[68];
var spanBuffer = new Span(bufferPtr, 68);
- Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' }), null));
- Assert.AreEqual(68, charsWritten);
- Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten));
+ Assert.That(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' }), null));
+ Assert.That(charsWritten, Is.EqualTo(68));
+ Assert.That(Encoding.UTF8.GetString(bufferPtr, charsWritten), Is.EqualTo(expectedString));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -379,8 +379,8 @@ public void Utf8SpanFormattableTryFormatSmallDestination(byte[] correctBytes)
};
foreach (char format in formats)
{
- Assert.False(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format }), null));
- Assert.AreEqual(0, charsWritten);
+ Assert.That(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format }), null), Is.False);
+ Assert.That(charsWritten, Is.EqualTo(0));
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs
index d6e7380..9d7d46c 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs
@@ -17,8 +17,8 @@ public void TryParseExactNullStringCorrectFormatShouldFalse()
bool parsed = Uuid.TryParseExact(NullString, format, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
}
@@ -33,8 +33,8 @@ public void TryParseExactCorrectStringNullFormatShouldFalse()
#pragma warning disable 8625
bool parsed = Uuid.TryParseExact(correctNString.String, NullString, out Uuid uuid);
#pragma warning restore 8625
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -47,8 +47,8 @@ public void TryParseExactCorrectStringIncorrectFormatShouldFalse()
foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings)
{
bool parsed = Uuid.TryParseExact(correctNString.String, "Ъ", out Uuid uuid);
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -61,8 +61,8 @@ public void TryParseExactEmptyStringCorrectFormatShouldFalse()
foreach (string format in UuidTestData.Formats.All)
{
bool parsed = Uuid.TryParseExact(string.Empty, format, out Uuid uuid);
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -77,8 +77,8 @@ public void TryParseExactEmptySpanCorrectFormatShouldFalse()
var stringSpan = new ReadOnlySpan(new char[] { });
var formatSpan = new ReadOnlySpan(format.ToCharArray());
bool parsed = Uuid.TryParseExact(stringSpan, formatSpan, out Uuid uuid);
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -93,8 +93,8 @@ public void TryParseExactCorrectSpanEmptyFormatShouldFalse()
var stringSpan = new ReadOnlySpan(correctNString.String.ToCharArray());
var formatSpan = new ReadOnlySpan(new char[] { });
bool parsed = Uuid.TryParseExact(stringSpan, formatSpan, out Uuid uuid);
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -109,8 +109,8 @@ public void TryParseExactCorrectSpanIncorrectFormatShouldFalse()
var stringSpan = new ReadOnlySpan(correctNString.String.ToCharArray());
var formatSpan = new ReadOnlySpan(new[] { 'Ъ' });
bool parsed = Uuid.TryParseExact(stringSpan, formatSpan, out Uuid uuid);
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
}
});
}
@@ -325,10 +325,10 @@ private unsafe void TryParseExactCorrectStringCorrectFormat(
*(Uuid*) pinnedSpan = parsedUuidFromSpan;
}
- Assert.True(isParsedFromString);
- Assert.True(isParsedBoolFromSpan);
- Assert.AreEqual(correctString.Bytes, actualBytesString);
- Assert.AreEqual(correctString.Bytes, actualBytesSpan);
+ Assert.That(isParsedFromString);
+ Assert.That(isParsedBoolFromSpan);
+ Assert.That(actualBytesString, Is.EqualTo(correctString.Bytes));
+ Assert.That(actualBytesSpan, Is.EqualTo(correctString.Bytes));
}
}
});
@@ -381,10 +381,10 @@ private unsafe void TryParseExactCorrectStringIncorrectFormat(
*(Uuid*) pinnedSpan = parsedUuidFromSpan;
}
- Assert.False(isParsedFromString);
- Assert.False(isParsedBoolFromSpan);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan);
+ Assert.That(isParsedFromString, Is.False);
+ Assert.That(isParsedBoolFromSpan, Is.False);
+ Assert.That(actualBytesString, Is.EqualTo(ExpectedEmptyUuidBytes));
+ Assert.That(actualBytesSpan, Is.EqualTo(ExpectedEmptyUuidBytes));
}
}
});
@@ -417,10 +417,10 @@ private unsafe void TryParseExactIncorrectStringCorrectFormat(
*(Uuid*) pinnedSpan = parsedUuidFromSpan;
}
- Assert.False(isParsedFromString);
- Assert.False(isParsedBoolFromSpan);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan);
+ Assert.That(isParsedFromString, Is.False);
+ Assert.That(isParsedBoolFromSpan, Is.False);
+ Assert.That(actualBytesString, Is.EqualTo(ExpectedEmptyUuidBytes));
+ Assert.That(actualBytesSpan, Is.EqualTo(ExpectedEmptyUuidBytes));
}
}
});
@@ -453,10 +453,10 @@ private unsafe void TryParseExactOtherFormatStringCorrectFormat(
*(Uuid*) pinnedSpan = parsedUuidFromSpan;
}
- Assert.False(isParsedFromString);
- Assert.False(isParsedBoolFromSpan);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString);
- Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan);
+ Assert.That(isParsedFromString, Is.False);
+ Assert.That(isParsedBoolFromSpan, Is.False);
+ Assert.That(actualBytesString, Is.EqualTo(ExpectedEmptyUuidBytes));
+ Assert.That(actualBytesSpan, Is.EqualTo(ExpectedEmptyUuidBytes));
}
}
});
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs
index 2720a93..3ec1df1 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs
@@ -13,8 +13,8 @@ public void TryParseNullStringShouldFalse()
bool parsed = Uuid.TryParse((string?) null, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -24,8 +24,8 @@ public void TryParseEmptyStringShouldFalse()
bool parsed = Uuid.TryParse(string.Empty, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -35,8 +35,8 @@ public void TryParseEmptySpanShouldFalse()
bool parsed = Uuid.TryParse(new ReadOnlySpan(new char[] { }), out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -319,8 +319,8 @@ private unsafe void TryParseCorrectString(UuidStringWithBytes[] correctStrings)
*(Uuid*) pinnedActualBytes = uuid;
}
- Assert.True(parsed);
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(parsed);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -342,8 +342,8 @@ private unsafe void TryParseCorrectSpan(UuidStringWithBytes[] correctStrings)
*(Uuid*) pinnedActualBytes = uuid;
}
- Assert.True(parsed);
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(parsed);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -354,7 +354,7 @@ private void TryParseIncorrectString(string[] incorrectLargeStrings)
{
foreach (string largeString in incorrectLargeStrings)
{
- Assert.False(Uuid.TryParse(largeString, out _));
+ Assert.That(Uuid.TryParse(largeString, out _), Is.False);
}
});
}
@@ -366,7 +366,7 @@ private void TryParseIncorrectSpan(string[] incorrectLargeStrings)
foreach (string largeString in incorrectLargeStrings)
{
var largeSpan = new ReadOnlySpan(largeString.ToCharArray());
- Assert.False(Uuid.TryParse(largeSpan, out _));
+ Assert.That(Uuid.TryParse(largeSpan, out _), Is.False);
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs
index 1a130df..d375d82 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs
@@ -14,8 +14,8 @@ public void TryParseUtf8NullSpanShouldFalse()
bool parsed = Uuid.TryParse((ReadOnlySpan) null, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -25,8 +25,8 @@ public void TryParseUtf8EmptySpanShouldFalse()
bool parsed = Uuid.TryParse(ReadOnlySpan.Empty, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -191,8 +191,8 @@ private unsafe void TryParseUtf8CorrectSpan(UuidStringWithBytes[] correctStrings
*(Uuid*) pinnedActualBytes = uuid;
}
- Assert.True(parsed);
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(parsed);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
});
}
@@ -206,7 +206,7 @@ private void TryParseUtf8IncorrectSpan(string[] incorrectLargeStrings)
{
int utf8Chars = GetUtf8BytesSpanFromString(largeString, utf8Buffer);
Span spanToParse = utf8Buffer.Slice(0, utf8Chars);
- Assert.False(Uuid.TryParse(spanToParse, out _));
+ Assert.That(Uuid.TryParse(spanToParse, out _), Is.False);
}
});
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs
index b4c9306..745b3dd 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs
@@ -34,8 +34,8 @@ public void TryParseNullStringShouldFalse([ValueSource(nameof(GetFormatProviders
bool parsed = Uuid.TryParse(valueToParse, formatProvider, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -45,8 +45,8 @@ public void TryParseEmptyStringShouldFalse([ValueSource(nameof(GetFormatProvider
bool parsed = Uuid.TryParse(string.Empty, formatProvider, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -56,8 +56,8 @@ public void TryParseEmptySpanShouldFalse([ValueSource(nameof(GetFormatProviders)
bool parsed = Uuid.TryParse(new ReadOnlySpan(new char[] { }), formatProvider, out Uuid uuid);
Assert.Multiple(() =>
{
- Assert.False(parsed);
- Assert.AreEqual(Uuid.Empty, uuid);
+ Assert.That(parsed, Is.False);
+ Assert.That(uuid, Is.EqualTo(Uuid.Empty));
});
}
@@ -342,8 +342,8 @@ private unsafe void TryParseCorrectString(UuidStringWithBytes[] correctStrings)
*(Uuid*) pinnedActualBytes = uuid;
}
- Assert.True(parsed);
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(parsed);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
}
});
@@ -368,8 +368,8 @@ private unsafe void TryParseCorrectSpan(UuidStringWithBytes[] correctStrings)
*(Uuid*) pinnedActualBytes = uuid;
}
- Assert.True(parsed);
- Assert.AreEqual(expectedBytes, actualBytes);
+ Assert.That(parsed);
+ Assert.That(actualBytes, Is.EqualTo(expectedBytes));
}
}
});
@@ -383,7 +383,7 @@ private void TryParseIncorrectString(string[] incorrectLargeStrings)
{
foreach (string largeString in incorrectLargeStrings)
{
- Assert.False(Uuid.TryParse(largeString, formatProvider, out _));
+ Assert.That(Uuid.TryParse(largeString, formatProvider, out _), Is.False);
}
}
});
@@ -398,7 +398,7 @@ private void TryParseIncorrectSpan(string[] incorrectLargeStrings)
foreach (string largeString in incorrectLargeStrings)
{
var largeSpan = new ReadOnlySpan(largeString.ToCharArray());
- Assert.False(Uuid.TryParse(largeSpan, formatProvider, out _));
+ Assert.That(Uuid.TryParse(largeSpan, formatProvider, out _), Is.False);
}
}
});
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryWriteBytesTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryWriteBytesTests.cs
index 7dd2f14..b650ce2 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTryWriteBytesTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryWriteBytesTests.cs
@@ -17,8 +17,8 @@ public unsafe void ToByteArrayExactOutputSize(byte[] correctBytes)
byte[] outputBytes = output.ToArray();
- Assert.True(wasWritten);
- Assert.AreEqual(correctBytes, outputBytes);
+ Assert.That(wasWritten);
+ Assert.That(outputBytes, Is.EqualTo(correctBytes));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -32,8 +32,8 @@ public unsafe void ToByteArrayLargeOutputSize(byte[] correctBytes)
byte[] outputBytes = output.Slice(0, 16).ToArray();
- Assert.True(wasWritten);
- Assert.AreEqual(correctBytes, outputBytes);
+ Assert.That(wasWritten);
+ Assert.That(outputBytes, Is.EqualTo(correctBytes));
}
[TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))]
@@ -47,7 +47,7 @@ public unsafe void ToByteArraySmallOutputSize(byte[] correctBytes)
byte[] outputBytes = output.ToArray();
- Assert.False(wasWritten);
- Assert.AreNotEqual(correctBytes, outputBytes);
+ Assert.That(wasWritten, Is.False);
+ Assert.That(outputBytes, Is.Not.EqualTo(correctBytes));
}
}
diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs
index 5264d66..cbe0936 100644
--- a/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs
+++ b/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs
@@ -13,21 +13,21 @@ public class UuidTypeConverterTests
public void CanConvertToCorrect(Type type)
{
var converter = new UuidTypeConverter();
- Assert.True(converter.CanConvertTo(type));
+ Assert.That(converter.CanConvertTo(type));
}
[Test]
public void CanConvertFromCorrect()
{
var converter = new UuidTypeConverter();
- Assert.True(converter.CanConvertFrom(typeof(string)));
+ Assert.That(converter.CanConvertFrom(typeof(string)));
}
[Test]
public void CanConvertFromInt32()
{
var converter = new UuidTypeConverter();
- Assert.False(converter.CanConvertFrom(typeof(int)));
+ Assert.That(converter.CanConvertFrom(typeof(int)), Is.False);
}
[Test]
@@ -39,10 +39,10 @@ public void ConvertNotUuidToStringWillCallOverrideToString()
object? actualValue = converter.ConvertTo(notUuid, typeof(string));
- Assert.NotNull(actualValue);
- Assert.IsInstanceOf(actualValue);
- Assert.AreEqual(expectedValue, (string?) actualValue);
- Assert.AreEqual(1, notUuid.ToStringCalls);
+ Assert.That(actualValue, Is.Not.Null);
+ Assert.That(actualValue, Is.InstanceOf());
+ Assert.That((string?) actualValue, Is.EqualTo(expectedValue));
+ Assert.That(notUuid.ToStringCalls, Is.EqualTo(1));
}
[Test]
@@ -54,9 +54,9 @@ public void ConvertToString()
object? actualValue = converter.ConvertTo(uuid, typeof(string));
- Assert.NotNull(actualValue);
- Assert.IsInstanceOf(actualValue);
- Assert.AreEqual(expectedValue, (string?) actualValue);
+ Assert.That(actualValue, Is.Not.Null);
+ Assert.That(actualValue, Is.InstanceOf());
+ Assert.That((string?) actualValue, Is.EqualTo(expectedValue));
}
[Test]
@@ -69,12 +69,12 @@ public void ConvertToInstanceDescriptor()
object? actualValue = converter.ConvertTo(uuid, typeof(InstanceDescriptor));
- Assert.NotNull(actualValue);
- Assert.IsInstanceOf(actualValue);
+ Assert.That(actualValue, Is.Not.Null);
+ Assert.That(actualValue, Is.InstanceOf());
var actualDescriptor = (InstanceDescriptor?) actualValue;
- Assert.AreEqual(expectedValue.MemberInfo, actualDescriptor?.MemberInfo);
- Assert.AreEqual(expectedValue.IsComplete, actualDescriptor?.IsComplete);
- Assert.AreEqual(expectedValue.Arguments, actualDescriptor?.Arguments);
+ Assert.That(actualDescriptor?.MemberInfo, Is.EqualTo(expectedValue.MemberInfo));
+ Assert.That(actualDescriptor?.IsComplete, Is.EqualTo(expectedValue.IsComplete));
+ Assert.That(actualDescriptor?.Arguments, Is.EqualTo(expectedValue.Arguments));
}
[Test]
@@ -97,9 +97,9 @@ public void ConvertFromString()
object? actualValue = converter.ConvertFrom("28d2b480b9e743f48ee32ecf03247ad1");
- Assert.NotNull(actualValue);
- Assert.IsInstanceOf(actualValue);
- Assert.AreEqual(expectedValue, (Uuid) actualValue!);
+ Assert.That(actualValue, Is.Not.Null);
+ Assert.That(actualValue, Is.InstanceOf());
+ Assert.That((Uuid) actualValue!, Is.EqualTo(expectedValue));
}
[Test]
@@ -112,9 +112,9 @@ public void ConvertFromValidInstanceDescriptor()
object? actualValue = converter.ConvertFrom(descriptor);
- Assert.NotNull(actualValue);
- Assert.IsInstanceOf(actualValue);
- Assert.AreEqual(expectedValue, (Uuid) actualValue!);
+ Assert.That(actualValue, Is.Not.Null);
+ Assert.That(actualValue, Is.InstanceOf());
+ Assert.That((Uuid) actualValue!, Is.EqualTo(expectedValue));
}
[Test]
diff --git a/src/Dodo.Primitives.sln b/src/Dodo.Primitives.sln
deleted file mode 100644
index d0629e0..0000000
--- a/src/Dodo.Primitives.sln
+++ /dev/null
@@ -1,61 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30011.22
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dodo.Primitives", "Dodo.Primitives\Dodo.Primitives.csproj", "{B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dodo.Primitives.Tests", "Dodo.Primitives.Tests\Dodo.Primitives.Tests.csproj", "{4C9485A5-FCB5-4361-8C46-C99669D5B22E}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{56E0CBC4-2555-4231-B28A-A0193DDB9F88}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{23740544-1379-49B7-8654-AEC78FB10D75}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{D54C1753-031A-4F30-B892-0C6456E3D7D6}"
-ProjectSection(SolutionItems) = preProject
- Directory.Build.props = Directory.Build.props
- ..\.editorconfig = ..\.editorconfig
- ..\.gitattributes = ..\.gitattributes
- ..\.gitignore = ..\.gitignore
- ..\global.json = ..\global.json
- ..\README.md = ..\README.md
-EndProjectSection
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{021B24DA-238D-4E15-B27D-9DA9191F0ED0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dodo.Primitives.Benchmarks", "Dodo.Primitives.Benchmarks\Dodo.Primitives.Benchmarks.csproj", "{288CCF26-65FB-4CC8-932B-01F0A458940A}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7}.Release|Any CPU.Build.0 = Release|Any CPU
- {4C9485A5-FCB5-4361-8C46-C99669D5B22E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {4C9485A5-FCB5-4361-8C46-C99669D5B22E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {4C9485A5-FCB5-4361-8C46-C99669D5B22E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {4C9485A5-FCB5-4361-8C46-C99669D5B22E}.Release|Any CPU.Build.0 = Release|Any CPU
- {288CCF26-65FB-4CC8-932B-01F0A458940A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {288CCF26-65FB-4CC8-932B-01F0A458940A}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {288CCF26-65FB-4CC8-932B-01F0A458940A}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {288CCF26-65FB-4CC8-932B-01F0A458940A}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7} = {56E0CBC4-2555-4231-B28A-A0193DDB9F88}
- {4C9485A5-FCB5-4361-8C46-C99669D5B22E} = {23740544-1379-49B7-8654-AEC78FB10D75}
- {288CCF26-65FB-4CC8-932B-01F0A458940A} = {021B24DA-238D-4E15-B27D-9DA9191F0ED0}
- {56E0CBC4-2555-4231-B28A-A0193DDB9F88} = {D54C1753-031A-4F30-B892-0C6456E3D7D6}
- {23740544-1379-49B7-8654-AEC78FB10D75} = {D54C1753-031A-4F30-B892-0C6456E3D7D6}
- {021B24DA-238D-4E15-B27D-9DA9191F0ED0} = {D54C1753-031A-4F30-B892-0C6456E3D7D6}
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {CD7CBDA7-367E-4456-8A78-BD65663C7340}
- EndGlobalSection
-EndGlobal
diff --git a/src/Dodo.Primitives.slnx b/src/Dodo.Primitives.slnx
new file mode 100644
index 0000000..7ad732b
--- /dev/null
+++ b/src/Dodo.Primitives.slnx
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Dodo.Primitives.sln.DotSettings b/src/Dodo.Primitives.slnx.DotSettings
similarity index 100%
rename from src/Dodo.Primitives.sln.DotSettings
rename to src/Dodo.Primitives.slnx.DotSettings
diff --git a/src/Dodo.Primitives/Dodo.Primitives.csproj b/src/Dodo.Primitives/Dodo.Primitives.csproj
index 52edb44..635d1d7 100644
--- a/src/Dodo.Primitives/Dodo.Primitives.csproj
+++ b/src/Dodo.Primitives/Dodo.Primitives.csproj
@@ -1,7 +1,7 @@
- net6.0;net8.0
+ net6.0;net8.0;net9.0
b9ecdb73-d6f3-4ec4-b4b4-a7ed2ae781b7
11.0
enable
diff --git a/src/Dodo.Primitives/Hex.cs b/src/Dodo.Primitives/Hex.cs
deleted file mode 100644
index 31030ff..0000000
--- a/src/Dodo.Primitives/Hex.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using Dodo.Primitives.Internal;
-
-namespace Dodo.Primitives;
-
-///
-/// Utility methods to work with hexadecimal strings.
-///
-[SuppressMessage("ReSharper", "RedundantNameQualifier")]
-public static unsafe class Hex
-{
- private const ushort MaximalChar = InternalHexTables.MaximalChar;
- private static readonly uint* TableToHexUtf16;
- private static readonly byte* TableFromHexToBytesUtf16;
-
- static Hex()
- {
- TableToHexUtf16 = InternalHexTables.TableToHexUtf16;
- TableFromHexToBytesUtf16 = InternalHexTables.TableFromHexToBytesUtf16;
- }
-
- ///
- /// Checks that provided string is hexadecimal.
- ///
- /// String to check.
- ///
- public static bool IsHexString(string? possibleHexString)
- {
- if (string.IsNullOrWhiteSpace(possibleHexString))
- {
- return false;
- }
-
- if (possibleHexString!.Length % 2 != 0)
- {
- return false;
- }
-
- int length = possibleHexString.Length;
- fixed (char* stringPtr = &possibleHexString.GetPinnableReference())
- {
- for (var i = 0; i < length;)
- {
- if (stringPtr[i] < MaximalChar
- && TableFromHexToBytesUtf16[stringPtr[i]] != 0xFF
- && stringPtr[i + 1] < MaximalChar
- && TableFromHexToBytesUtf16[stringPtr[i + 1]] != 0xFF)
- {
- i += 2;
- }
- else
- {
- return false;
- }
- }
- }
-
- return true;
- }
-
- ///
- /// Returns bytes of hexadecimal string.
- ///
- /// Hexadecimal string
- ///
- public static byte[]? GetBytes(string hexString)
- {
- if (string.IsNullOrWhiteSpace(hexString))
- {
- return null;
- }
-
- if (hexString.Length % 2 != 0)
- {
- return null;
- }
-
- int length = hexString.Length;
- var result = new byte[length / 2];
- fixed (char* stringPtr = &hexString.GetPinnableReference())
- fixed (byte* resultPtr = &result[0])
- {
- var resultIndex = 0;
- for (var i = 0; i < length;)
- {
- byte hexByteHi;
- byte hexByteLow;
- if (stringPtr[i] < MaximalChar
- && (hexByteHi = TableFromHexToBytesUtf16[stringPtr[i]]) != 0xFF
- && stringPtr[i + 1] < MaximalChar
- && (hexByteLow = TableFromHexToBytesUtf16[stringPtr[i + 1]]) != 0xFF)
- {
- var resultByte = (byte) ((byte) (hexByteHi << 4) | hexByteLow);
- resultPtr[resultIndex] = resultByte;
- i += 2;
- resultIndex += 1;
- }
- else
- {
- return null;
- }
- }
- }
-
- return result;
- }
-
- ///
- /// Return hexadecimal string representation of provided bytes.
- ///
- /// Bytes that need to be presented as hexadecimal string.
- ///
- [SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse")]
- public static string? GetString(byte[]? bytes)
- {
- if (bytes == null)
- {
- return null;
- }
-
- if (bytes.Length == 0)
- {
- return string.Empty;
- }
-
- var resultString = new string('\0', bytes.Length * 2);
- fixed (char* stringPtr = &resultString.GetPinnableReference())
- {
- var destUints = (uint*) stringPtr;
- for (var i = 0; i < bytes.Length; i++)
- {
- destUints[i] = TableToHexUtf16[bytes[i]];
- }
- }
-
- return resultString;
- }
-}
diff --git a/src/Dodo.Primitives/Internal/InternalHexTables.cs b/src/Dodo.Primitives/Internal/InternalHexTables.cs
index 11e3ad0..0d86405 100644
--- a/src/Dodo.Primitives/Internal/InternalHexTables.cs
+++ b/src/Dodo.Primitives/Internal/InternalHexTables.cs
@@ -6,7 +6,7 @@ namespace Dodo.Primitives.Internal;
internal static unsafe class InternalHexTables
{
- internal const ushort MaximalChar = 103;
+ internal const ushort MaximalChar = 128;
internal static readonly uint* TableToHexUtf16;
internal static readonly ushort* TableToHexUtf8;
internal static readonly byte* TableFromHexToBytesUtf16;
diff --git a/src/Dodo.Primitives/Uuid.cs b/src/Dodo.Primitives/Uuid.cs
index 16bbf44..9411800 100644
--- a/src/Dodo.Primitives/Uuid.cs
+++ b/src/Dodo.Primitives/Uuid.cs
@@ -1,4 +1,5 @@
using System;
+using System.Buffers.Binary;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@@ -23,7 +24,8 @@ public unsafe struct Uuid :
ISpanFormattable,
IComparable,
IComparable,
- IEquatable, IFormattable
+ IEquatable,
+ IFormattable
#if NET8_0_OR_GREATER
, ISpanParsable, IParsable, IUtf8SpanFormattable, IComparisonOperators
#endif
@@ -63,7 +65,29 @@ static Uuid()
///
// ReSharper disable once RedundantDefaultMemberInitializer
// ReSharper disable once MemberCanBePrivate.Global
- public static readonly Uuid Empty = new Uuid();
+ // ReSharper disable once UnassignedReadonlyField
+ public static readonly Uuid Empty;
+
+ /// Gets a where all bits are set.
+ /// This returns the value: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
+ public static Uuid AllBitsSet => new Uuid(
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue,
+ byte.MaxValue);
+
///
/// Initializes a new instance of the structure by using the specified array of bytes.
@@ -82,15 +106,6 @@ public Uuid(byte[] bytes)
this = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(bytes.AsSpan()));
}
- ///
- /// Initializes a new instance of the structure by using the specified byte pointer.
- ///
- /// A byte pointer containing bytes which used to initialize the .
- public Uuid(byte* bytes)
- {
- this = Unsafe.ReadUnaligned(bytes);
- }
-
///
/// Initializes a new instance of the structure by using the value represented by the specified read-only span of
/// bytes.
@@ -107,6 +122,124 @@ public Uuid(ReadOnlySpan bytes)
this = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(bytes));
}
+ ///
+ /// Initializes a new instance of the structure by using the specified bytes, numbering from zero.
+ ///
+ /// Byte 0.
+ /// Byte 1.
+ /// Byte 2.
+ /// Byte 3.
+ /// Byte 4.
+ /// Byte 5.
+ /// Byte 6.
+ /// Byte 7.
+ /// Byte 8.
+ /// Byte 9.
+ /// Byte 10.
+ /// Byte 11.
+ /// Byte 12.
+ /// Byte 13.
+ /// Byte 14.
+ /// Byte 15.
+ public Uuid(
+ byte byte0,
+ byte byte1,
+ byte byte2,
+ byte byte3,
+ byte byte4,
+ byte byte5,
+ byte byte6,
+ byte byte7,
+ byte byte8,
+ byte byte9,
+ byte byte10,
+ byte byte11,
+ byte byte12,
+ byte byte13,
+ byte byte14,
+ byte byte15)
+ {
+ _byte0 = byte0;
+ _byte1 = byte1;
+ _byte2 = byte2;
+ _byte3 = byte3;
+ _byte4 = byte4;
+ _byte5 = byte5;
+ _byte6 = byte6;
+ _byte7 = byte7;
+ _byte8 = byte8;
+ _byte9 = byte9;
+ _byte10 = byte10;
+ _byte11 = byte11;
+ _byte12 = byte12;
+ _byte13 = byte13;
+ _byte14 = byte14;
+ _byte15 = byte15;
+ }
+
+ /// Gets the value of the variant field for the .
+ ///
+ /// This corresponds to the most significant 4 bits of the 8th byte: 00000000-0000-0000-F000-000000000000. The "don't-care" bits are not masked out.
+ /// See RFC 9562 for more information on how to interpret this value.
+ ///
+ public int Variant => _byte8 >> 4;
+
+ /// Gets the value of the version field for the .
+ ///
+ /// This corresponds to the most significant 4 bits of the 6th byte: 00000000-0000-F000-0000-000000000000.
+ /// See RFC 9562 for more information on how to interpret this value.
+ ///
+ public int Version => _byte6 >> 4;
+
+ /// Creates a new according to RFC 9562, following the Version 7 format.
+ /// A new according to RFC 9562, following the Version 7 format.
+ ///
+ /// This uses to determine the Unix Epoch timestamp source.
+ /// This seeds the unix_ts_ms, rand_a and 2 bits of rand_b fields with the number of ticks of the Unix time epoch. The remain part of field rand_b is filled with random data.
+ ///
+ public static Uuid CreateVersion7()
+ {
+ return CreateVersion7(DateTimeOffset.UtcNow);
+ }
+
+ /// Creates a new according to RFC 9562, following the Version 7 format.
+ /// The date time offset used to determine the Unix Epoch timestamp.
+ /// A new according to RFC 9562, following the Version 7 format.
+ /// represents an offset prior to .
+ ///
+ /// This seeds the unix_ts_ms, rand_a and 2 bits of rand_b fields with the number of ticks of the Unix time epoch. The remain part of field rand_b is filled with random data.
+ ///
+ public static Uuid CreateVersion7(DateTimeOffset timestamp)
+ {
+ const long unixEpochTicks = 621_355_968_000_000_000L;
+ const byte variant10XxMask = 0b11000000;
+ const byte variant10XxValue = 0b10000000;
+ const ushort version7Mask = 0b11110000_00000000;
+ const ushort version7Value = 0b01110000_00000000;
+ const ushort ticksNotFitInRandAExtractMask = 0b00000000_00000011;
+ const ushort ticksNotFitInRandASetMask = 0b00110000;
+ if (timestamp.UtcTicks < unixEpochTicks)
+ {
+ throw new ArgumentOutOfRangeException(
+ $"{nameof(timestamp)} must be greater than {DateTimeOffset.UnixEpoch}.");
+ }
+
+ Span result = stackalloc byte[16];
+ var tempGuid = Guid.NewGuid();
+ tempGuid.TryWriteBytes(result);
+ var unixTsTicks = (ulong) (timestamp.UtcTicks - unixEpochTicks);
+ ulong unixTsMs = unixTsTicks / TimeSpan.TicksPerMillisecond;
+ BinaryPrimitives.WriteUInt64BigEndian(result, unixTsMs << 16);
+ var remainTicks = (ushort) (unixTsTicks - (unixTsMs * TimeSpan.TicksPerMillisecond)); // up to 14 bits
+ var randA = (ushort) (remainTicks >> 2);
+ var randAVer = (ushort) ((randA & ~version7Mask) | version7Value);
+ BinaryPrimitives.WriteUInt16BigEndian(result[6..], randAVer);
+ result[8] = (byte) ((result[8] & ~variant10XxMask) | variant10XxValue);
+ var ticksNotFitInRandA = (byte) ((byte) (remainTicks & ticksNotFitInRandAExtractMask) << 4);
+ result[8] = (byte) ((result[8] & ~ticksNotFitInRandASetMask) | ticksNotFitInRandA);
+ return new Uuid(result);
+ }
+
///
/// Returns a 16-element byte array that contains the value of this instance.
///
@@ -158,84 +291,18 @@ public int CompareTo(object? obj)
}
var other = (Uuid) obj;
- if (other._byte0 != _byte0)
- {
- return _byte0 < other._byte0 ? -1 : 1;
- }
-
- if (other._byte1 != _byte1)
- {
- return _byte1 < other._byte1 ? -1 : 1;
- }
-
- if (other._byte2 != _byte2)
- {
- return _byte2 < other._byte2 ? -1 : 1;
- }
-
- if (other._byte3 != _byte3)
- {
- return _byte3 < other._byte3 ? -1 : 1;
- }
-
- if (other._byte4 != _byte4)
- {
- return _byte4 < other._byte4 ? -1 : 1;
- }
-
- if (other._byte5 != _byte5)
- {
- return _byte5 < other._byte5 ? -1 : 1;
- }
-
- if (other._byte6 != _byte6)
+ ref ulong rSelfHi = ref Unsafe.As(ref this);
+ ref ulong rSelfLo = ref Unsafe.Add(ref rSelfHi, 1);
+ ref ulong rOtherHi = ref Unsafe.As(ref other);
+ ref ulong rOtherLo = ref Unsafe.Add(ref rOtherHi, 1);
+ if (rSelfHi != rOtherHi)
{
- return _byte6 < other._byte6 ? -1 : 1;
+ return rSelfHi < rOtherHi ? -1 : 1;
}
- if (other._byte7 != _byte7)
+ if (rSelfLo != rOtherLo)
{
- return _byte7 < other._byte7 ? -1 : 1;
- }
-
- if (other._byte8 != _byte8)
- {
- return _byte8 < other._byte8 ? -1 : 1;
- }
-
- if (other._byte9 != _byte9)
- {
- return _byte9 < other._byte9 ? -1 : 1;
- }
-
- if (other._byte10 != _byte10)
- {
- return _byte10 < other._byte10 ? -1 : 1;
- }
-
- if (other._byte11 != _byte11)
- {
- return _byte11 < other._byte11 ? -1 : 1;
- }
-
- if (other._byte12 != _byte12)
- {
- return _byte12 < other._byte12 ? -1 : 1;
- }
-
- if (other._byte13 != _byte13)
- {
- return _byte13 < other._byte13 ? -1 : 1;
- }
-
- if (other._byte14 != _byte14)
- {
- return _byte14 < other._byte14 ? -1 : 1;
- }
-
- if (other._byte15 != _byte15)
- {
- return _byte15 < other._byte15 ? -1 : 1;
+ return rSelfLo < rOtherLo ? -1 : 1;
}
return 0;
@@ -248,84 +315,19 @@ public int CompareTo(object? obj)
/// A signed number indicating the relative values of this instance and .
public int CompareTo(Uuid other)
{
- if (other._byte0 != _byte0)
- {
- return _byte0 < other._byte0 ? -1 : 1;
- }
-
- if (other._byte1 != _byte1)
- {
- return _byte1 < other._byte1 ? -1 : 1;
- }
-
- if (other._byte2 != _byte2)
- {
- return _byte2 < other._byte2 ? -1 : 1;
- }
-
- if (other._byte3 != _byte3)
- {
- return _byte3 < other._byte3 ? -1 : 1;
- }
-
- if (other._byte4 != _byte4)
- {
- return _byte4 < other._byte4 ? -1 : 1;
- }
-
- if (other._byte5 != _byte5)
- {
- return _byte5 < other._byte5 ? -1 : 1;
- }
+ ref ulong rSelfHi = ref Unsafe.As(ref this);
+ ref ulong rSelfLo = ref Unsafe.Add(ref rSelfHi, 1);
+ ref ulong rOtherHi = ref Unsafe.As(ref other);
+ ref ulong rOtherLo = ref Unsafe.Add(ref rOtherHi, 1);
- if (other._byte6 != _byte6)
+ if (rSelfHi != rOtherHi)
{
- return _byte6 < other._byte6 ? -1 : 1;
+ return rSelfHi < rOtherHi ? -1 : 1;
}
- if (other._byte7 != _byte7)
+ if (rSelfLo != rOtherLo)
{
- return _byte7 < other._byte7 ? -1 : 1;
- }
-
- if (other._byte8 != _byte8)
- {
- return _byte8 < other._byte8 ? -1 : 1;
- }
-
- if (other._byte9 != _byte9)
- {
- return _byte9 < other._byte9 ? -1 : 1;
- }
-
- if (other._byte10 != _byte10)
- {
- return _byte10 < other._byte10 ? -1 : 1;
- }
-
- if (other._byte11 != _byte11)
- {
- return _byte11 < other._byte11 ? -1 : 1;
- }
-
- if (other._byte12 != _byte12)
- {
- return _byte12 < other._byte12 ? -1 : 1;
- }
-
- if (other._byte13 != _byte13)
- {
- return _byte13 < other._byte13 ? -1 : 1;
- }
-
- if (other._byte14 != _byte14)
- {
- return _byte14 < other._byte14 ? -1 : 1;
- }
-
- if (other._byte15 != _byte15)
- {
- return _byte15 < other._byte15 ? -1 : 1;
+ return rSelfLo < rOtherLo ? -1 : 1;
}
return 0;
@@ -932,7 +934,6 @@ public string ToString(
}
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf8N(byte* dest)
{
// dddddddddddddddddddddddddddddddd
@@ -955,7 +956,6 @@ private void FormatUtf8N(byte* dest)
destInt16[15] = TableToHexUtf8[_byte15];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf8D(byte* dest)
{
// dddddddd-dddd-dddd-dddd-dddddddddddd
@@ -981,7 +981,6 @@ private void FormatUtf8D(byte* dest)
destInt16[10] = TableToHexUtf8[_byte9];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf8B(byte* dest)
{
// {dddddddd-dddd-dddd-dddd-dddddddddddd}
@@ -1009,7 +1008,6 @@ private void FormatUtf8B(byte* dest)
destInt16[17] = TableToHexUtf8[_byte15];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf8P(byte* dest)
{
// (dddddddd-dddd-dddd-dddd-dddddddddddd)
@@ -1037,7 +1035,6 @@ private void FormatUtf8P(byte* dest)
destInt16[17] = TableToHexUtf8[_byte15];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf8X(byte* dest)
{
const ushort zeroXUtf8 = ('x' << 8) | '0'; // 0x
@@ -1072,7 +1069,6 @@ private void FormatUtf8X(byte* dest)
destInt16[29] = TableToHexUtf8[_byte14];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf16N(char* dest)
{
// dddddddddddddddddddddddddddddddd
@@ -1095,7 +1091,6 @@ private void FormatUtf16N(char* dest)
destInt32[15] = TableToHexUtf16[_byte15];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf16D(char* dest)
{
// dddddddd-dddd-dddd-dddd-dddddddddddd
@@ -1121,7 +1116,6 @@ private void FormatUtf16D(char* dest)
destInt32[10] = TableToHexUtf16[_byte9];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf16B(char* dest)
{
// {dddddddd-dddd-dddd-dddd-dddddddddddd}
@@ -1149,7 +1143,6 @@ private void FormatUtf16B(char* dest)
destInt32[17] = TableToHexUtf16[_byte15];
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf16P(char* dest)
{
// (dddddddd-dddd-dddd-dddd-dddddddddddd)
@@ -1177,8 +1170,6 @@ private void FormatUtf16P(char* dest)
destInt32[17] = TableToHexUtf16[_byte15];
}
-
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void FormatUtf16X(char* dest)
{
const uint zeroXUtf16 = ((uint) 'x' << 16) | '0'; // 0x
@@ -1214,10 +1205,13 @@ private void FormatUtf16X(char* dest)
}
///
- /// Converts to preserve same binary representation.
+ ///
+ /// Obsolete. Use instead.
+ ///
+ /// Converts to preserve same binary representation (little endian).
///
- ///
- [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining)]
+ /// with same binary representation (little endian).
+ [Obsolete("Use ToGuidLittleEndian() instead.")]
public Guid ToGuidByteLayout()
{
var result = new Guid();
@@ -1243,10 +1237,41 @@ public Guid ToGuidByteLayout()
}
///
- /// Converts to preserve same string representation.
+ /// Converts to in little endian format.
///
- ///
- [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining)]
+ /// in little endian format.
+ public Guid ToGuidLittleEndian()
+ {
+ var result = new Guid();
+ Guid* resultPtr = &result;
+ var resultPtrBytes = (byte*) resultPtr;
+ resultPtrBytes[0] = _byte0;
+ resultPtrBytes[1] = _byte1;
+ resultPtrBytes[2] = _byte2;
+ resultPtrBytes[3] = _byte3;
+ resultPtrBytes[4] = _byte4;
+ resultPtrBytes[5] = _byte5;
+ resultPtrBytes[6] = _byte6;
+ resultPtrBytes[7] = _byte7;
+ resultPtrBytes[8] = _byte8;
+ resultPtrBytes[9] = _byte9;
+ resultPtrBytes[10] = _byte10;
+ resultPtrBytes[11] = _byte11;
+ resultPtrBytes[12] = _byte12;
+ resultPtrBytes[13] = _byte13;
+ resultPtrBytes[14] = _byte14;
+ resultPtrBytes[15] = _byte15;
+ return result;
+ }
+
+ ///
+ ///
+ /// Obsolete. Use instead.
+ ///
+ /// Converts to preserve same string representation (big endian).
+ ///
+ /// with same string representation (big endian).
+ [Obsolete("Use ToGuidBigEndian() instead.")]
public Guid ToGuidStringLayout()
{
var result = new Guid();
@@ -1271,6 +1296,34 @@ public Guid ToGuidStringLayout()
return result;
}
+ ///
+ /// Converts to in big endian format.
+ ///
+ /// in big endian format.
+ public Guid ToGuidBigEndian()
+ {
+ var result = new Guid();
+ Guid* resultPtr = &result;
+ var resultPtrBytes = (byte*) resultPtr;
+ resultPtrBytes[0] = _byte3;
+ resultPtrBytes[1] = _byte2;
+ resultPtrBytes[2] = _byte1;
+ resultPtrBytes[3] = _byte0;
+ resultPtrBytes[4] = _byte5;
+ resultPtrBytes[5] = _byte4;
+ resultPtrBytes[6] = _byte7;
+ resultPtrBytes[7] = _byte6;
+ resultPtrBytes[8] = _byte8;
+ resultPtrBytes[9] = _byte9;
+ resultPtrBytes[10] = _byte10;
+ resultPtrBytes[11] = _byte11;
+ resultPtrBytes[12] = _byte12;
+ resultPtrBytes[13] = _byte13;
+ resultPtrBytes[14] = _byte14;
+ resultPtrBytes[15] = _byte15;
+ return result;
+ }
+
///
/// Initializes a new instance of the structure by using the value represented by the specified string.
///
@@ -2324,7 +2377,6 @@ private static void ParseWithExceptionsX(uint uuidStringLength, char* uuidString
}
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrN(char* value, byte* resultPtr)
{
// e.g. "d85b1407351d4694939203acc5870eb1"
@@ -2463,7 +2515,6 @@ private static bool TryParsePtrN(char* value, byte* resultPtr)
return false;
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrD(char* value, byte* resultPtr)
{
// e.g. "d85b1407-351d-4694-9392-03acc5870eb1"
@@ -2614,7 +2665,6 @@ private static bool TryParsePtrD(char* value, byte* resultPtr)
return false;
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrX(char* value, byte* resultPtr)
{
// e.g. "{0xd85b1407,0x351d,0x4694,{0x93,0x92,0x03,0xac,0xc5,0x87,0x0e,0xb1}}"
@@ -2808,7 +2858,6 @@ private static bool TryParsePtrX(char* value, byte* resultPtr)
return false;
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrNUtf8(byte* value, byte* resultPtr)
{
// e.g. "d85b1407351d4694939203acc5870eb1"
@@ -2947,7 +2996,6 @@ private static bool TryParsePtrNUtf8(byte* value, byte* resultPtr)
return false;
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr)
{
// e.g. "d85b1407-351d-4694-9392-03acc5870eb1"
@@ -3098,7 +3146,6 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr)
return false;
}
- [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr)
{
// e.g. "{0xd85b1407,0x351d,0x4694,{0x93,0x92,0x03,0xac,0xc5,0x87,0x0e,0xb1}}"
@@ -3307,84 +3354,18 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr)
#endif
public static bool operator <(Uuid left, Uuid right)
{
- if (left._byte0 != right._byte0)
+ ref ulong leftHi = ref Unsafe.As(ref left);
+ ref ulong leftLo = ref Unsafe.Add(ref leftHi, 1);
+ ref ulong rightHi = ref Unsafe.As(ref right);
+ ref ulong rightLo = ref Unsafe.Add(ref rightHi, 1);
+ if (leftHi != rightHi)
{
- return left._byte0 < right._byte0;
+ return leftHi < rightHi;
}
- if (left._byte1 != right._byte1)
+ if (leftLo != rightLo)
{
- return left._byte1 < right._byte1;
- }
-
- if (left._byte2 != right._byte2)
- {
- return left._byte2 < right._byte2;
- }
-
- if (left._byte3 != right._byte3)
- {
- return left._byte3 < right._byte3;
- }
-
- if (left._byte4 != right._byte4)
- {
- return left._byte4 < right._byte4;
- }
-
- if (left._byte5 != right._byte5)
- {
- return left._byte5 < right._byte5;
- }
-
- if (left._byte6 != right._byte6)
- {
- return left._byte6 < right._byte6;
- }
-
- if (left._byte7 != right._byte7)
- {
- return left._byte7 < right._byte7;
- }
-
- if (left._byte8 != right._byte8)
- {
- return left._byte8 < right._byte8;
- }
-
- if (left._byte9 != right._byte9)
- {
- return left._byte9 < right._byte9;
- }
-
- if (left._byte10 != right._byte10)
- {
- return left._byte10 < right._byte10;
- }
-
- if (left._byte11 != right._byte11)
- {
- return left._byte11 < right._byte11;
- }
-
- if (left._byte12 != right._byte12)
- {
- return left._byte12 < right._byte12;
- }
-
- if (left._byte13 != right._byte13)
- {
- return left._byte13 < right._byte13;
- }
-
- if (left._byte14 != right._byte14)
- {
- return left._byte14 < right._byte14;
- }
-
- if (left._byte15 != right._byte15)
- {
- return left._byte15 < right._byte15;
+ return leftLo < rightLo;
}
return false;
@@ -3405,84 +3386,18 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr)
#endif
public static bool operator <=(Uuid left, Uuid right)
{
- if (left._byte0 != right._byte0)
- {
- return left._byte0 < right._byte0;
- }
-
- if (left._byte1 != right._byte1)
- {
- return left._byte1 < right._byte1;
- }
-
- if (left._byte2 != right._byte2)
- {
- return left._byte2 < right._byte2;
- }
-
- if (left._byte3 != right._byte3)
- {
- return left._byte3 < right._byte3;
- }
-
- if (left._byte4 != right._byte4)
- {
- return left._byte4 < right._byte4;
- }
-
- if (left._byte5 != right._byte5)
+ ref ulong leftHi = ref Unsafe.As(ref left);
+ ref ulong leftLo = ref Unsafe.Add(ref leftHi, 1);
+ ref ulong rightHi = ref Unsafe.As(ref right);
+ ref ulong rightLo = ref Unsafe.Add(ref rightHi, 1);
+ if (leftHi != rightHi)
{
- return left._byte5 < right._byte5;
+ return leftHi < rightHi;
}
- if (left._byte6 != right._byte6)
+ if (leftLo != rightLo)
{
- return left._byte6 < right._byte6;
- }
-
- if (left._byte7 != right._byte7)
- {
- return left._byte7 < right._byte7;
- }
-
- if (left._byte8 != right._byte8)
- {
- return left._byte8 < right._byte8;
- }
-
- if (left._byte9 != right._byte9)
- {
- return left._byte9 < right._byte9;
- }
-
- if (left._byte10 != right._byte10)
- {
- return left._byte10 < right._byte10;
- }
-
- if (left._byte11 != right._byte11)
- {
- return left._byte11 < right._byte11;
- }
-
- if (left._byte12 != right._byte12)
- {
- return left._byte12 < right._byte12;
- }
-
- if (left._byte13 != right._byte13)
- {
- return left._byte13 < right._byte13;
- }
-
- if (left._byte14 != right._byte14)
- {
- return left._byte14 < right._byte14;
- }
-
- if (left._byte15 != right._byte15)
- {
- return left._byte15 < right._byte15;
+ return leftLo < rightLo;
}
return true;
@@ -3503,84 +3418,18 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr)
#endif
public static bool operator >(Uuid left, Uuid right)
{
- if (left._byte0 != right._byte0)
- {
- return left._byte0 > right._byte0;
- }
-
- if (left._byte1 != right._byte1)
+ ref ulong leftHi = ref Unsafe.As(ref left);
+ ref ulong leftLo = ref Unsafe.Add(ref leftHi, 1);
+ ref ulong rightHi = ref Unsafe.As(ref right);
+ ref ulong rightLo = ref Unsafe.Add(ref rightHi, 1);
+ if (leftHi != rightHi)
{
- return left._byte1 > right._byte1;
+ return leftHi > rightHi;
}
- if (left._byte2 != right._byte2)
+ if (leftLo != rightLo)
{
- return left._byte2 > right._byte2;
- }
-
- if (left._byte3 != right._byte3)
- {
- return left._byte3 > right._byte3;
- }
-
- if (left._byte4 != right._byte4)
- {
- return left._byte4 > right._byte4;
- }
-
- if (left._byte5 != right._byte5)
- {
- return left._byte5 > right._byte5;
- }
-
- if (left._byte6 != right._byte6)
- {
- return left._byte6 > right._byte6;
- }
-
- if (left._byte7 != right._byte7)
- {
- return left._byte7 > right._byte7;
- }
-
- if (left._byte8 != right._byte8)
- {
- return left._byte8 > right._byte8;
- }
-
- if (left._byte9 != right._byte9)
- {
- return left._byte9 > right._byte9;
- }
-
- if (left._byte10 != right._byte10)
- {
- return left._byte10 > right._byte10;
- }
-
- if (left._byte11 != right._byte11)
- {
- return left._byte11 > right._byte11;
- }
-
- if (left._byte12 != right._byte12)
- {
- return left._byte12 > right._byte12;
- }
-
- if (left._byte13 != right._byte13)
- {
- return left._byte13 > right._byte13;
- }
-
- if (left._byte14 != right._byte14)
- {
- return left._byte14 > right._byte14;
- }
-
- if (left._byte15 != right._byte15)
- {
- return left._byte15 > right._byte15;
+ return leftLo > rightLo;
}
return false;
@@ -3601,84 +3450,18 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr)
#endif
public static bool operator >=(Uuid left, Uuid right)
{
- if (left._byte0 != right._byte0)
- {
- return left._byte0 > right._byte0;
- }
-
- if (left._byte1 != right._byte1)
- {
- return left._byte1 > right._byte1;
- }
-
- if (left._byte2 != right._byte2)
- {
- return left._byte2 > right._byte2;
- }
-
- if (left._byte3 != right._byte3)
- {
- return left._byte3 > right._byte3;
- }
-
- if (left._byte4 != right._byte4)
- {
- return left._byte4 > right._byte4;
- }
-
- if (left._byte5 != right._byte5)
- {
- return left._byte5 > right._byte5;
- }
-
- if (left._byte6 != right._byte6)
- {
- return left._byte6 > right._byte6;
- }
-
- if (left._byte7 != right._byte7)
- {
- return left._byte7 > right._byte7;
- }
-
- if (left._byte8 != right._byte8)
- {
- return left._byte8 > right._byte8;
- }
-
- if (left._byte9 != right._byte9)
- {
- return left._byte9 > right._byte9;
- }
-
- if (left._byte10 != right._byte10)
- {
- return left._byte10 > right._byte10;
- }
-
- if (left._byte11 != right._byte11)
- {
- return left._byte11 > right._byte11;
- }
-
- if (left._byte12 != right._byte12)
- {
- return left._byte12 > right._byte12;
- }
-
- if (left._byte13 != right._byte13)
- {
- return left._byte13 > right._byte13;
- }
-
- if (left._byte14 != right._byte14)
+ ref ulong leftHi = ref Unsafe.As(ref left);
+ ref ulong leftLo = ref Unsafe.Add(ref leftHi, 1);
+ ref ulong rightHi = ref Unsafe.As(ref right);
+ ref ulong rightLo = ref Unsafe.Add(ref rightHi, 1);
+ if (leftHi != rightHi)
{
- return left._byte14 > right._byte14;
+ return leftHi > rightHi;
}
- if (left._byte15 != right._byte15)
+ if (leftLo != rightLo)
{
- return left._byte15 > right._byte15;
+ return leftLo > rightLo;
}
return true;
@@ -3707,7 +3490,7 @@ public static Uuid Parse(string s, IFormatProvider? provider)
///
#else
///
- /// Tries to parses a string into a value.
+ /// Tries to parse a string into a value.
///
/// The string to parse.
/// An object that provides culture-specific formatting information about .
@@ -3741,7 +3524,7 @@ public static Uuid Parse(ReadOnlySpan s, IFormatProvider? provider)
///
#else
///
- /// Tries to parses a span of characters into a value.
+ /// Tries to parse a span of characters into a value.
///
/// The span of characters to parse.
/// An object that provides culture-specific formatting information about .
@@ -3764,9 +3547,13 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out
private const byte ReservedFlag = 0b1000_0000;
///
- /// Initializes a new instance of the structure that represents Uuid v1 (RFC4122).
+ ///
+ /// Obsolete. Use instead.
+ ///
+ /// Initializes a new instance of the structure that represents Uuid v1 (RFC4122).
///
///
+ [Obsolete("Use CreateVersion7() instead.")]
public static Uuid NewTimeBased()
{
byte* resultPtr = stackalloc byte[16];
@@ -3784,13 +3571,17 @@ public static Uuid NewTimeBased()
resultPtr[6] = (byte) ((ticksPtr[7] & ResetVersionMask) | Version1Flag);
resultPtr[7] = ticksPtr[6];
resultPtr[8] = (byte) ((resultPtr[8] & ResetReservedMask) | ReservedFlag);
- return new Uuid(resultPtr);
+ return new Uuid(new Span(resultPtr, 16));
}
///
- /// Initializes a new instance of the structure that works the same way as UUID_TO_BIN(UUID(), 1) from MySQL 8.0.
+ ///
+ /// Obsolete. Use instead.
+ ///
+ /// Initializes a new instance of the structure that works the same way as UUID_TO_BIN(UUID(), 1) from MySQL 8.0.
///
///
+ [Obsolete("Use CreateVersion7() instead.")]
public static Uuid NewMySqlOptimized()
{
byte* resultPtr = stackalloc byte[16];
@@ -3808,7 +3599,7 @@ public static Uuid NewMySqlOptimized()
resultPtr[6] = ticksPtr[1];
resultPtr[7] = ticksPtr[0];
resultPtr[8] = (byte) ((resultPtr[8] & ResetReservedMask) | ReservedFlag);
- return new Uuid(resultPtr);
+ return new Uuid(new Span(resultPtr, 16));
}
#endregion
diff --git a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj
index f8ab8c4..bda65a6 100644
--- a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj
+++ b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj
@@ -2,15 +2,15 @@
Exe
- net8.0
- 12.0
+ net9.0
+ 13.0
enable
disable
true
-
+
diff --git a/tools/Dodo.Primitives.Tools.sln b/tools/Dodo.Primitives.Tools.sln
deleted file mode 100644
index b4718ba..0000000
--- a/tools/Dodo.Primitives.Tools.sln
+++ /dev/null
@@ -1,25 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30011.22
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dodo.Primitives.Tools.CompareVersions", "Dodo.Primitives.Tools.CompareVersions\Dodo.Primitives.Tools.CompareVersions.csproj", "{9BD07E2C-4EAA-4FC5-8D8F-20D4EE16C4D3}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9BD07E2C-4EAA-4FC5-8D8F-20D4EE16C4D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9BD07E2C-4EAA-4FC5-8D8F-20D4EE16C4D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9BD07E2C-4EAA-4FC5-8D8F-20D4EE16C4D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9BD07E2C-4EAA-4FC5-8D8F-20D4EE16C4D3}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {55D2DDB3-2AF1-424D-8F55-7C0157149A16}
- EndGlobalSection
-EndGlobal
diff --git a/tools/Dodo.Primitives.Tools.slnx b/tools/Dodo.Primitives.Tools.slnx
new file mode 100644
index 0000000..544c70e
--- /dev/null
+++ b/tools/Dodo.Primitives.Tools.slnx
@@ -0,0 +1,3 @@
+
+
+