public static T Column <T>(this FakeDataReader reader, int i) { if (reader is null) { throw new ArgumentException(nameof(reader)); } return(_extractor.Extract <T>(reader.GetValue(i))); }
public void Extract_Int32_Throws_On_DBNull() { // Arrange // Act TestDelegate test = () => _extractor.Extract <int>(DBNull.Value); // Assert Assert.That(test, Throws.TypeOf <InvalidCastException>()); }
public void Extract_Int32_Unboxes(object input) { // Arrange // Act int result = _extractor.Extract <int>(input); // Assert Assert.That(result, Is.EqualTo(input)); }
public void Extract_Int32_Unwraps(int input) { // Arrange WrappedInt32 value = new WrappedInt32(input); // Act int result = _extractor.Extract <int>(value); // Assert Assert.That(result, Is.EqualTo(input)); }
public void Unbox_DataReader_Columns_with_Custom_Handlers(object input) { // Arrange ValueExtractor extractor = ValueExtractor.Create(config => { config.UseHandler <bool>( (obj, ctx) => { if (obj is bool b) { ctx.Result = b; return; } if (obj is string s) { ctx.Result = s == "Y"; return; } }); }); // Act bool result = extractor.Extract <bool>(input); // Assert }
public void ContextualHandler_Throws_InvalidCastException_If_No_Result_Assigned() { // Arrange ValueExtractor extractor = ValueExtractor.Create(config => { config.UseHandler <string>( (obj, ctx) => { }); }); // Act TestDelegate test = () => extractor.Extract <string>(""); // Assert Assert.That(test, Throws.TypeOf <InvalidCastException>()); }
internal virtual object Extract(object o) { return(ValueExtractor.Extract(o)); }