Unit test SHA256 wrapper queries
- by Sam Leach
I am just beginning to write unit tests. So please bear with me. I have the following SHA256 wrapper.
public static string SHA256(string plainText)
{
StringBuilder sb = new StringBuilder();
SHA256CryptoServiceProvider provider = new SHA256CryptoServiceProvider();
var hashedBytes = provider.ComputeHash(Encoding.UTF8.GetBytes(plainText));
for (int i = 0; i < hashedBytes.Length; i++)
{
sb.Append(hashedBytes[i].ToString("x2").ToLower());
}
return sb.ToString();
}
Do I want to be testing it? If so, what do you recommend?
My thought process is as follows:
What logic is there here.
The answer is my for loop and ToString("x2") so from my understanding I want to be testing this part?
I can assume Encoding.UTF8.GetBytes(plainText) works. Correct assumption?
I can assume SHA256CryptoServiceProvider.ComputeHash() works. Correct assumption?
I want to be only testing my logic. In this case is limited to the printing of hex encoded hash. Correct?
Thanks.