我正在尝试将下面的pex测试方法转换为正常的单元测试。虽然我打算在需要的地方使用Microsoft Fakes,但我想先了解一些事情。
[TestMethod]
[PexGeneratedBy(typeof(ErrorLogTest))]
public void Initialize139()
{
ErrorLog errorLog;
NameValueCollection nameValueCollection;
errorLog = new ErrorLog();
errorLog.MyProperty = false;
KeyValuePair<string, string>[] keyValuePairs = new KeyValuePair<string, string>[5];
KeyValuePair<string, string> s0 = new KeyValuePair<string, string>("", "");
keyValuePairs[0] = s0;
KeyValuePair<string, string> s1 = new KeyValuePair<string, string>("", "");
keyValuePairs[1] = s1;
KeyValuePair<string, string> s2 = new KeyValuePair<string, string>("", "");
keyValuePairs[2] = s2;
KeyValuePair<string, string> s3 = new KeyValuePair<string, string>("", "");
keyValuePairs[3] = s3;
KeyValuePair<string, string> s4 = new KeyValuePair<string, string>("", "");
keyValuePairs[4] = s4;
nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs);
this.Initialize(errorLog, "", nameValueCollection);
Assert.IsNotNull((object)errorLog);
Assert.AreEqual<bool>(false, errorLog.MyProperty);
}
我已将其转换为如下所示的简单单元测试:
[TestMethod]
public void Initialize1390()
{
ErrorLog errorLog;
NameValueCollection nameValueCollection = new NameValueCollection();
errorLog = new ErrorLog();
errorLog.MyProperty = false;
KeyValuePair<string, string>[] keyValuePairs = new KeyValuePair<string, string>[5];
KeyValuePair<string, string> s0 = new KeyValuePair<string, string>("", "");
keyValuePairs[0] = s0;
KeyValuePair<string, string> s1 = new KeyValuePair<string, string>("", "");
keyValuePairs[1] = s1;
KeyValuePair<string, string> s2 = new KeyValuePair<string, string>("", "");
keyValuePairs[2] = s2;
KeyValuePair<string, string> s3 = new KeyValuePair<string, string>("", "");
keyValuePairs[3] = s3;
KeyValuePair<string, string> s4 = new KeyValuePair<string, string>("", "");
keyValuePairs[4] = s4;
errorLog.Initialize("", nameValueCollection);
Assert.IsNotNull((object)errorLog);
Assert.AreEqual<bool>(false, errorLog.MyProperty);
}
我在这里有两个问题:
答案 0 :(得分:1)
您的新测试似乎缺少将keyValuePairs
数组的内容复制到nameValueCollection
集合中的步骤。我相信这是在这条线的原始测试中完成的:
nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs);