fast-member icon indicating copy to clipboard operation
fast-member copied to clipboard

Add support for multiple result sets with ObjectReader

Open gtbuchanan opened this issue 6 years ago • 0 comments

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.

gtbuchanan avatar May 31 '18 20:05 gtbuchanan