Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phnx47 committed Dec 14, 2019
1 parent cbbe821 commit 59650d6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions tests/ArrayFingerprintBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Security.Cryptography;
using Xunit;

namespace FingerprintBuilder.Tests
{
public class ArrayFingerprintBuilderTests
{
[Fact]
public void UserInfo_Sha1()
{
var fingerprint = FingerprintBuilder<UserInfo>
.Create(SHA1.Create().ComputeHash)
.For(p => p.Name)
.For(p => p.Emails)
.Build();

var user = new UserInfo { Name = "John", Emails = new[] { "test@test.com", "test1@test.com" } };

var hash = fingerprint(user).ToLowerHexString();

Assert.Equal("365993bbd89e2e25039848e51904679cc9e13d17", hash);
}

[Fact]
public void UserInfo_EmailsString_Sha1()
{
var fingerprint = FingerprintBuilder<UserInfo>
.Create(SHA1.Create().ComputeHash)
.For(p => p.Name)
.For(p => p.Emails, emails=> string.Join('|', emails))
.Build();

var user = new UserInfo { Name = "John", Emails = new[] { "test@test.com", "test1@test.com" } };

var hash = fingerprint(user).ToLowerHexString();

Assert.Equal("9f825a64a3eb7a7f0b4887ce09ad2a76d085a8b0", hash);
}

private class UserInfo
{
public string Name { get; set; }

public string[] Emails { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion tests/FingerprintBuilder.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace FingerprintBuilder.Tests
{
public class FingerprintBuilderTests
public class SimpleFingerprintBuilderTests
{
[Fact]
public void UserInfo_Sha1()
Expand Down

0 comments on commit 59650d6

Please sign in to comment.