mgravell / fast-member

Automatically exported from code.google.com/p/fast-member
Apache License 2.0
1.03k stars 139 forks source link

Add support for multiple result sets with ObjectReader #58

Open gtbuchanan opened 6 years ago

gtbuchanan commented 6 years ago

I've found FastMember to be excellent for wrapping dummy data in unit tests for logic using DbDataReader. It would be great if ObjectReader supported creating a reader with multiple result sets since it is much more user-friendly than DataSet.CreateDataReader.

Current test usage example using NUnit/AutoFixture:

internal sealed class TestRow
{
    public string StringColumn { get; set; }

    public int? IntColumn { get; set; }
}

[Test, AutoData]
public void Coalesce_ReturnsDefaultNullInt(IFixture fixture, int defaultValue)
{
    var row = fixture.Build<TestRow>().Without(r => r.IntColumn).Create();
    var sut = ObjectReader.Create(new[] { row });
    sut.Read();

    var value = sut.Coalesce(nameof(row.IntColumn), defaultValue);

    Assert.That(value, Is.EqualTo(defaultValue));
}

This is obviously a very simple example using a single result set, but hopefully you can see how useful it would be to use ObjectReader with AutoFixture to generate more complex data sets without having to resort to mocking or manually building a DataSet.