Provides data from Comma Separated Values (CSV) contents.

Namespace:  MbUnit.Framework
Assembly:  MbUnit (in MbUnit.dll) Version: 3.2.0.0 (3.2.528.0)

Syntax

C#
public class CsvDataAttribute : ContentAttribute
Visual Basic (Declaration)
Public Class CsvDataAttribute _
	Inherits ContentAttribute

Remarks

If the CSV document has a header, then it is interpreted as the names of the columns. Columns with names in brackets, such as "[ExpectedException]", are interpreted as containing metadata values associated with the named key.

Examples

This example reads data from an Embedded Resource called Data.csv within the same namespace as the test fixture.

Data files:

CopyC#
Item, Quantity, UnitPrice, [Category]
Bananas, 3, 0.85, Produce
Cookies, 10, 0.10, Snacks
# Comment: mmmm!
Shortbread, 1, 2.25, Snacks

A simple test.

CopyC#
public class AccountingTests
{
    [Test]
    [CsvData(ResourcePath = "Data.csv")]
    public void ShoppingCartTotalWithSingleItem(string item, decimal unitPrice, decimal quantity)
    {
        ShoppingCart shoppingCart = new ShoppingCart();
        shoppingCart.Add(item, unitprice, quantity);
        Assert.AreEqual(unitPrice * quantity, shoppingCart.TotalCost);
    }
}

Inheritance Hierarchy

See Also