public void CreateTestCases() { Random randSource = new Random(); testValues = new List<int>(Enumerable.Range(1, 17).Select(x => randSource.Next())); testTuple = new Tuple<int, String, bool>(testValues[0], testValues[1].ToString(), testValues[2] % 2 == 0); testTupleType = typeof (Tuple<int, String, bool>); testNestedTuple = new Tuple <int, int, int, int, int, int, int, Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>>( testValues[0], testValues[1], testValues[2], testValues[3], testValues[4], testValues[5], testValues[6], new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>( testValues[7], testValues[8], testValues[9], testValues[10], testValues[11], testValues[12], testValues[13], new Tuple<int, int, int>(testValues[14], testValues[15], testValues[16]))); testNestedTupleType = typeof ( Tuple <int, int, int, int, int, int, int, Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>>); testExtendedTuple = new ExtendedTuple<Tuple<int, String, bool>>(testTuple); }
public void CreateTestCases() { Random randSource = new Random(); testValues = new List <int>(Enumerable.Range(1, 17).Select(x => randSource.Next())); testTuple = new Tuple <int, String, bool>(testValues[0], testValues[1].ToString(), testValues[2] % 2 == 0); testTupleType = typeof(Tuple <int, String, bool>); testNestedTuple = new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int> > >( testValues[0], testValues[1], testValues[2], testValues[3], testValues[4], testValues[5], testValues[6], new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int> >( testValues[7], testValues[8], testValues[9], testValues[10], testValues[11], testValues[12], testValues[13], new Tuple <int, int, int>(testValues[14], testValues[15], testValues[16]))); testNestedTupleType = typeof( Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int> > >); testExtendedTuple = new ExtendedTuple <Tuple <int, String, bool> >(testTuple); }
public void ExtendedTuple_TestTupleIndexerWithNullableTypes() { Tuple <int?, int> t = new Tuple <int?, int>(null, 2); ExtendedTuple <Tuple <int?, int> > et = new ExtendedTuple <Tuple <int?, int> >(t); Assert.AreEqual(null, et[0]); }
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 void ExtendedTuple_TestTupleIndexerWithNullableTypes() { Tuple<int?, int> t = new Tuple<int?, int>(null, 2); ExtendedTuple<Tuple<int?, int>> et = new ExtendedTuple<Tuple<int?, int>>(t); Assert.AreEqual(null, et[0]); }
public void ExtendedTuple_InvalidTupleType_ThrowsTypeInitializationException() { ExtendedTuple<MyStructuralClass> testCase = new ExtendedTuple<MyStructuralClass>(new MyStructuralClass()); }
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); }
public void ExtendedTuple_InvalidTupleType_ThrowsTypeInitializationException() { ExtendedTuple <MyStructuralClass> testCase = new ExtendedTuple <MyStructuralClass>(new MyStructuralClass()); }