I am trying to convert the below pex testmethod to a normal unit test. Though I am planning to use Microsoft Fakes where it is required, I want to understand few things first.
[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);
}
And I have converted that to a simple unit test like below:
[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);
}
I have two questions here:
Your new test appears to be missing the step where you copy the contents of the keyValuePairs
array into the nameValueCollection
collection. I believe this was done in the original test by this line:
nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs);