Skip to content

Instantly share code, notes, and snippets.

@cmillr
Created April 14, 2014 20:04
Show Gist options
  • Save cmillr/10678741 to your computer and use it in GitHub Desktop.
Save cmillr/10678741 to your computer and use it in GitHub Desktop.
This gets CSV values in property syntax for data-driven tests
using System;
using System.Dynamic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public class TestDataReader : DynamicObject
{
private readonly TestContext _testContextInstance;
public TestDataReader(TestContext testContext)
{
_testContextInstance = testContext;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
try
{
result = _testContextInstance.DataRow[binder.Name];
if (result is DBNull)
{
result = null;
}
return true;
}
catch
{
result = null;
return false;
}
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
throw new Exception("The TestDataReader type is read-only. You cannot set new values.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment