75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System.Security.Cryptography;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace UnitTests.Common.Extensions
|
|
{
|
|
[TestClass]
|
|
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
|
public class CryptographyHelperExtensionsTests
|
|
{
|
|
[TestMethod]
|
|
public void ShouldReturnMd5Hash()
|
|
{
|
|
// arrange
|
|
string str = "Hello World!";
|
|
byte[] bytes = new byte[] { 0xaf, 0xfe };
|
|
|
|
// act
|
|
string strHash = str.Md5();
|
|
string byteHash = bytes.Md5();
|
|
|
|
// assert
|
|
Assert.AreEqual("ed076287532e86365e841e92bfc50d8c", strHash);
|
|
Assert.AreEqual("63c983de427ce9e2430ba8554d2a822f", byteHash);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldReturnSha1Hash()
|
|
{
|
|
// arrange
|
|
string str = "Hello World!";
|
|
byte[] bytes = new byte[] { 0xaf, 0xfe };
|
|
|
|
// act
|
|
string strHash = str.Sha1();
|
|
string byteHash = bytes.Sha1();
|
|
|
|
// assert
|
|
Assert.AreEqual("2ef7bde608ce5404e97d5f042f95f89f1c232871", strHash);
|
|
Assert.AreEqual("ec2c39d500316044fa49f6c8f471ddec8b4fb9d1", byteHash);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldReturnSha256Hash()
|
|
{
|
|
// arrange
|
|
string str = "Hello World!";
|
|
byte[] bytes = new byte[] { 0xaf, 0xfe };
|
|
|
|
// act
|
|
string strHash = str.Sha256();
|
|
string byteHash = bytes.Sha256();
|
|
|
|
// assert
|
|
Assert.AreEqual("7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069", strHash);
|
|
Assert.AreEqual("4e0da689dc7a51957be426d6cfb1bd860169cb25dd1ac946a2f141228217804a", byteHash);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldReturnSha512Hash()
|
|
{
|
|
// arrange
|
|
string str = "Hello World!";
|
|
byte[] bytes = new byte[] { 0xaf, 0xfe };
|
|
|
|
// act
|
|
string strHash = str.Sha512();
|
|
string byteHash = bytes.Sha512();
|
|
|
|
// assert
|
|
Assert.AreEqual("861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8", strHash);
|
|
Assert.AreEqual("591098c5d470a09f0ff48a4fdb7769ab89f803eae9e23b6f9f69dd228cca46c074bbc11a5fceaa8a5f48d14d2bf19a83a629266c2c5b7d9ef34623b64cb2f8e7", byteHash);
|
|
}
|
|
}
|
|
}
|