I have a file parser and my manager told me that I need to create unit tests for it. Here is my code:
public class ParsedDetails
{
public int Id { get; set; }
public Guid Guid { get; set; }
public bool IsValid { get; set; }
}
public class CsvParser : IParser
{
private const int CsvColumns = 2;
private const char CsvSeparator = ';';
private const int IdColumnIndex = 0;
private const int GuidColumnIndex = 1;
private ParsedDetails ParseLine(string line)
{
ParsedCardDetails result = new ParsedCardDetails();
//validating and parsing data
return result;
}
public IEnumerable<ParsedCardDetails> Parse(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("The path must not be empty");
}
if (!File.Exists(path))
{
throw new FileNotFoundException();
}
List<ParsedCardDetails> result = new List<ParsedCardDetails>();
var data = File.ReadAllLines(path);
foreach (var item in data)
{
var validationResult = ParseLine(item);
result.Add(validationResult);
}
return result;
}
}
So, the only thing that crossed my mind was to write unit tests to the ParseLine
method, but this is private and I have no other reason to make it public and there is no need for me to mock the parser class. Do you have any idea on how to proceed?
This is my first time writing unit tests.