I am trying to test an exception, NUnit 3.11 is giving me the error, and the unit test is failing. I want Nunit to green pass if it receives this exception, not error out. How would I resolve this?
Feel free to improve code if you want, just started learning programming few months ago.
When running it gives the exception itself, does not pass.
Test errors out- Message: System.ArgumentException : Too much data
public class ParseVendorSupply
{
public VendorSupply FromCsv(string csvLine)
{
string[] values = csvLine.Split(',');
if (values.Length > 3)
{
throw new System.ArgumentException("Too much data");
}
VendorSupply vendorsupply = new VendorSupply();
vendorsupply.VendorId = Convert.ToInt16(values[0]);
vendorsupply.ProductId = Convert.ToInt16(values[1]);
vendorsupply.Quantity = Convert.ToInt16(values[2]);
return vendorsupply;
}
}
Test:
public class ParseVendorSupplyNunit
{
ParseVendorSupply parseVendorSupplytest = new ParseVendorSupply();
[Test]
public void FromCsv_ParseCorrectly_Extradata()
{
string csvLineTest = "5,8,3,9,5";
//VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.That(parseVendorSupplytest.FromCsv(csvLineTest), Throws.ArgumentException);
}