Add typed procedure contract result handling

This commit is contained in:
2026-02-27 15:18:11 +01:00
parent 79cce3d1f4
commit c9a41adef3
8 changed files with 564 additions and 49 deletions

View File

@@ -0,0 +1,135 @@
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*/
using System;
using System.Collections.Generic;
using System.Data;
namespace DynamORM.Tests.Helpers
{
internal sealed class FakeMultiResultDataReader : IDataReader
{
private sealed class ResultSet
{
public string[] Names;
public Type[] Types;
public object[][] Rows;
}
private readonly List<ResultSet> _sets = new List<ResultSet>();
private int _setIndex;
private int _rowIndex = -1;
public FakeMultiResultDataReader(params Tuple<string[], Type[], object[][]>[] sets)
{
foreach (var set in sets)
_sets.Add(new ResultSet
{
Names = set.Item1,
Types = set.Item2,
Rows = set.Item3
});
}
private ResultSet Current { get { return _sets[_setIndex]; } }
public object this[string name] { get { return GetValue(GetOrdinal(name)); } }
public object this[int i] { get { return GetValue(i); } }
public int Depth { get { return 0; } }
public bool IsClosed { get; private set; }
public int RecordsAffected { get { return 0; } }
public int FieldCount { get { return Current.Names.Length; } }
public void Close() { IsClosed = true; }
public void Dispose() { Close(); }
public bool GetBoolean(int i) { return (bool)GetValue(i); }
public byte GetByte(int i) { return (byte)GetValue(i); }
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { throw new NotSupportedException(); }
public char GetChar(int i) { return (char)GetValue(i); }
public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) { throw new NotSupportedException(); }
public IDataReader GetData(int i) { throw new NotSupportedException(); }
public string GetDataTypeName(int i) { return GetFieldType(i).Name; }
public DateTime GetDateTime(int i) { return (DateTime)GetValue(i); }
public decimal GetDecimal(int i) { return (decimal)GetValue(i); }
public double GetDouble(int i) { return (double)GetValue(i); }
public Type GetFieldType(int i) { return Current.Types[i]; }
public float GetFloat(int i) { return (float)GetValue(i); }
public Guid GetGuid(int i) { return (Guid)GetValue(i); }
public short GetInt16(int i) { return Convert.ToInt16(GetValue(i)); }
public int GetInt32(int i) { return Convert.ToInt32(GetValue(i)); }
public long GetInt64(int i) { return Convert.ToInt64(GetValue(i)); }
public string GetName(int i) { return Current.Names[i]; }
public int GetOrdinal(string name)
{
for (int i = 0; i < Current.Names.Length; i++)
if (string.Equals(Current.Names[i], name, StringComparison.OrdinalIgnoreCase))
return i;
return -1;
}
public DataTable GetSchemaTable()
{
DataTable schema = new DataTable();
schema.Columns.Add("ColumnName", typeof(string));
schema.Columns.Add("ColumnOrdinal", typeof(int));
schema.Columns.Add("ColumnSize", typeof(int));
schema.Columns.Add("NumericPrecision", typeof(short));
schema.Columns.Add("NumericScale", typeof(short));
schema.Columns.Add("DataType", typeof(Type));
schema.Columns.Add("ProviderType", typeof(int));
schema.Columns.Add("NativeType", typeof(int));
schema.Columns.Add("AllowDBNull", typeof(bool));
schema.Columns.Add("IsUnique", typeof(bool));
schema.Columns.Add("IsKey", typeof(bool));
schema.Columns.Add("IsAutoIncrement", typeof(bool));
for (int i = 0; i < Current.Names.Length; i++)
{
DataRow row = schema.NewRow();
row[0] = Current.Names[i];
row[1] = i;
row[2] = 0;
row[3] = 0;
row[4] = 0;
row[5] = Current.Types[i];
row[6] = 0;
row[7] = 0;
row[8] = true;
row[9] = false;
row[10] = false;
row[11] = false;
schema.Rows.Add(row);
}
return schema;
}
public string GetString(int i) { return (string)GetValue(i); }
public object GetValue(int i) { return Current.Rows[_rowIndex][i]; }
public int GetValues(object[] values)
{
int count = Math.Min(values.Length, FieldCount);
for (int i = 0; i < count; i++)
values[i] = GetValue(i);
return count;
}
public bool IsDBNull(int i) { return GetValue(i) == null || GetValue(i) == DBNull.Value; }
public bool NextResult()
{
if (_setIndex + 1 >= _sets.Count)
return false;
_setIndex++;
_rowIndex = -1;
return true;
}
public bool Read()
{
if (_rowIndex + 1 >= Current.Rows.Length)
return false;
_rowIndex++;
return true;
}
}
}