public void CanEquateRowValues() { var rows1 = new ResultSetRowCollection(); var rows2 = new ResultSetRowCollection(); Assert.IsTrue(rows1.EqualRowCollections(rows2)); rows1.Add(new ResultSetRow()); rows2.Add(new ResultSetRow()); Assert.IsTrue(rows1.EqualRowCollections(rows2)); rows1[0]["cola"] = 99; Assert.IsFalse(rows1.EqualRowCollections(rows2)); rows2[0]["cola"] = 99; Assert.IsTrue(rows1.EqualRowCollections(rows2)); rows1.Add(new ResultSetRow()); rows2.Add(new ResultSetRow()); Assert.IsTrue(rows1.EqualRowCollections(rows2)); rows1[1]["abc"] = "hi"; Assert.IsFalse(rows1.EqualRowCollections(rows2)); rows2[1]["abc"] = "hi"; Assert.IsTrue(rows1.EqualRowCollections(rows2)); rows1.Add(new ResultSetRow()); rows2.Add(new ResultSetRow()); rows1[1]["test"] = "klm"; rows2[2]["test2"] = "klm"; Assert.IsFalse(rows1.EqualRowCollections(rows2)); }
public void CanValidateWithoutNoRecursiveCheck() { var schema = new ResultSetSchema(); var rows = new ResultSetRowCollection(); rows.Add(new ResultSetRow()); rows[0]["Name"] = "will"; Assert.IsNull(rows.Validate(schema)); }
public void CanWriteXmlFor0Rows() { using (var w = new TestXmlWriter()) { var rows = new ResultSetRowCollection(); new ResultSetRowCollectionSerializer().Serialize(w.Writer, rows, new ResultSetRowCollectionSerializerContext { Schema = new ResultSetSchema() }); Assert.AreEqual("<Rows />", w.Xml); } }
public void ValidationSucceedsWithRecursiveCheckAndValidRows() { var schema = new ResultSetSchema(); schema.Columns.Add(new Column { Name = "Name", ClrType = typeof(string), DbType = "varchar" }); var rows = new ResultSetRowCollection(); rows.Add(new ResultSetRow()); rows[0]["Name"] = "will"; Assert.IsNull(rows.Validate(schema, true)); }
public void ValidationFailsWithRecursiveCheckAndInvalidRow() { var schema = new ResultSetSchema(); var rows = new ResultSetRowCollection(); rows.Add(new ResultSetRow()); rows[0]["Name"] = "will"; var ex = rows.Validate(schema, true); Assert.IsNotNull(ex); Assert.AreSame(typeof(InvalidOperationException), ex.GetType()); Assert.AreEqual("Found invalid row(s)", ex.Message); Assert.IsNotNull(ex.InnerException); }
public void CanCreateFromReaderWith0Rows() { var r = new TestDataReader(); var rs = new ResultSet(); r.ResultSets.Add(rs); rs.Schema.Columns.Add(new Column { Name = "cola", ClrType = typeof(string), DbType = "varchar" }); var readRs = ResultSetRowCollection.CreateFromReader(r); Assert.IsNotNull(readRs); Assert.AreEqual(0, readRs.Count); }
public void CanwriteXmlFor2Rows() { using (var w = new TestXmlWriter()) { var rows = new ResultSetRowCollection(); rows.Add(new ResultSetRow()); rows.Add(new ResultSetRow()); rows[0]["Name"] = "john"; rows[1]["Name"] = "smith"; var schema = new ResultSetSchema(); schema.Columns.Add(new Column { ClrType = typeof(string), DbType = "varchar", Name = "Name" }); new ResultSetRowCollectionSerializer().Serialize(w.Writer, rows, new ResultSetRowCollectionSerializerContext { Schema = schema }); Assert.AreEqual("<Rows><Row><Name>john</Name></Row><Row><Name>smith</Name></Row></Rows>", w.Xml); } }
public static bool EqualRowCollections(this ResultSetRowCollection c1, ResultSetRowCollection c2) { if (c2 == null) { throw new ArgumentNullException("c2"); } // check for equal number of rows if (c1.Count != c2.Count) { return(false); } for (var t = 0; t < c1.Count; t++) { if (!c1[t].EqualRows(c2[t])) { return(false); } } return(true); }
public void CreateFromReaderThrowsWithNullReader() { Assert.ThrowsException <ArgumentNullException>(() => { ResultSetRowCollection.CreateFromReader(null); }, "reader"); }