public void BuilderTest() { Tuple <string, int, int, int, double> a = ExtendedTuple.Create("Hello", 4, 5, 6, 7.0); IEnumerable <int> intEnum = new[] { 1, 2, 3, 4 }; IEnumerable <Tuple <int, int, string> > tuples = intEnum.ToTuple(c => c, c => c + 1, c => c.ToString()); Trace.WriteLine(string.Join(Environment.NewLine, tuples.Select(t => t.ToString()))); }
public async Task ExecuteReader_WithNestedTupleParameter_ExecutesSuccessfully() { SqlProgram <IEnumerable <Tuple <int, string, bool, bool, decimal, decimal, double, Tuple <string, short, TestSerializableObject, byte, DateTime, DateTime, XElement, Tuple <int, long, int, int> > > > > tupleTableTypeTest = await SqlProgram <IEnumerable <Tuple <int, string, bool, bool, decimal, decimal, double, Tuple <string, short, TestSerializableObject, byte, DateTime, DateTime, XElement, Tuple <int, long, int, int> > > > > .Create((Connection)DifferentLocalDatabaseConnectionString, "spTakesMultiTupleTable"); var rows = new List < Tuple <int, string, bool, bool, decimal, decimal, double, Tuple <string, short, TestSerializableObject, byte, DateTime, DateTime, XElement, Tuple <int, long, int, int> > > >(); for (int i = 0; i < Random.Next(3, 10); i++) { rows.Add(ExtendedTuple.Create( Random.RandomInt32(), Random.RandomString(50, false), false, true, RandomSqlSafeDecimal(), RandomSqlSafeDecimal(), Random.RandomDouble(), Random.RandomString(), Random.RandomInt16(), new TestSerializableObject { String1 = Random.RandomString(), String2 = Random.RandomString() }, Random.RandomByte(), RandomSqlSafeDateTime(), RandomSqlSafeDateTime(), new XElement("Test", new XAttribute("attribute", Random.Next())), Random.RandomInt32(), Random.RandomInt64(), Random.RandomInt32(), Random.RandomInt32())); } var indexer = typeof( Tuple <int, string, bool, bool, decimal, decimal, double, Tuple <string, short, TestSerializableObject, byte, DateTime, DateTime, XElement, Tuple <int, long, int, int> > > ).GetTupleIndexer(); tupleTableTypeTest.ExecuteReader( reader => { int r = 0; while (reader.Read()) { var tuple = rows[r++]; for (int c = 0; c < 18; c++) { // Get the tuple value that was passed into the sproc. object cell = indexer(tuple, c); // Check collections (e.g. byte[]) ICollection cellCollection = cell as ICollection; if (cellCollection != null) { ICollection resultCollection = reader.GetValue(c) as ICollection; Assert.IsNotNull( resultCollection, "The db did not return a collection"); CollectionAssert.AreEqual(cellCollection, resultCollection); continue; } // Check serialized object TestSerializableObject serializedObject = cell as TestSerializableObject; if (serializedObject != null) { // Deserialize object TestSerializableObject deserializedObject = (TestSerializableObject)reader.GetObjectByName(reader.GetName(c)); // Check we don't have same object instance. Assert.IsFalse(ReferenceEquals(serializedObject, deserializedObject)); // Check equality of object instances using equality method. Assert.AreEqual(serializedObject, deserializedObject); continue; } // Check XELement XElement xelement = cell as XElement; if (xelement != null) { XElement result = XElement.Parse(reader.GetString(c)); Assert.AreEqual(xelement.ToString(), result.ToString()); continue; } Assert.AreEqual(cell, reader.GetValue(c)); } } }, rows); }