Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
How can I test this class using xUnit?
Post Body

I am new to xUnit and generally unit testing. I am really confused about how to write tests for this. This is basically a class from a data access assembly from a project I am working on.

 public class CSVPlayerReader : IPlayerReader
    {
        private const string PLAYERBIO_PATH = @"xxxx\Data\PlayerBio.csv";
        private const string PLAYERH2H_PATH = @"xxxx\Data\PlayerH2H.csv";

        public CSVPlayerReader()
        {
        }

        public IEnumerable<PlayerBio> GetAllPlayerBios()
        {
            var reader = GetReader(PLAYERBIO_PATH);
            return (reader.GetRecords<PlayerBio>());
        }

        public IEnumerable<PlayerH2H> GetAllPlayerH2Hs()
        {
            var reader = GetReader(PLAYERH2H_PATH);
            return reader.GetRecords<PlayerH2H>();
        }

        public PlayerBio GetPlayerBio(int PlayerId)
        {
            var reader = GetReader(PLAYERBIO_PATH);
            var allPlayerBios = reader.GetRecords<PlayerBio>().ToList();
            PlayerBio pb = allPlayerBios.Find(p => p.Id == PlayerId);
            return pb;
        }

        public IEnumerable<PlayerH2H> GetPlayerH2Hs(int Player1Id, int Player2Id)
        {
            var reader = GetReader(PLAYERH2H_PATH);
            var allPlayerH2Hs = reader.GetRecords<PlayerH2H>().Where(hh => (hh.Player1Id == Player1Id) && (hh.Player2Id == Player2Id));
            return allPlayerH2Hs;
        }

        private CsvReader GetReader(string Path)
        {
            var streamReader = new StreamReader(Path);
            var csvReader = new CsvReader(streamReader, CultureInfo.InvariantCulture);
            return csvReader;
        }
    }

So for example while testing method GetAllPlayerBios, I would like to check whether it throws the correct exception if it cannot find the file or there is some permissions issue etc. But since the file paths are stored in private members, I am not sure what should be done. I have also read opinions that file or sql reading classes don't need to be unit tested and integration tests should be more than enough. So I am not sure what to do here.

Author
Account Strength
60%
Account Age
8 years
Verified Email
No
Verified Flair
No
Total Karma
2,382
Link Karma
1,651
Comment Karma
690
Profile updated: 6 days ago
Posts updated: 5 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago