Skip to content

Instantly share code, notes, and snippets.

@miklund
Created January 7, 2016 13:01
Show Gist options
  • Save miklund/5d94934a6b7b1b83c0fd to your computer and use it in GitHub Desktop.
Save miklund/5d94934a6b7b1b83c0fd to your computer and use it in GitHub Desktop.
2011-05-26 Data driven test cases in NUnit
# Title: Data driven test cases in NUnit
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2011/05/26/data-driven-test-cases-in-nunit.html
private IEnumerable MassiveAmountOfUsers
{
get { return GetMassiveAmountOfUsers(); }
}
private IEnumerable GetMassiveAmountOfUsers()
{
var doc = XDocument.Load("users.xml");
return
from user in doc.Descendants("user")
let username = user.Attribute("username").Value
let password = user.Attribute("password").Value
let expected = user.Attribute("success").Value
.Equals("true", StringComparison.InvariantCultureIgnoreCase)
select new object[] { username, password, expected };
}
[TestCaseSource("MassiveAmountOfUsers")]
public void ShouldLogin(string username, string password, bool expected)
{
/* Setup */
var repository = new UserRepository();
/* Test */
var result = repository.Authenticate(username, password);
/* Assert */
Assert.That(result, Is.EqualTo(expected));
}
<?xml version="1.0" encoding="utf-8" ?>
<users>
<user username="fsse" password="dj7sihfs" success="true" />
<user username="hgtd" password="sd122?=s" success="true" />
<user username="asde" password="!!sf3mff" success="true" />
<user username="bsfd" password="--sdfj+?" success="true" />
<user username="aefb" password="!#¤%/(sd" success="true" />
...
</users>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment