Skip to content

Commit

Permalink
Add conversion to Guid
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbukin committed May 27, 2020
1 parent bfb9ce3 commit 0251f05
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 14,795 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dodo.Primitives

[![Latest release](https://img.shields.io/badge/nuget-1.0.2-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/1.0.2)
[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/1.0.2&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/1.0.2)
[![Latest release](https://img.shields.io/badge/nuget-1.1.0-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/1.1.0)
[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/1.1.0&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/1.1.0)

Library provides .NET primitive types:

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.2</VersionPrefix>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>Dodo Pizza</Authors>
<Company>Dodo Pizza</Company>
Expand Down
12 changes: 6 additions & 6 deletions src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.1"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageReference Include="nunit" Version="3.12.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1"/>
<PackageReference Include="coverlet.msbuild" Version="2.8.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dodo.Primitives\Dodo.Primitives.csproj"/>
<ProjectReference Include="..\Dodo.Primitives\Dodo.Primitives.csproj" />
</ItemGroup>

</Project>
87 changes: 87 additions & 0 deletions src/Dodo.Primitives.Tests/Uuids/UuidToGuidTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using Dodo.Primitives.Tests.Uuids.Data;
using NUnit.Framework;

namespace Dodo.Primitives.Tests.Uuids
{
public class UuidToGuidTests
{
[Test]
public void ToGuidByteLayout()
{
Assert.Multiple(() =>
{
foreach (var nString in UuidTestData.CorrectNStrings)
{
var uuid = new Uuid(nString.Bytes);
Guid guid = uuid.ToGuidByteLayout();

var expectedBytes = uuid.ToByteArray();
var actualBytes = guid.ToByteArray();
string? expectedGuidString = Primitives.Hex.GetString(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.AreEqual(expectedBytes, actualBytes);
Assert.True(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
}
});
}

[Test]
public void ToGuidStringLayout()
{
Assert.Multiple(() =>
{
foreach (var nString in UuidTestData.CorrectNStrings)
{
var uuid = new Uuid(nString.Bytes);
Guid guid = uuid.ToGuidStringLayout();

var expectedBytes = 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 actualBytes = guid.ToByteArray();
var expectedGuidString = uuid.ToString("N");
var actualGuidString = guid.ToString("N");

Assert.AreEqual(expectedBytes, actualBytes);
Assert.True(string.Equals(expectedGuidString, actualGuidString, StringComparison.Ordinal));
}
});
}
}
}
Loading

0 comments on commit 0251f05

Please sign in to comment.