I have a unit test written in c# that uses a .CSV as a datasource:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData.csv", "TestData#csv", DataAccessMethod.Sequential), DeploymentItem("TxRP.Tests\\TestData.csv"), TestMethod()]
public void CompareOrgsTest()
{
// Arrange
var vdd = new Mock<ViewDataDictionary>().Object;
HtmlHelper helper = MVCMocks.CreateMockHelper(vdd);
string orgOne = testContextInstance.DataRow["OrgOne"].ToString();
string orgTwo = testContextInstance.DataRow["OrgTwo"].ToString();
bool expected = Convert.ToBoolean(testContextInstance.DataRow["OrgCompareExpected"]);
// Act
bool actual = HtmlHelpers.CompareOrg(helper, orgOne, orgTwo);
// Assert
Assert.AreEqual(expected, actual, "Did not return " + expected + ". Org1=" + orgOne + ", Org2=" + orgTwo);
}
Works fabulously, until I needed to add some null value testing. I can't seem to figure out how to pass a NULL value as one of the data elements...has anyone done this before?
Thanks!
You can't. You're reading in values from a CSV file. There is no such thing as a 'null' value in a CSV file. The next best thing I know to do would be to write some code to test 'null' if a 'magic string' is read from the CSV file.
string orgOne = testContextInstance.DataRow["OrgOne"].ToString();
if (orgOne=="null")
orgOne = null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With