From a6e96eb51c85bb9e9b8a3270510c36e521874d3f Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Mon, 2 Jan 2023 14:38:05 -0600 Subject: [PATCH] Upgraded build to GitHub Actions, reset folder structure to match other projects --- .github/workflows/build.yml | 97 +++++ src/NewId.sln => NewId.sln | 83 ++-- appveyor.yml | 48 --- build.cake | 115 ----- build.ps1 | 242 ----------- build.sh | 117 ------ build/parameters.cake | 63 --- build/paths.cake | 64 --- build/version.cake | 57 --- .../NewId.Benchmarks/Benchmarker.cs | 0 .../NewId.Benchmarks/NewId.Benchmarks.csproj | 2 +- {src => tests}/NewId.Benchmarks/Program.cs | 0 {src => tests}/NewId.Tests/Formatter_Specs.cs | 282 ++++++------- {src => tests}/NewId.Tests/Generator_Specs.cs | 0 .../NewId.Tests/GuidInterop_Specs.cs | 388 ++++++++--------- {src => tests}/NewId.Tests/LongTerm_Specs.cs | 108 ++--- .../NewId.Tests/NetworkAddress_Specs.cs | 126 +++--- {src => tests}/NewId.Tests/NewId.Tests.csproj | 57 ++- {src => tests}/NewId.Tests/NewId_Specs.cs | 394 +++++++++--------- {src => tests}/NewId.Tests/Order_Specs.cs | 0 {src => tests}/NewId.Tests/Usage_Specs.cs | 110 ++--- {src => tests}/NewId.Tests/guids.txt | 0 {src => tests}/NewId.Tests/texts.txt | 0 tools/packages.config | 4 - 24 files changed, 867 insertions(+), 1490 deletions(-) create mode 100644 .github/workflows/build.yml rename src/NewId.sln => NewId.sln (71%) delete mode 100644 appveyor.yml delete mode 100644 build.cake delete mode 100644 build.ps1 delete mode 100755 build.sh delete mode 100644 build/parameters.cake delete mode 100644 build/paths.cake delete mode 100644 build/version.cake rename {src => tests}/NewId.Benchmarks/Benchmarker.cs (100%) rename {src => tests}/NewId.Benchmarks/NewId.Benchmarks.csproj (86%) rename {src => tests}/NewId.Benchmarks/Program.cs (100%) rename {src => tests}/NewId.Tests/Formatter_Specs.cs (96%) rename {src => tests}/NewId.Tests/Generator_Specs.cs (100%) rename {src => tests}/NewId.Tests/GuidInterop_Specs.cs (96%) rename {src => tests}/NewId.Tests/LongTerm_Specs.cs (96%) rename {src => tests}/NewId.Tests/NetworkAddress_Specs.cs (97%) rename {src => tests}/NewId.Tests/NewId.Tests.csproj (84%) rename {src => tests}/NewId.Tests/NewId_Specs.cs (96%) rename {src => tests}/NewId.Tests/Order_Specs.cs (100%) rename {src => tests}/NewId.Tests/Usage_Specs.cs (96%) rename {src => tests}/NewId.Tests/guids.txt (100%) rename {src => tests}/NewId.Tests/texts.txt (100%) delete mode 100644 tools/packages.config diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c0d8504 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,97 @@ +name: NewId +env: + NEWID_VERSION: 4.0.1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: true +on: + push: + paths: + - 'src/**' + - 'tests/**' + - 'NewId.sln' + - 'Directory.Build.props' + - '**/build.yml' + pull_request: + paths: + - 'src/**' + - 'tests/**' + - 'NewId.sln' + - 'Directory.Build.props' + - '**/build.yml' + workflow_dispatch: + +jobs: + compile: + name: Compile and Unit Tests + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + + - name: Restore NuGet packages + run: dotnet restore + working-directory: ./ + + - name: Build + run: dotnet build -c Release --no-restore + working-directory: ./ + + - name: Test + run: dotnet test -c Release --no-build + working-directory: tests/NewId.Tests + + calc-version: + name: Calculate Version + runs-on: ubuntu-latest + needs: + - compile + outputs: + version: ${{ steps.v.outputs.version }} + steps: + - id: v + run: | + if [ "${{ github.ref }}" = 'refs/heads/master' ]; then + echo "::set-output name=version::${NEWID_VERSION}" + else + echo "::set-output name=version::${NEWID_VERSION}-develop.${{ github.run_number }}" + fi + + publish: + name: Build and Publish NuGets + runs-on: ubuntu-latest + if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.repository == 'MassTransit/NewId' && success() + needs: + - calc-version + steps: + - name: Version Output Check + run: | + echo "${{ needs.calc-version.outputs.version }}" + + - name: Check out code + uses: actions/checkout@v2 + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + + - name: Build and Publish NewId + # was: brandedoutcast/publish-nuget@v2.5.5 + uses: drusellers/publish-nuget@master + with: + project-file-path: src/NewId/NewId.csproj + version: ${{ needs.calc-version.outputs.version }} + tag-commit: false + nuget-key: ${{secrets.NUGET_API_KEY}} + include-symbols: true + diff --git a/src/NewId.sln b/NewId.sln similarity index 71% rename from src/NewId.sln rename to NewId.sln index 9635d4e..b354388 100644 --- a/src/NewId.sln +++ b/NewId.sln @@ -1,46 +1,37 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewId", "NewId\NewId.csproj", "{660D8862-F851-4C9B-A8AB-62A7EEA65614}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewId.Tests", "NewId.Tests\NewId.Tests.csproj", "{C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cake", "Cake", "{40320C2F-D164-462C-8E57-F91DADC8D440}" -ProjectSection(SolutionItems) = preProject - Directory.Build.props = Directory.Build.props - ..\appveyor.yml = ..\appveyor.yml - ..\build.cake = ..\build.cake - ..\build.ps1 = ..\build.ps1 - ..\build.sh = ..\build.sh -EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewId.Benchmarks", "NewId.Benchmarks\NewId.Benchmarks.csproj", "{0753A4DB-8D17-4D51-BC09-1F50D1B5820D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Debug|Any CPU.Build.0 = Debug|Any CPU - {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Release|Any CPU.ActiveCfg = Release|Any CPU - {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Release|Any CPU.Build.0 = Release|Any CPU - {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Release|Any CPU.Build.0 = Release|Any CPU - {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9BD652A7-9C0C-4784-AC00-8CC69969DDC5} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewId", "src\NewId\NewId.csproj", "{660D8862-F851-4C9B-A8AB-62A7EEA65614}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewId.Tests", "tests\NewId.Tests\NewId.Tests.csproj", "{C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewId.Benchmarks", "tests\NewId.Benchmarks\NewId.Benchmarks.csproj", "{0753A4DB-8D17-4D51-BC09-1F50D1B5820D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Debug|Any CPU.Build.0 = Debug|Any CPU + {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Release|Any CPU.ActiveCfg = Release|Any CPU + {660D8862-F851-4C9B-A8AB-62A7EEA65614}.Release|Any CPU.Build.0 = Release|Any CPU + {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C92C3C4B-5DA0-49C5-A382-E31FD69CDBCD}.Release|Any CPU.Build.0 = Release|Any CPU + {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0753A4DB-8D17-4D51-BC09-1F50D1B5820D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9BD652A7-9C0C-4784-AC00-8CC69969DDC5} + EndGlobalSection +EndGlobal diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index e43cd30..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: 4.0.0.{build} - -branches: - only: - - develop - - master - -skip_tags: true - -skip_commits: - files: - - docs/**/* - - package.json - - docs.yml - - readme.md - -image: - - Visual Studio 2019 - -build: off -test: off - -artifacts: - - path: artifacts/*.nupkg - name: NuGet - - path: artifacts/*.snupkg - name: Symbols - -build_script: - - ps: .\Build.ps1 - -deploy: -- provider: NuGet - name: Prerelease - symbol_server: https://www.nuget.org - artifact: NuGet, Symbols - api_key: - secure: u/Nk80LYwsBw+2kztOliHzTEaNI78K0pHFfzy7wx87zl8kgH5JXtdIPn5oTybnMs - on: - branch: develop -- provider: NuGet - name: Release - symbol_server: https://www.nuget.org - artifact: NuGet, Symbols - api_key: - secure: u/Nk80LYwsBw+2kztOliHzTEaNI78K0pHFfzy7wx87zl8kgH5JXtdIPn5oTybnMs - on: - branch: master diff --git a/build.cake b/build.cake deleted file mode 100644 index 785400b..0000000 --- a/build.cake +++ /dev/null @@ -1,115 +0,0 @@ -////////////////////////////////////////////////////////////////////// -// TOOLS -////////////////////////////////////////////////////////////////////// - -// Load other scripts. -#load "./build/parameters.cake" - -////////////////////////////////////////////////////////////////////// -// ARGUMENTS -////////////////////////////////////////////////////////////////////// - -var target = Argument("target", "Default"); - -////////////////////////////////////////////////////////////////////// -// PREPARATION -////////////////////////////////////////////////////////////////////// - -Setup(setupContext => -{ - var buildParams = BuildParameters.GetParameters(setupContext); - buildParams.Initialize(setupContext); - return buildParams; -}); - -////////////////////////////////////////////////////////////////////// -// TASKS -////////////////////////////////////////////////////////////////////// - -Task("Clean") - .Does(data => -{ - CleanDirectories($"./src/**/obj/{data.Configuration}"); - CleanDirectories($"./src/**/bin/{data.Configuration}"); - CleanDirectory(data.Paths.Directories.Artifacts); -}); - -Task("CleanAll") - .Does(data => -{ - CleanDirectories($"./src/**/obj"); - CleanDirectories($"./src/**/bin"); - CleanDirectory(data.Paths.Directories.Artifacts); -}); - -Task("Restore-NuGet") - .Does(data => -{ - DotNetCoreRestore(data.Paths.Directories.Solution.FullPath); -}); - -Task("Build") - .IsDependentOn("Clean") - .IsDependentOn("Restore-NuGet") - .Does(data => -{ - var settings = new DotNetCoreBuildSettings{ - NoRestore = true, - Configuration = data.Configuration, - MSBuildSettings = new DotNetCoreMSBuildSettings().WithProperty("Version", data.Version.Version) - }; - - DotNetCoreBuild(data.Paths.Directories.Solution.FullPath, settings); -}); - -Task("Test") - .IsDependentOn("Build") - .Does(data => -{ - var settings = new DotNetCoreTestSettings - { - NoBuild = true, - Configuration = data.Configuration, - DiagnosticOutput = true - }; - - if(data.IsRunningOnAppVeyor) settings.ArgumentCustomization = args => args.Append($"--test-adapter-path:.").Append("--logger:Appveyor"); - - Information($"Running {project.GetFilename()} test with SSE3 enabled"); - DotNetCoreTest(data.Paths.Directories.Solution.FullPath, settings); - - settings.EnvironmentVariables["COMPlus_EnableSSE3"] = "0"; - Information($"Running {project.GetFilename()} test with SSE3 disabled"); - DotNetTest(data.Paths.Directories.Solution.FullPath, settings); -}); - -Task("Pack") - .IsDependentOn("Build") - .WithCriteria((context,data) => data.ShouldPublish) - .Does(data => -{ - var settings = new DotNetCorePackSettings{ - NoBuild = true, - OutputDirectory = data.Paths.Directories.Artifacts, - Configuration = data.Configuration, - MSBuildSettings = new DotNetCoreMSBuildSettings().WithProperty("Version", data.Version.Version) - }; - DotNetCorePack(data.Paths.Directories.Solution.FullPath, settings); -}); - -////////////////////////////////////////////////////////////////////// -// TASK TARGETS -////////////////////////////////////////////////////////////////////// - -Task("Default") - .IsDependentOn("Clean") - .IsDependentOn("Restore-NuGet") - .IsDependentOn("Build") - .IsDependentOn("Test") - .IsDependentOn("Pack"); - -////////////////////////////////////////////////////////////////////// -// EXECUTION -////////////////////////////////////////////////////////////////////// - -RunTarget(target); diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index c6c91b2..0000000 --- a/build.ps1 +++ /dev/null @@ -1,242 +0,0 @@ -########################################################################## -# This is the Cake bootstrapper script for PowerShell. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -<# - -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. - -.DESCRIPTION -This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) -and execute your Cake build script with the parameters you provide. - -.PARAMETER Script -The build script to execute. -.PARAMETER Target -The build script target to run. -.PARAMETER Configuration -The build configuration to use. -.PARAMETER Verbosity -Specifies the amount of information to be displayed. -.PARAMETER ShowDescription -Shows description about tasks. -.PARAMETER DryRun -Performs a dry run. -.PARAMETER SkipToolPackageRestore -Skips restoring of packages. -.PARAMETER ScriptArgs -Remaining arguments are added here. - -.LINK -https://cakebuild.net - -#> - -[CmdletBinding()] -Param( - [string]$Script = "build.cake", - [string]$Target, - [string]$Configuration, - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity, - [switch]$ShowDescription, - [Alias("WhatIf", "Noop")] - [switch]$DryRun, - [switch]$SkipToolPackageRestore, - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs -) - -# Attempt to set highest encryption available for SecurityProtocol. -# PowerShell will not set this by default (until maybe .NET 4.6.x). This -# will typically produce a message for PowerShell v2 (just an info -# message though) -try { - # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) - # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't - # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is - # installed (.NET 4.5 is an in-place upgrade). - [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 - } catch { - Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3' - } - -[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) -{ - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) - { - return $null - } - - [System.IO.Stream] $file = $null; - [System.Security.Cryptography.MD5] $md5 = $null; - try - { - $md5 = [System.Security.Cryptography.MD5]::Create() - $file = [System.IO.File]::OpenRead($filePath) - return [System.BitConverter]::ToString($md5.ComputeHash($file)) - } - finally - { - if ($file -ne $null) - { - $file.Dispose() - } - } -} - -function GetProxyEnabledWebClient -{ - $wc = New-Object System.Net.WebClient - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $wc.Proxy = $proxy - return $wc -} - -Write-Host "Preparing to run build script..." - -if(!$PSScriptRoot){ - $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -} - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" -$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" -$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" -$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null -} - -# Make sure that packages.config exist. -if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) - } catch { - Throw "Could not download packages.config." - } -} - -# Try find NuGet.exe in path if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { - Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." - $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName - } -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Downloading NuGet.exe..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } catch { - Throw "Could not download NuGet.exe." - } -} - -# Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE - -# Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { - Push-Location - Set-Location $TOOLS_DIR - - # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) - if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed package.config hash..." - Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | - Remove-Item -Recurse - } - - Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet tools." - } - else - { - $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore addins from NuGet -if (Test-Path $ADDINS_PACKAGES_CONFIG) { - Push-Location - Set-Location $ADDINS_DIR - - Write-Verbose -Message "Restoring addins from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet addins." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore modules from NuGet -if (Test-Path $MODULES_PACKAGES_CONFIG) { - Push-Location - Set-Location $MODULES_DIR - - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet modules." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} - - - -# Build Cake arguments -$cakeArguments = @("$Script"); -if ($Target) { $cakeArguments += "-target=$Target" } -if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } -if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } -if ($ShowDescription) { $cakeArguments += "-showdescription" } -if ($DryRun) { $cakeArguments += "-dryrun" } -$cakeArguments += $ScriptArgs - -# Start Cake -Write-Host "Running build script..." -&$CAKE_EXE $cakeArguments -exit $LASTEXITCODE diff --git a/build.sh b/build.sh deleted file mode 100755 index b9e1252..0000000 --- a/build.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/tools -ADDINS_DIR=$TOOLS_DIR/Addins -MODULES_DIR=$TOOLS_DIR/Modules -NUGET_EXE=$TOOLS_DIR/nuget.exe -CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe -PACKAGES_CONFIG=$TOOLS_DIR/packages.config -PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum -ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config -MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config - -# Define md5sum or md5 depending on Linux/OSX -MD5_EXE= -if [[ "$(uname -s)" == "Darwin" ]]; then - MD5_EXE="md5 -r" -else - MD5_EXE="md5sum" -fi - -# Define default arguments. -SCRIPT="build.cake" -CAKE_ARGUMENTS=() - -# Parse arguments. -for i in "$@"; do - case $1 in - -s|--script) SCRIPT="$2"; shift ;; - --) shift; CAKE_ARGUMENTS+=("$@"); break ;; - *) CAKE_ARGUMENTS+=("$1") ;; - esac - shift -done - -# Make sure the tools folder exist. -if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" -fi - -# Make sure that packages.config exist. -if [ ! -f "$TOOLS_DIR/packages.config" ]; then - echo "Downloading packages.config..." - curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages - if [ $? -ne 0 ]; then - echo "An error occurred while downloading packages.config." - exit 1 - fi -fi - -# Download NuGet if it does not exist. -if [ ! -f "$NUGET_EXE" ]; then - echo "Downloading NuGet..." - curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - if [ $? -ne 0 ]; then - echo "An error occurred while downloading nuget.exe." - exit 1 - fi -fi - -# Restore tools from NuGet. -pushd "$TOOLS_DIR" >/dev/null -if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then - find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf -fi - -mono "$NUGET_EXE" install -ExcludeVersion -if [ $? -ne 0 ]; then - echo "Could not restore NuGet tools." - exit 1 -fi - -$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5" - -popd >/dev/null - -# Restore addins from NuGet. -if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then - pushd "$ADDINS_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet addins." - exit 1 - fi - - popd >/dev/null -fi - -# Restore modules from NuGet. -if [ -f "$MODULES_PACKAGES_CONFIG" ]; then - pushd "$MODULES_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet modules." - exit 1 - fi - - popd >/dev/null -fi - -# Make sure that Cake has been installed. -if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 -fi - -# Start Cake -exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}" diff --git a/build/parameters.cake b/build/parameters.cake deleted file mode 100644 index 6589f7e..0000000 --- a/build/parameters.cake +++ /dev/null @@ -1,63 +0,0 @@ -#load "./paths.cake" -#load "./version.cake" - -public class BuildParameters -{ - public string Configuration { get; private set; } - public bool IsLocalBuild { get; private set; } - public bool IsRunningOnUnix { get; private set; } - public bool IsRunningOnWindows { get; private set; } - public bool IsRunningOnAppVeyor { get; private set; } - public bool IsPullRequest { get; private set; } - public bool IsMainMassTransitRepo { get; private set; } - public bool IsMasterBranch { get; private set; } - public bool IsDevelopBranch { get; private set; } - public bool IsTagged { get; private set; } - public BuildPaths Paths { get; private set; } - public BuildVersion Version { get; private set; } - - public bool ShouldPublish - { - get - { - return !IsLocalBuild && IsRunningOnWindows && !IsPullRequest && IsMainMassTransitRepo && (IsMasterBranch - || IsDevelopBranch); - } - } - - public void Initialize(ICakeContext context) - { - Version = BuildVersion.Calculate(context, this); - } - - public static BuildParameters GetParameters(ICakeContext context) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - var target = context.Argument("target", "Default"); - var buildSystem = context.BuildSystem(); - - return new BuildParameters { - Configuration = context.Argument("configuration", "Release"), - IsLocalBuild = buildSystem.IsLocalBuild, - IsRunningOnUnix = context.IsRunningOnUnix(), - IsRunningOnWindows = context.IsRunningOnWindows(), - IsRunningOnAppVeyor = buildSystem.AppVeyor.IsRunningOnAppVeyor, - IsPullRequest = buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest, - IsMainMassTransitRepo = StringComparer.OrdinalIgnoreCase.Equals("phatboyg/newid", buildSystem.AppVeyor.Environment.Repository.Name), - IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals("master", buildSystem.AppVeyor.Environment.Repository.Branch), - IsDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", buildSystem.AppVeyor.Environment.Repository.Branch), - IsTagged = IsBuildTagged(buildSystem), - Paths = BuildPaths.GetPaths(context) - }; - } - - private static bool IsBuildTagged(BuildSystem buildSystem) - { - return buildSystem.AppVeyor.Environment.Repository.Tag.IsTag - && !string.IsNullOrWhiteSpace(buildSystem.AppVeyor.Environment.Repository.Tag.Name); - } -} diff --git a/build/paths.cake b/build/paths.cake deleted file mode 100644 index 82f2bce..0000000 --- a/build/paths.cake +++ /dev/null @@ -1,64 +0,0 @@ -public class BuildPaths -{ - public BuildDirectories Directories { get; private set; } - - public static BuildPaths GetPaths( - ICakeContext context - ) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - - var rootDir = context.MakeAbsolute(context.Directory("./")); - var solutionDir = rootDir.Combine("src"); - var artifactsDir = rootDir.Combine("artifacts"); - - // Directories - var buildDirectories = new BuildDirectories( - artifactsDir, - rootDir, - solutionDir); - - return new BuildPaths - { - Directories = buildDirectories - }; - } -} - -public class BuildFiles -{ - public FilePath VersionProperties { get; private set; } - - public BuildFiles( - FilePath versionProperties - ) - { - VersionProperties = versionProperties; - } -} - -public class BuildDirectories -{ - public DirectoryPath Artifacts { get; } - public DirectoryPath Root { get; } - public DirectoryPath Solution { get; } - public ICollection ToClean { get; } - - public BuildDirectories( - DirectoryPath artifactsDir, - DirectoryPath rootDir, - DirectoryPath solutionDir - ) - { - Artifacts = artifactsDir; - Root = rootDir; - Solution = solutionDir; - ToClean = new[] { - Artifacts - }; - } -} diff --git a/build/version.cake b/build/version.cake deleted file mode 100644 index 259865e..0000000 --- a/build/version.cake +++ /dev/null @@ -1,57 +0,0 @@ -public class BuildVersion -{ - public string Prefix { get; set; } - public string Suffix { get; set; } - public string Metadata { get; set; } - - public string Version => (Prefix + "-" + Suffix).Trim('-') + Metadata; - - public static BuildVersion Calculate(ICakeContext context, BuildParameters buildParameters) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - var buildSystem = context.BuildSystem(); - - var prefix = context.EnvironmentVariable("APPVEYOR_BUILD_VERSION") ?? "1.0.0"; - - // Appveyor needs a unique build version, so it's always MAJOR.MINOR.PATCH.{buildnumber}, but - // this doesn't follow SemVer 2.0, we put the build number as metadata - prefix = string.Join(".", prefix.Split('.').Take(3)); - - string suffix = "alpha.9999"; - string metadata = null; - - if(!buildParameters.IsLocalBuild) - { - var buildNumber = buildSystem.AppVeyor.Environment.Build.Number; - var commitHash = buildSystem.AppVeyor.Environment.Repository.Commit.Id; - commitHash = commitHash.Substring(0,Math.Min(commitHash.Length,7)); - - suffix = - buildParameters.IsMasterBranch ? null - : buildParameters.IsDevelopBranch ? "develop" - : "beta"; - - if(suffix != null) - { - suffix += $".{buildNumber}"; - metadata = $"+sha.{commitHash}"; - } - else - { - metadata = $"+build.{buildNumber}.sha.{commitHash}"; - } - } - - - return new BuildVersion - { - Prefix = prefix, - Suffix = suffix, - Metadata = metadata - }; - } -} diff --git a/src/NewId.Benchmarks/Benchmarker.cs b/tests/NewId.Benchmarks/Benchmarker.cs similarity index 100% rename from src/NewId.Benchmarks/Benchmarker.cs rename to tests/NewId.Benchmarks/Benchmarker.cs diff --git a/src/NewId.Benchmarks/NewId.Benchmarks.csproj b/tests/NewId.Benchmarks/NewId.Benchmarks.csproj similarity index 86% rename from src/NewId.Benchmarks/NewId.Benchmarks.csproj rename to tests/NewId.Benchmarks/NewId.Benchmarks.csproj index 58507ca..0a790ec 100644 --- a/src/NewId.Benchmarks/NewId.Benchmarks.csproj +++ b/tests/NewId.Benchmarks/NewId.Benchmarks.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/NewId.Benchmarks/Program.cs b/tests/NewId.Benchmarks/Program.cs similarity index 100% rename from src/NewId.Benchmarks/Program.cs rename to tests/NewId.Benchmarks/Program.cs diff --git a/src/NewId.Tests/Formatter_Specs.cs b/tests/NewId.Tests/Formatter_Specs.cs similarity index 96% rename from src/NewId.Tests/Formatter_Specs.cs rename to tests/NewId.Tests/Formatter_Specs.cs index 1498991..4352a34 100644 --- a/src/NewId.Tests/Formatter_Specs.cs +++ b/tests/NewId.Tests/Formatter_Specs.cs @@ -1,141 +1,141 @@ -namespace MassTransit.NewIdTests -{ - using System; - using System.Collections.Generic; - using System.IO; - using NewIdFormatters; - using NewIdParsers; - using NUnit.Framework; - - - [TestFixture] - public class Using_the_newid_formatters - { - [Test] - public void Should_compare_known_conversions() - { - var directory = AppDomain.CurrentDomain.BaseDirectory; - var newIdFileName = Path.Combine(directory, "guids.txt"); - var textsFileName = Path.Combine(directory, "texts.txt"); - - var newIds = new List(); - - using (var file = File.Open(newIdFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) - using (var reader = new StreamReader(file)) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - newIds.Add(new NewId(line.Trim())); - } - } - - var texts = new List(newIds.Count); - - using (var file = File.Open(textsFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) - using (var reader = new StreamReader(file)) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - texts.Add(line.Trim()); - } - } - - Assert.AreEqual(newIds.Count, texts.Count); - - var formatter = new Base32Formatter("0123456789ABCDEFGHIJKLMNOPQRSTUV"); - - for (var i = 0; i < newIds.Count; i++) - { - var text = newIds[i].ToString(formatter); - - Assert.AreEqual(texts[i], text); - } - - Console.WriteLine("Compared {0} equal conversions", texts.Count); - } - - [Test] - public void Should_convert_back_using_parser() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var formatter = new ZBase32Formatter(true); - - var ns = n.ToString(formatter); - - var parser = new ZBase32Parser(); - var newId = parser.Parse(ns); - - - Assert.AreEqual(n, newId); - } - - [Test] - public void Should_convert_back_using_standard_parser() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var formatter = new Base32Formatter(true); - - var ns = n.ToString(formatter); - - var parser = new Base32Parser(); - var newId = parser.Parse(ns); - - - Assert.AreEqual(n, newId); - } - - [Test] - public void Should_convert_using_custom_base32_formatting_characters() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var formatter = new Base32Formatter("0123456789ABCDEFGHIJKLMNOPQRSTUV"); - - var ns = n.ToString(formatter); - - Assert.AreEqual("UQP7OV4AN129HB4N79GGF8GJ10", ns); - } - - [Test] - public void Should_convert_using_standard_base32_formatting_characters() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var formatter = new Base32Formatter(true); - - var ns = n.ToString(formatter); - - Assert.AreEqual("62ZHY7EKXBCJRLEXHJQQPIQTBA", ns); - } - - [Test] - public void Should_convert_using_the_optimized_human_readable_formatter() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var formatter = new ZBase32Formatter(true); - - var ns = n.ToString(formatter); - - Assert.AreEqual("6438A9RKZBNJTMRZ8JOOXEOUBY", ns); - } - - [Test] - public void Should_translate_often_transposed_characters_to_proper_values() - { - var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); - - var ns = "6438A9RK2BNJTMRZ8J0OXE0UBY"; - - var parser = new ZBase32Parser(true); - var newId = parser.Parse(ns); - - - Assert.AreEqual(n, newId); - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using System.Collections.Generic; + using System.IO; + using NewIdFormatters; + using NewIdParsers; + using NUnit.Framework; + + + [TestFixture] + public class Using_the_newid_formatters + { + [Test] + public void Should_compare_known_conversions() + { + var directory = AppDomain.CurrentDomain.BaseDirectory; + var newIdFileName = Path.Combine(directory, "guids.txt"); + var textsFileName = Path.Combine(directory, "texts.txt"); + + var newIds = new List(); + + using (var file = File.Open(newIdFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) + using (var reader = new StreamReader(file)) + { + while (!reader.EndOfStream) + { + var line = reader.ReadLine(); + newIds.Add(new NewId(line.Trim())); + } + } + + var texts = new List(newIds.Count); + + using (var file = File.Open(textsFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) + using (var reader = new StreamReader(file)) + { + while (!reader.EndOfStream) + { + var line = reader.ReadLine(); + texts.Add(line.Trim()); + } + } + + Assert.AreEqual(newIds.Count, texts.Count); + + var formatter = new Base32Formatter("0123456789ABCDEFGHIJKLMNOPQRSTUV"); + + for (var i = 0; i < newIds.Count; i++) + { + var text = newIds[i].ToString(formatter); + + Assert.AreEqual(texts[i], text); + } + + Console.WriteLine("Compared {0} equal conversions", texts.Count); + } + + [Test] + public void Should_convert_back_using_parser() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var formatter = new ZBase32Formatter(true); + + var ns = n.ToString(formatter); + + var parser = new ZBase32Parser(); + var newId = parser.Parse(ns); + + + Assert.AreEqual(n, newId); + } + + [Test] + public void Should_convert_back_using_standard_parser() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var formatter = new Base32Formatter(true); + + var ns = n.ToString(formatter); + + var parser = new Base32Parser(); + var newId = parser.Parse(ns); + + + Assert.AreEqual(n, newId); + } + + [Test] + public void Should_convert_using_custom_base32_formatting_characters() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var formatter = new Base32Formatter("0123456789ABCDEFGHIJKLMNOPQRSTUV"); + + var ns = n.ToString(formatter); + + Assert.AreEqual("UQP7OV4AN129HB4N79GGF8GJ10", ns); + } + + [Test] + public void Should_convert_using_standard_base32_formatting_characters() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var formatter = new Base32Formatter(true); + + var ns = n.ToString(formatter); + + Assert.AreEqual("62ZHY7EKXBCJRLEXHJQQPIQTBA", ns); + } + + [Test] + public void Should_convert_using_the_optimized_human_readable_formatter() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var formatter = new ZBase32Formatter(true); + + var ns = n.ToString(formatter); + + Assert.AreEqual("6438A9RKZBNJTMRZ8JOOXEOUBY", ns); + } + + [Test] + public void Should_translate_often_transposed_characters_to_proper_values() + { + var n = new NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); + + var ns = "6438A9RK2BNJTMRZ8J0OXE0UBY"; + + var parser = new ZBase32Parser(true); + var newId = parser.Parse(ns); + + + Assert.AreEqual(n, newId); + } + } +} diff --git a/src/NewId.Tests/Generator_Specs.cs b/tests/NewId.Tests/Generator_Specs.cs similarity index 100% rename from src/NewId.Tests/Generator_Specs.cs rename to tests/NewId.Tests/Generator_Specs.cs diff --git a/src/NewId.Tests/GuidInterop_Specs.cs b/tests/NewId.Tests/GuidInterop_Specs.cs similarity index 96% rename from src/NewId.Tests/GuidInterop_Specs.cs rename to tests/NewId.Tests/GuidInterop_Specs.cs index f66f951..c8018e9 100644 --- a/src/NewId.Tests/GuidInterop_Specs.cs +++ b/tests/NewId.Tests/GuidInterop_Specs.cs @@ -1,194 +1,194 @@ -namespace MassTransit.NewIdTests -{ - using System; - using NUnit.Framework; - - - [TestFixture] - public class When_interoperating_with_the_guid_type - { - [Test] - public void Should_convert_from_a_guid_quickly() - { - var g = Guid.NewGuid(); - - var n = g.ToNewId(); - - var ns = n.ToString(); - var gs = g.ToString(); - - Assert.AreEqual(ns, gs); - } - - [Test] - public void Should_convert_to_guid_quickly() - { - var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 - - var g = n.ToGuid(); - - var ns = n.ToString(); - var gs = g.ToString(); - - Assert.AreEqual(ns, gs); - } - - [Test] - public void Should_display_sequentially_for_newid() - { - var id = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 - - Console.WriteLine(id.ToString("DS")); - } - - [Test] - public void Should_make_the_round_trip_successfully_via_bytes() - { - var g = Guid.NewGuid(); - - var n = new NewId(g.ToByteArray()); - - var gn = new Guid(n.ToByteArray()); - - Assert.AreEqual(g, gn); - } - - [Test] - public void Should_make_the_round_trip_successfully_via_guid() - { - var g = Guid.NewGuid(); - - var n = g.ToNewId(); - - var gn = n.ToGuid(); - - Assert.AreEqual(g, gn); - } - - [Test] - public void Should_match_string_output_b() - { - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - - var g = new Guid(bytes); - var n = new NewId(bytes); - - var gs = g.ToString("B"); - var ns = n.ToString("B"); - - Assert.AreEqual(gs, ns); - } - - [Test] - public void Should_match_string_output_d() - { - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - - var g = new Guid(bytes); - var n = new NewId(bytes); - - var gs = g.ToString("d"); - var ns = n.ToString("d"); - - Assert.AreEqual(gs, ns); - } - - [Test] - public void Should_match_string_output_n() - { - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - - var g = new Guid(bytes); - var n = new NewId(bytes); - - var gs = g.ToString("N"); - var ns = n.ToString("N"); - - Assert.AreEqual(gs, ns); - } - - [Test] - public void Should_match_string_output_p() - { - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - - var g = new Guid(bytes); - var n = new NewId(bytes); - - var gs = g.ToString("P"); - var ns = n.ToString("P"); - - Assert.AreEqual(gs, ns); - } - - [Test] - public void Should_properly_handle_string_passthrough() - { - var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 - - var ns = n.ToString("D"); - - var g = new Guid(ns); - - var nn = new NewId(g.ToString("D")); - - Assert.AreEqual(n, nn); - } - - [Test] - public void Should_support_the_same_constructor() - { - // ensure all bytes have a different value - var guid = new Guid(0x01020304, 0x0506, 0x0708, 9, 10, 11, 12, 13, 14, 15, 16); - var newid = new NewId(0x01020304, 0x0506, 0x0708, 9, 10, 11, 12, 13, 14, 15, 16); - - Assert.AreEqual(guid.ToString(), newid.ToString()); - } - - [Test] - public void Should_work_from_newid_to_guid_to_newid() - { - var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 - - var g = new Guid(n.ToByteArray()); - - var ng = new NewId(g.ToByteArray()); - - Console.WriteLine(g.ToString("D")); - - Assert.AreEqual(n, ng); - } - - - [Test] - public void Should_parse_newid_guid_as_newid() - { - NewId n = NewId.Next(); - - var g = n.ToGuid(); - - var ng = NewId.FromGuid(g); - - Assert.AreEqual(n, ng); - - // Also checks to see if this would throw - Assert.IsTrue(ng.Timestamp != default); - } - - [Test] - public void Should_parse_sequential_guid_as_newid() - { - NewId n = NewId.Next(); - - var nn = n.ToGuid(); - var g = n.ToSequentialGuid(); - - var ng = NewId.FromSequentialGuid(g); - - Assert.AreEqual(n, ng); - - // Also checks to see if this would throw - Assert.IsTrue(ng.Timestamp != default); - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using NUnit.Framework; + + + [TestFixture] + public class When_interoperating_with_the_guid_type + { + [Test] + public void Should_convert_from_a_guid_quickly() + { + var g = Guid.NewGuid(); + + var n = g.ToNewId(); + + var ns = n.ToString(); + var gs = g.ToString(); + + Assert.AreEqual(ns, gs); + } + + [Test] + public void Should_convert_to_guid_quickly() + { + var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 + + var g = n.ToGuid(); + + var ns = n.ToString(); + var gs = g.ToString(); + + Assert.AreEqual(ns, gs); + } + + [Test] + public void Should_display_sequentially_for_newid() + { + var id = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 + + Console.WriteLine(id.ToString("DS")); + } + + [Test] + public void Should_make_the_round_trip_successfully_via_bytes() + { + var g = Guid.NewGuid(); + + var n = new NewId(g.ToByteArray()); + + var gn = new Guid(n.ToByteArray()); + + Assert.AreEqual(g, gn); + } + + [Test] + public void Should_make_the_round_trip_successfully_via_guid() + { + var g = Guid.NewGuid(); + + var n = g.ToNewId(); + + var gn = n.ToGuid(); + + Assert.AreEqual(g, gn); + } + + [Test] + public void Should_match_string_output_b() + { + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + + var g = new Guid(bytes); + var n = new NewId(bytes); + + var gs = g.ToString("B"); + var ns = n.ToString("B"); + + Assert.AreEqual(gs, ns); + } + + [Test] + public void Should_match_string_output_d() + { + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + + var g = new Guid(bytes); + var n = new NewId(bytes); + + var gs = g.ToString("d"); + var ns = n.ToString("d"); + + Assert.AreEqual(gs, ns); + } + + [Test] + public void Should_match_string_output_n() + { + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + + var g = new Guid(bytes); + var n = new NewId(bytes); + + var gs = g.ToString("N"); + var ns = n.ToString("N"); + + Assert.AreEqual(gs, ns); + } + + [Test] + public void Should_match_string_output_p() + { + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + + var g = new Guid(bytes); + var n = new NewId(bytes); + + var gs = g.ToString("P"); + var ns = n.ToString("P"); + + Assert.AreEqual(gs, ns); + } + + [Test] + public void Should_properly_handle_string_passthrough() + { + var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 + + var ns = n.ToString("D"); + + var g = new Guid(ns); + + var nn = new NewId(g.ToString("D")); + + Assert.AreEqual(n, nn); + } + + [Test] + public void Should_support_the_same_constructor() + { + // ensure all bytes have a different value + var guid = new Guid(0x01020304, 0x0506, 0x0708, 9, 10, 11, 12, 13, 14, 15, 16); + var newid = new NewId(0x01020304, 0x0506, 0x0708, 9, 10, 11, 12, 13, 14, 15, 16); + + Assert.AreEqual(guid.ToString(), newid.ToString()); + } + + [Test] + public void Should_work_from_newid_to_guid_to_newid() + { + var n = NewId.Next(2)[1]; // ensure sequence number is not 0x0000 + + var g = new Guid(n.ToByteArray()); + + var ng = new NewId(g.ToByteArray()); + + Console.WriteLine(g.ToString("D")); + + Assert.AreEqual(n, ng); + } + + + [Test] + public void Should_parse_newid_guid_as_newid() + { + NewId n = NewId.Next(); + + var g = n.ToGuid(); + + var ng = NewId.FromGuid(g); + + Assert.AreEqual(n, ng); + + // Also checks to see if this would throw + Assert.IsTrue(ng.Timestamp != default); + } + + [Test] + public void Should_parse_sequential_guid_as_newid() + { + NewId n = NewId.Next(); + + var nn = n.ToGuid(); + var g = n.ToSequentialGuid(); + + var ng = NewId.FromSequentialGuid(g); + + Assert.AreEqual(n, ng); + + // Also checks to see if this would throw + Assert.IsTrue(ng.Timestamp != default); + } + } +} diff --git a/src/NewId.Tests/LongTerm_Specs.cs b/tests/NewId.Tests/LongTerm_Specs.cs similarity index 96% rename from src/NewId.Tests/LongTerm_Specs.cs rename to tests/NewId.Tests/LongTerm_Specs.cs index ead0322..e5d05d3 100644 --- a/src/NewId.Tests/LongTerm_Specs.cs +++ b/tests/NewId.Tests/LongTerm_Specs.cs @@ -1,54 +1,54 @@ -namespace MassTransit.NewIdTests -{ - using System; - using System.Data.SqlTypes; - using NewIdProviders; - using NUnit.Framework; - - - [TestFixture] - public class Generating_ids_over_time - { - [Test] - public void Should_keep_them_ordered_for_sql_server() - { - var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); - generator.Next(); - - var limit = 1024; - - var ids = new NewId[limit]; - for (var i = 0; i < limit; i++) - ids[i] = generator.Next(); - - for (var i = 0; i < limit - 1; i++) - { - Assert.AreNotEqual(ids[i], ids[i + 1]); - - SqlGuid left = ids[i].ToGuid(); - SqlGuid right = ids[i + 1].ToGuid(); - Assert.Less(left, right); - if (i % 128 == 0) - Console.WriteLine("Normal: {0} Sql: {1}", left, ids[i].ToSequentialGuid()); - } - } - - - class TimeLapseTickProvider : - ITickProvider - { - TimeSpan _interval = TimeSpan.FromSeconds(2); - DateTime _previous = DateTime.UtcNow; - - public long Ticks - { - get - { - _previous = _previous + _interval; - _interval = TimeSpan.FromSeconds((long)_interval.TotalSeconds + 30); - return _previous.Ticks; - } - } - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using System.Data.SqlTypes; + using NewIdProviders; + using NUnit.Framework; + + + [TestFixture] + public class Generating_ids_over_time + { + [Test] + public void Should_keep_them_ordered_for_sql_server() + { + var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); + generator.Next(); + + var limit = 1024; + + var ids = new NewId[limit]; + for (var i = 0; i < limit; i++) + ids[i] = generator.Next(); + + for (var i = 0; i < limit - 1; i++) + { + Assert.AreNotEqual(ids[i], ids[i + 1]); + + SqlGuid left = ids[i].ToGuid(); + SqlGuid right = ids[i + 1].ToGuid(); + Assert.Less(left, right); + if (i % 128 == 0) + Console.WriteLine("Normal: {0} Sql: {1}", left, ids[i].ToSequentialGuid()); + } + } + + + class TimeLapseTickProvider : + ITickProvider + { + TimeSpan _interval = TimeSpan.FromSeconds(2); + DateTime _previous = DateTime.UtcNow; + + public long Ticks + { + get + { + _previous = _previous + _interval; + _interval = TimeSpan.FromSeconds((long)_interval.TotalSeconds + 30); + return _previous.Ticks; + } + } + } + } +} diff --git a/src/NewId.Tests/NetworkAddress_Specs.cs b/tests/NewId.Tests/NetworkAddress_Specs.cs similarity index 97% rename from src/NewId.Tests/NetworkAddress_Specs.cs rename to tests/NewId.Tests/NetworkAddress_Specs.cs index e5de819..f10f056 100644 --- a/src/NewId.Tests/NetworkAddress_Specs.cs +++ b/tests/NewId.Tests/NetworkAddress_Specs.cs @@ -1,63 +1,63 @@ -namespace MassTransit.NewIdTests -{ - using System; - using System.Linq; - using System.Net.NetworkInformation; - using NewIdProviders; - using NUnit.Framework; - - - [TestFixture] - public class When_getting_a_network_address_for_the_id_generator - { - [Test] - public void Should_pull_all_adapters() - { - NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces() - .ToArray(); - - foreach (var networkInterface in interfaces) - { - Console.WriteLine("Network Interface: {0} - {1}", networkInterface.Description, - networkInterface.NetworkInterfaceType); - } - } - - [Test] - public void Should_pull_the_network_adapter_mac_address() - { - var networkIdProvider = new NetworkAddressWorkerIdProvider(); - - var networkId = networkIdProvider.GetWorkerId(0); - - Assert.IsNotNull(networkId); - Assert.AreEqual(6, networkId.Length); - } - - [Test] - public void Should_pull_using_host_name() - { - var networkIdProvider = new HostNameHashWorkerIdProvider(); - - var networkId = networkIdProvider.GetWorkerId(0); - - Assert.IsNotNull(networkId); - Assert.AreEqual(6, networkId.Length); - } - - [Test] - public void Should_pull_using_net() - { - NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces() - .Where(x => x.NetworkInterfaceType == NetworkInterfaceType.Ethernet - || x.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet - || x.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 - || x.NetworkInterfaceType == NetworkInterfaceType.FastEthernetFx - || x.NetworkInterfaceType == NetworkInterfaceType.FastEthernetT - ).ToArray(); - - foreach (var networkInterface in interfaces) - Console.WriteLine("Network Interface: {0}", networkInterface.Description); - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using System.Linq; + using System.Net.NetworkInformation; + using NewIdProviders; + using NUnit.Framework; + + + [TestFixture] + public class When_getting_a_network_address_for_the_id_generator + { + [Test] + public void Should_pull_all_adapters() + { + NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces() + .ToArray(); + + foreach (var networkInterface in interfaces) + { + Console.WriteLine("Network Interface: {0} - {1}", networkInterface.Description, + networkInterface.NetworkInterfaceType); + } + } + + [Test] + public void Should_pull_the_network_adapter_mac_address() + { + var networkIdProvider = new NetworkAddressWorkerIdProvider(); + + var networkId = networkIdProvider.GetWorkerId(0); + + Assert.IsNotNull(networkId); + Assert.AreEqual(6, networkId.Length); + } + + [Test] + public void Should_pull_using_host_name() + { + var networkIdProvider = new HostNameHashWorkerIdProvider(); + + var networkId = networkIdProvider.GetWorkerId(0); + + Assert.IsNotNull(networkId); + Assert.AreEqual(6, networkId.Length); + } + + [Test] + public void Should_pull_using_net() + { + NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces() + .Where(x => x.NetworkInterfaceType == NetworkInterfaceType.Ethernet + || x.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet + || x.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 + || x.NetworkInterfaceType == NetworkInterfaceType.FastEthernetFx + || x.NetworkInterfaceType == NetworkInterfaceType.FastEthernetT + ).ToArray(); + + foreach (var networkInterface in interfaces) + Console.WriteLine("Network Interface: {0}", networkInterface.Description); + } + } +} diff --git a/src/NewId.Tests/NewId.Tests.csproj b/tests/NewId.Tests/NewId.Tests.csproj similarity index 84% rename from src/NewId.Tests/NewId.Tests.csproj rename to tests/NewId.Tests/NewId.Tests.csproj index 72373c1..700df95 100644 --- a/src/NewId.Tests/NewId.Tests.csproj +++ b/tests/NewId.Tests/NewId.Tests.csproj @@ -1,29 +1,28 @@ - - - - netcoreapp3.1;net6.0 - MassTransit.NewIdTests - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - - - {772d113c-cfb5-48f7-9ee5-41eda3a5740c} - NewId - - - + + + + netcoreapp3.1;net6.0 + MassTransit.NewIdTests + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + + {772d113c-cfb5-48f7-9ee5-41eda3a5740c} + NewId + + + diff --git a/src/NewId.Tests/NewId_Specs.cs b/tests/NewId.Tests/NewId_Specs.cs similarity index 96% rename from src/NewId.Tests/NewId_Specs.cs rename to tests/NewId.Tests/NewId_Specs.cs index 7842e78..d737b5f 100644 --- a/src/NewId.Tests/NewId_Specs.cs +++ b/tests/NewId.Tests/NewId_Specs.cs @@ -1,197 +1,197 @@ -namespace MassTransit.NewIdTests -{ - using System; - using System.Diagnostics; - using System.Linq; - using System.Threading.Tasks; - using NewIdProviders; - using NUnit.Framework; - - - [TestFixture] - public class Using_the_newid_generator - { - [Test] - public void Should_be_able_to_determine_equal_ids() - { - var id1 = new NewId("fc070000-9565-3668-e000-08d5893343c6"); - var id2 = new NewId("fc070000-9565-3668-e000-08d5893343c6"); - - Assert.IsTrue(id1 == id2); - } - - [Test] - public void Should_be_able_to_determine_greater_id() - { - var lowerId = new NewId("fc070000-9565-3668-e000-08d5893343c6"); - var greaterId = new NewId("fc070000-9565-3668-9180-08d589338b38"); - - Assert.IsTrue(lowerId < greaterId); - } - - [Test] - public void Should_be_able_to_determine_lower_id() - { - var lowerId = new NewId("fc070000-9565-3668-e000-08d5893343c6"); - var greaterId = new NewId("fc070000-9565-3668-9180-08d589338b38"); - - Assert.IsFalse(lowerId > greaterId); - } - - [Test] - [Explicit] - public void Should_be_able_to_extract_timestamp() - { - var now = DateTime.UtcNow; - var id = NewId.Next(); - - var timestamp = id.Timestamp; - - Console.WriteLine("Now: {0}, Timestamp: {1}", now, timestamp); - - var difference = timestamp - now; - if (difference < TimeSpan.Zero) - difference = difference.Negate(); - - Assert.LessOrEqual(difference, TimeSpan.FromMinutes(1)); - } - - [Test] - [Explicit] - public void Should_be_able_to_extract_timestamp_with_process_id() - { - var now = DateTime.UtcNow; - NewId.SetProcessIdProvider(new CurrentProcessIdProvider()); - var id = NewId.Next(); - - var timestamp = id.Timestamp; - - Console.WriteLine("Now: {0}, Timestamp: {1}", now, timestamp); - - var difference = timestamp - now; - if (difference < TimeSpan.Zero) - difference = difference.Negate(); - - Assert.LessOrEqual(difference, TimeSpan.FromMinutes(1)); - } - - [Test] - [Explicit] - public void Should_be_completely_thread_safe_to_avoid_duplicates() - { - NewId.Next(); - - var timer = Stopwatch.StartNew(); - - var threadCount = 20; - - var loopCount = 1024 * 1024; - - var limit = loopCount * threadCount; - - var ids = new NewId[limit]; - - ParallelEnumerable - .Range(0, limit) - .WithDegreeOfParallelism(8) - .WithExecutionMode(ParallelExecutionMode.ForceParallelism) - .ForAll(x => - { - ids[x] = NewId.Next(); - }); - - timer.Stop(); - - Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, - limit / timer.ElapsedMilliseconds); - - Console.WriteLine("Distinct: {0}", ids.Distinct().Count()); - - IGrouping[] duplicates = ids.GroupBy(x => x).Where(x => x.Count() > 1).ToArray(); - - Console.WriteLine("Duplicates: {0}", duplicates.Count()); - - foreach (IGrouping newId in duplicates) - Console.WriteLine("{0} {1}", newId.Key, newId.Count()); - } - - [Test] - [Explicit] - public void Should_be_fast_and_friendly() - { - NewId.Next(); - - - var limit = 1000000; - - var ids = new NewId[limit]; - - Parallel.For(0, limit, x => ids[x] = NewId.Next()); - - var timer = Stopwatch.StartNew(); - - Parallel.For(0, limit, x => ids[x] = NewId.Next()); - - timer.Stop(); - - Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, - limit / timer.ElapsedMilliseconds); - - Console.WriteLine("Distinct: {0}", ids.Distinct().Count()); - - IGrouping[] duplicates = ids.GroupBy(x => x).Where(x => x.Count() > 1).ToArray(); - - Console.WriteLine("Duplicates: {0}", duplicates.Count()); - - foreach (IGrouping newId in duplicates) - Console.WriteLine("{0} {1}", newId.Key, newId.Count()); - } - - [Test] - public void Should_generate_sequential_ids_quickly() - { - NewId.SetTickProvider(new StopwatchTickProvider()); - NewId.Next(); - - var limit = 10; - - var ids = new NewId[limit]; - for (var i = 0; i < limit; i++) - ids[i] = NewId.Next(); - - for (var i = 0; i < limit - 1; i++) - { - Assert.AreNotEqual(ids[i], ids[i + 1]); - Console.WriteLine(ids[i]); - } - } - - [Test] - [Explicit] - public void Should_generate_unique_identifiers_with_each_invocation() - { - NewId.Next(); - - var timer = Stopwatch.StartNew(); - - var limit = 1024 * 1024; - - var ids = new NewId[limit]; - for (var i = 0; i < limit; i++) - ids[i] = NewId.Next(); - - timer.Stop(); - - for (var i = 0; i < limit - 1; i++) - { - Assert.AreNotEqual(ids[i], ids[i + 1]); - var end = ids[i].ToString().Substring(32, 4); - if (end == "0000") - Console.WriteLine("{0}", ids[i].ToString()); - } - - Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, - limit / timer.ElapsedMilliseconds); - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using System.Diagnostics; + using System.Linq; + using System.Threading.Tasks; + using NewIdProviders; + using NUnit.Framework; + + + [TestFixture] + public class Using_the_newid_generator + { + [Test] + public void Should_be_able_to_determine_equal_ids() + { + var id1 = new NewId("fc070000-9565-3668-e000-08d5893343c6"); + var id2 = new NewId("fc070000-9565-3668-e000-08d5893343c6"); + + Assert.IsTrue(id1 == id2); + } + + [Test] + public void Should_be_able_to_determine_greater_id() + { + var lowerId = new NewId("fc070000-9565-3668-e000-08d5893343c6"); + var greaterId = new NewId("fc070000-9565-3668-9180-08d589338b38"); + + Assert.IsTrue(lowerId < greaterId); + } + + [Test] + public void Should_be_able_to_determine_lower_id() + { + var lowerId = new NewId("fc070000-9565-3668-e000-08d5893343c6"); + var greaterId = new NewId("fc070000-9565-3668-9180-08d589338b38"); + + Assert.IsFalse(lowerId > greaterId); + } + + [Test] + [Explicit] + public void Should_be_able_to_extract_timestamp() + { + var now = DateTime.UtcNow; + var id = NewId.Next(); + + var timestamp = id.Timestamp; + + Console.WriteLine("Now: {0}, Timestamp: {1}", now, timestamp); + + var difference = timestamp - now; + if (difference < TimeSpan.Zero) + difference = difference.Negate(); + + Assert.LessOrEqual(difference, TimeSpan.FromMinutes(1)); + } + + [Test] + [Explicit] + public void Should_be_able_to_extract_timestamp_with_process_id() + { + var now = DateTime.UtcNow; + NewId.SetProcessIdProvider(new CurrentProcessIdProvider()); + var id = NewId.Next(); + + var timestamp = id.Timestamp; + + Console.WriteLine("Now: {0}, Timestamp: {1}", now, timestamp); + + var difference = timestamp - now; + if (difference < TimeSpan.Zero) + difference = difference.Negate(); + + Assert.LessOrEqual(difference, TimeSpan.FromMinutes(1)); + } + + [Test] + [Explicit] + public void Should_be_completely_thread_safe_to_avoid_duplicates() + { + NewId.Next(); + + var timer = Stopwatch.StartNew(); + + var threadCount = 20; + + var loopCount = 1024 * 1024; + + var limit = loopCount * threadCount; + + var ids = new NewId[limit]; + + ParallelEnumerable + .Range(0, limit) + .WithDegreeOfParallelism(8) + .WithExecutionMode(ParallelExecutionMode.ForceParallelism) + .ForAll(x => + { + ids[x] = NewId.Next(); + }); + + timer.Stop(); + + Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, + limit / timer.ElapsedMilliseconds); + + Console.WriteLine("Distinct: {0}", ids.Distinct().Count()); + + IGrouping[] duplicates = ids.GroupBy(x => x).Where(x => x.Count() > 1).ToArray(); + + Console.WriteLine("Duplicates: {0}", duplicates.Count()); + + foreach (IGrouping newId in duplicates) + Console.WriteLine("{0} {1}", newId.Key, newId.Count()); + } + + [Test] + [Explicit] + public void Should_be_fast_and_friendly() + { + NewId.Next(); + + + var limit = 1000000; + + var ids = new NewId[limit]; + + Parallel.For(0, limit, x => ids[x] = NewId.Next()); + + var timer = Stopwatch.StartNew(); + + Parallel.For(0, limit, x => ids[x] = NewId.Next()); + + timer.Stop(); + + Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, + limit / timer.ElapsedMilliseconds); + + Console.WriteLine("Distinct: {0}", ids.Distinct().Count()); + + IGrouping[] duplicates = ids.GroupBy(x => x).Where(x => x.Count() > 1).ToArray(); + + Console.WriteLine("Duplicates: {0}", duplicates.Count()); + + foreach (IGrouping newId in duplicates) + Console.WriteLine("{0} {1}", newId.Key, newId.Count()); + } + + [Test] + public void Should_generate_sequential_ids_quickly() + { + NewId.SetTickProvider(new StopwatchTickProvider()); + NewId.Next(); + + var limit = 10; + + var ids = new NewId[limit]; + for (var i = 0; i < limit; i++) + ids[i] = NewId.Next(); + + for (var i = 0; i < limit - 1; i++) + { + Assert.AreNotEqual(ids[i], ids[i + 1]); + Console.WriteLine(ids[i]); + } + } + + [Test] + [Explicit] + public void Should_generate_unique_identifiers_with_each_invocation() + { + NewId.Next(); + + var timer = Stopwatch.StartNew(); + + var limit = 1024 * 1024; + + var ids = new NewId[limit]; + for (var i = 0; i < limit; i++) + ids[i] = NewId.Next(); + + timer.Stop(); + + for (var i = 0; i < limit - 1; i++) + { + Assert.AreNotEqual(ids[i], ids[i + 1]); + var end = ids[i].ToString().Substring(32, 4); + if (end == "0000") + Console.WriteLine("{0}", ids[i].ToString()); + } + + Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, + limit / timer.ElapsedMilliseconds); + } + } +} diff --git a/src/NewId.Tests/Order_Specs.cs b/tests/NewId.Tests/Order_Specs.cs similarity index 100% rename from src/NewId.Tests/Order_Specs.cs rename to tests/NewId.Tests/Order_Specs.cs diff --git a/src/NewId.Tests/Usage_Specs.cs b/tests/NewId.Tests/Usage_Specs.cs similarity index 96% rename from src/NewId.Tests/Usage_Specs.cs rename to tests/NewId.Tests/Usage_Specs.cs index 71253de..c46786c 100644 --- a/src/NewId.Tests/Usage_Specs.cs +++ b/tests/NewId.Tests/Usage_Specs.cs @@ -1,55 +1,55 @@ -namespace MassTransit.NewIdTests -{ - using System; - using NUnit.Framework; - - - [TestFixture] - public class Using_a_new_id - { - [Test] - public void Should_format_just_like_a_default_guid_formatter() - { - var newId = new NewId(); - - Assert.AreEqual("00000000-0000-0000-0000-000000000000", newId.ToString()); - } - - [Test] - public void Should_format_just_like_a_fancy_guid_formatter() - { - var newId = new NewId(); - - Assert.AreEqual("{00000000-0000-0000-0000-000000000000}", newId.ToString("B")); - } - - [Test] - public void Should_format_just_like_a_narrow_guid_formatter() - { - var newId = new NewId(); - - Assert.AreEqual("00000000000000000000000000000000", newId.ToString("N")); - } - - [Test] - public void Should_format_just_like_a_parenthesis_guid_formatter() - { - var newId = new NewId(); - - Assert.AreEqual("(00000000-0000-0000-0000-000000000000)", newId.ToString("P")); - } - - [Test] - public void Should_work_from_guid_to_newid_to_guid() - { - var g = Guid.NewGuid(); - - var n = new NewId(g.ToByteArray()); - - var gs = g.ToString("d"); - var ns = n.ToString("d"); - - Assert.AreEqual(gs, ns); - } - } -} +namespace MassTransit.NewIdTests +{ + using System; + using NUnit.Framework; + + + [TestFixture] + public class Using_a_new_id + { + [Test] + public void Should_format_just_like_a_default_guid_formatter() + { + var newId = new NewId(); + + Assert.AreEqual("00000000-0000-0000-0000-000000000000", newId.ToString()); + } + + [Test] + public void Should_format_just_like_a_fancy_guid_formatter() + { + var newId = new NewId(); + + Assert.AreEqual("{00000000-0000-0000-0000-000000000000}", newId.ToString("B")); + } + + [Test] + public void Should_format_just_like_a_narrow_guid_formatter() + { + var newId = new NewId(); + + Assert.AreEqual("00000000000000000000000000000000", newId.ToString("N")); + } + + [Test] + public void Should_format_just_like_a_parenthesis_guid_formatter() + { + var newId = new NewId(); + + Assert.AreEqual("(00000000-0000-0000-0000-000000000000)", newId.ToString("P")); + } + + [Test] + public void Should_work_from_guid_to_newid_to_guid() + { + var g = Guid.NewGuid(); + + var n = new NewId(g.ToByteArray()); + + var gs = g.ToString("d"); + var ns = n.ToString("d"); + + Assert.AreEqual(gs, ns); + } + } +} diff --git a/src/NewId.Tests/guids.txt b/tests/NewId.Tests/guids.txt similarity index 100% rename from src/NewId.Tests/guids.txt rename to tests/NewId.Tests/guids.txt diff --git a/src/NewId.Tests/texts.txt b/tests/NewId.Tests/texts.txt similarity index 100% rename from src/NewId.Tests/texts.txt rename to tests/NewId.Tests/texts.txt diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index 945c3e8..0000000 --- a/tools/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - -