Created
April 14, 2014 20:04
-
-
Save cmillr/10678741 to your computer and use it in GitHub Desktop.
This gets CSV values in property syntax for data-driven tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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