I have a large application that reads some parameters from a configuration file.
I'm writing unit tests for a class that generates a result after performing certain operations with both a parameter and a value read from the configuration file:
internal static class Password
{
private static readonly byte PASSWORD_PRIVATE_KEY
= ConfigFile.ReadByte("PASSWORD_PRIVATE_KEY");
public static byte Generate(byte passwordPublicKey);
}
In my unit test, I know the values the Password.Generate()
method should return for given PASSWORD_PRIVATE_KEY
and PASSWORD_PUBLIC_KEY
. But I'd like the PASSWORD_PRIVATE_KEY
value used to be defined in the unit test class, not in the configuration file:
[TestMethod]
public void PasswordGenerate_CalculatedProperly()
{
byte passwordPublicKey = 0x22;
Password_Accessor.PASSWORD_PRIVATE_KEY = 0xF0;
byte expectedGenerated = 0xAA;
byte generated = Password_Accessor.Generate(passwordPublicKey);
Assert.AreEqual(expectedGenerated, generated);
}
Is there a way I can write the private static readonly
thru code, so I don't have to rely any configuration file for my tests?