public void can_read_single_nullable_primative_type() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(long) }, Values = new object[] { 1L }, }; var val = stubDataReader.Single <long?>(); }
public void can_read_single_nullable_enum() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, }; var val = stubDataReader.Single <TestEnum?>(); }
public async Task can_read_single_primative_type_async() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(long) }, Values = new object[] { 1L }, }; await stubDataReader.SingleAsync <long>(); }
public void can_read_single() { var reader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(long) }, Values = new object[] { 1L }, }; reader.Single <long>(); }
public void cannot_read_single_when_more_than_one_row() { var stubDataReader = new StubDataReader { Names = new [] { "ORDER_ID" }, Types = new [] { typeof(int) }, Values = new object[] { 1 }, RecordCount = 2, }; Assert.Throws <InvalidOperationException>(() => { stubDataReader.Single <int>(); }); }
public void cannot_read_default_value_for_single() { var stubDataReader = new StubDataReader { Names = new[] { "ORDER_ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, RecordCount = 0, }; Assert.Throws <InvalidOperationException>(() => { stubDataReader.Single <int>(); }); }
public void can_read_single_nullable_via_explicit_operator() { var stubDataReader = new StubDataReader { Names = new[] { "VALUE" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, }; var val = stubDataReader.Single <Id <Order>?>(); Assert.AreEqual((Id <Order>) 1, val.Value); }
public async Task can_read_single_async() { var reader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(long) }, Values = new object[] { 1L }, }; var task = Task.FromResult <DbDataReader>(reader); await task.SingleAsync <long>(); }
public void can_read_into_struct() { var stubDataReader = new StubDataReader { Names = new[] { "VALUE" }, Types = new[] { typeof(long) }, Values = new object[] { 1L }, }; var val = stubDataReader.Single <TestStruct <long> >(); Assert.AreEqual(1L, val.Value); }
public void can_read_single_or_default() { var stubDataReader = new StubDataReader { Names = new [] { "ORDER_ID" }, Types = new [] { typeof(int) }, Values = new object[] { 1 }, }; var val = stubDataReader.SingleOrDefault <int>(); Assert.AreEqual(1, val); }
public void can_read_single_object_containing_guid() { var g = Guid.NewGuid(); var stubDataReader = new StubDataReader { Names = new[] { "VALUE" }, Types = new[] { g.GetType() }, Values = new object[] { g }, }; var read = stubDataReader.Single <Guid?>(); Assert.AreEqual(g, read.Value); }
public void can_read_single_DateTimeOffset() { var dt = DateTimeOffset.Now; var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { dt.GetType() }, Values = new object[] { dt }, }; var read = stubDataReader.Single <DateTimeOffset>(); Assert.AreEqual(dt, read); }
public void can_read_single_guid() { var g = Guid.NewGuid(); var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { g.GetType() }, Values = new object[] { g }, }; var read = stubDataReader.Single <Guid>(); Assert.AreEqual(g, read); }
public void can_read_decimal_into_nullable_decimal() { var stubDataReader = new StubDataReader { Names = new[] { "AMOUNT" }, Types = new[] { typeof(decimal) }, Values = new object[] { 1m }, }; var func = Extensions.GetMappingFunc <NullableDecimal>(stubDataReader); var result = func(stubDataReader); Assert.IsNotNull(result); Assert.AreEqual(1m, result.Amount); }
public void can_read_int_into_enum() { var stubDataReader = new StubDataReader { Names = new[] { "ID", "BOOKING_STATE" }, Types = new[] { typeof(int), typeof(int) }, Values = new object[] { 1, 2 }, }; var func = Extensions.GetMappingFunc <Booking>(stubDataReader); var result = func(stubDataReader); Assert.IsNotNull(result); Assert.AreEqual(State.Second, result.State); }
public async Task can_convert_to_lookup_and_change_type_async() { var stubDataReader = new StubDataReader { Names = new[] { "ID", "Name" }, Types = new[] { typeof(int), typeof(string) }, Values = new object[] { 1, "hello" }, }; var val = await stubDataReader.ToLookupAsync <Order, int, string>(ord => ord.Id, ord => ord.Name); Assert.AreEqual(1, val[1].Count); Assert.AreEqual("hello", val[1].First()); Assert.AreEqual(1, val.Count, "count"); }
public async Task can_convert_to_dictionary_and_change_type_async() { var stubDataReader = new StubDataReader { Names = new[] { "ID", "Name" }, Types = new[] { typeof(int), typeof(string) }, Values = new object[] { 1, "hello" }, }; var val = await stubDataReader.ToDictionaryAsync <Order, int, string>(ord => ord.Id, ord => ord.Name); Assert.AreEqual(true, val.ContainsKey(1)); Assert.AreEqual("hello", val[1]); Assert.AreEqual(1, val.Count, "count"); }
public void can_convert_to_lookup() { var stubDataReader = new StubDataReader { Names = new[] { "ID", "Name" }, Types = new[] { typeof(int), typeof(string) }, Values = new object[] { 1, "hello" }, }; var val = stubDataReader.ToLookup <int, Order>(ord => ord.Id); Assert.AreEqual(1, val[1].Count); Assert.AreEqual(1, val[1].First().Id); Assert.AreEqual("hello", val[1].First().Name); }
public void can_read_long_into_nullable_long() { var stubDataReader = new StubDataReader { Names = new [] { "ID" }, Types = new [] { typeof(long) }, Values = new object[] { 1L }, }; var func = Extensions.GetMappingFunc <NullableLong>(stubDataReader); var result = func(stubDataReader); Assert.IsNotNull(result); Assert.AreEqual(1L, result.Id); }
public void can_read_int_into_int() { var stubDataReader = new StubDataReader { Names = new[] { "ORDER_ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, }; var func = Extensions.GetMappingFunc <TestPropertyId>(stubDataReader); var result = func(stubDataReader); Assert.IsNotNull(result); Assert.AreEqual(1, result.OrderId); }
public void can_read_zero_rows() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, RecordCount = 0, }; var seq = new DynamicDataSequence(stubDataReader); var enm = seq.GetEnumerator(); Assert.IsFalse(enm.MoveNext()); }
public void can_convert_to_dictionary() { var stubDataReader = new StubDataReader { Names = new[] { "ID", "Name" }, Types = new[] { typeof(int), typeof(string) }, Values = new object[] { 1, "hello" }, }; var val = stubDataReader.ToDictionary <int, Order>(ord => ord.Id); Assert.AreEqual(true, val.ContainsKey(1)); Assert.AreEqual(1, val[1].Id); Assert.AreEqual("hello", val[1].Name); Assert.AreEqual(1, val.Count, "count"); }
public void can_get_values_of_row_via_dynamic() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, }; var seq = new DynamicDataSequence(stubDataReader); var enm = seq.GetEnumerator(); Assert.IsTrue(enm.MoveNext()); dynamic row = enm.Current; Assert.AreEqual(1, row.ID, "row.ID"); Assert.AreEqual(1, row.Id, "row.Id"); }
public void can_get_values_of_row() { var stubDataReader = new StubDataReader { Names = new[] { "ID" }, Types = new[] { typeof(int) }, Values = new object[] { 1 }, }; var seq = new DynamicDataSequence(stubDataReader); var enm = seq.GetEnumerator(); Assert.IsTrue(enm.MoveNext()); DynamicRow row = enm.Current; Assert.AreEqual(1, row.Count, "row.Count"); Assert.AreEqual(true, row.ContainsKey("ID"), "row.ContainsKey ID"); Assert.AreEqual(true, row.ContainsKey("id"), "row.ContainsKey id"); Assert.AreEqual(1, row["id"], "row[id]"); Assert.AreEqual(1, row[0], "row[0]"); }