NUnit 3.4.1、ジャストモック 2016.2.713.2
私はテスト中のクラスを持っています:
public class AppManager {
public string[] GetAppSets() => Registry.LocalMachine
.OpenSubKey(@"SOFTWARE\Autodesk\AutoCAD", false)
?.GetSubKeyNames();
}
また、GetAppSets
メソッドのテストがあります:
[Test]
public void GetAppSets_Returns_ValidValue() {
const string subkey = @"SOFTWARE\Autodesk\AutoCAD";
/* The sets of applications which are based on
* AutoCAD 2009-2017. */
string[] fakeSets = new[] { "R17.2", "R18.0",
"R18.1", "R18.2", "R19.0", "R19.1", "R20.0",
"R20.1","R21.0" };
RegistryKey rk = Mock.Create<RegistryKey>();
Mock.Arrange(() => rk.GetSubKeyNames()).Returns(
fakeSets);
Mock.Arrange(() => Registry.LocalMachine.OpenSubKey
(subkey, false)).Returns(rk);
AppManager appMng = new AppManager();
string[] appSets = appMng.GetAppSets();
Assert.AreEqual(fakeSets, appSets);
}
できます。しかし、メソッドが "S OFTWARE\Autodesk\AutoCAD " の代わりに " Software\Autodesk\AutoCAD " または " software\autodesk\autocadGetAppSets
" 文字列を使用する場合、私のテストは失敗します:文字列の大文字と小文字が変更される場合、変数はキーがコンピュータに存在しません)。appSets
null
したがって、この場合、テスターはGetAppSets
メソッドの実装 (悪いバリアント)を知るか、大文字と小文字を区別しない文字列のようなパラメーターを処理する必要があります。
2番目のバリアントを使用することは可能ですか?