コード例 #1
0
 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?>();
 }
コード例 #2
0
 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?>();
 }
コード例 #3
0
 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>();
 }
コード例 #4
0
ファイル: ApiTests.cs プロジェクト: SammyEnigma/Mapper
        public void can_read_single()
        {
            var reader = new StubDataReader
            {
                Names  = new[] { "ID" },
                Types  = new[] { typeof(long) },
                Values = new object[] { 1L },
            };

            reader.Single <long>();
        }
コード例 #5
0
        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>(); });
        }
コード例 #6
0
        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>(); });
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: ApiTests.cs プロジェクト: SammyEnigma/Mapper
        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>();
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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");
        }
コード例 #17
0
        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");
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
ファイル: DynamicTests.cs プロジェクト: SammyEnigma/Mapper
        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());
        }
コード例 #22
0
        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");
        }
コード例 #23
0
ファイル: DynamicTests.cs プロジェクト: SammyEnigma/Mapper
        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");
        }
コード例 #24
0
ファイル: DynamicTests.cs プロジェクト: SammyEnigma/Mapper
        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]");
        }