0

Apologies in advance as I'm fairly new to this so imagine this is be being a fool.

Anyway, I looking to pass individual comma delimited data into fields/variables. I am using FileHelpers and have it working and passing back data but my C# skills now fail me.

The CSV Data is:

Tom, Password

Two, PassTwo

Three, PassThree

And the code I have is :

[DelimitedRecord(",")]
    public class UserDetailsLogin
    {
        FileHelperEngine engine = new FileHelperEngine(typeof(UserDetails));

        [Test]
        public void TestData()
        {
            string User1;
            string User2;
            string User3;
            string Password1;

            UserDetails[] res = engine.ReadFile("TestData.csv") as UserDetails[];
            foreach (UserDetails user in res)
            {
                User1 = user.UserName;
                Console.WriteLine(User1);
            }
        }
    }

    [DelimitedRecord(",")]
    public class UserDetails
    {
        public string UserName;

        public string Password;
    }

Which, for the purpose of checking writes to console:

Tom

Two

Three

How would I be able to pass individual data to variables e.g:

User1 = "Tom"

Password1 = "Password"

User2 = "Two" etc etc..

Woodman81
  • 53
  • 1
  • 7

1 Answers1

0

Neither your question nor your code is very clear.

I think you are asking how to verify the values you have read in to the UserDetails array, in which case you can use the following test:

[TestFixture]
public class UserDetailsTests
{
    [Test]
    public void TestData()
    {
        FileHelperEngine engine = new FileHelperEngine(typeof(UserDetails));
        UserDetails[] res = engine.ReadFile("TestData.csv") as UserDetails[];

        Assert.AreEqual(res[0].UserName, "User 1");
        Assert.AreEqual(res[0].Password, "Password 1");
        Assert.AreEqual(res[1].UserName, "User 2");
        Assert.AreEqual(res[2].UserName, "User 3");
    }
}
shamp00
  • 11,106
  • 4
  • 38
  • 81