public void Rows_in_result_set_without_id_column_values_are_mapped_to_separate_entities_even_though_columns_values_match() { var resultSet = new ResultSet(); resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "First name"), new ColumnValue("ChildWithoutId Name", "child name 0")); resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "Another first name"), new ColumnValue("ChildWithoutId Name", "child name 1")); resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "First name"), new ColumnValue("ChildWithoutId Name", "child name 2")); var parents = _mapper.CreateInstanceGraphs <ParentWithoutId>(resultSet, new[] { _idLessRelation }); Assert.AreEqual(3, parents.Count); Assert.AreEqual(1, parents[0].Children.Count); Assert.AreEqual(1, parents[1].Children.Count); Assert.AreEqual(1, parents[2].Children.Count); Assert.AreEqual("First name", parents[0].Name); Assert.AreEqual("Another first name", parents[1].Name); Assert.AreEqual("First name", parents[2].Name); Assert.AreEqual("child name 0", parents[0].Children[0].Name); Assert.AreEqual("child name 1", parents[1].Children[0].Name); Assert.AreEqual("child name 2", parents[2].Children[0].Name); Assert.AreEqual(parents[0], parents[0].Children[0].Parent); Assert.AreEqual(parents[1], parents[1].Children[0].Parent); Assert.AreEqual(parents[2], parents[2].Children[0].Parent); }
public void Two_rows_for_entity_without_id_sharing_no_entities_are_mapped_to_two_separate_hierachies() { var resultSet = new ResultSet(); resultSet.AddRow(new ColumnValue("Parent Id", _guid1), new ColumnValue("Child Id", 1), new ColumnValue("GrandChild Id", 2)); resultSet.AddRow(new ColumnValue("Parent Id", _guid2), new ColumnValue("Child Id", 3), new ColumnValue("GrandChild Id", 4)); var parents = _mapper.CreateInstanceGraphs <Parent>(resultSet, new[] { _parentChildRelation, _childGrandChildRelation }); Assert.AreEqual(2, parents.Count); var firstParent = parents.First(); var secondParent = parents.Last(); var firstChild = firstParent.Children.FirstOrDefault(); var secondChild = secondParent.Children.FirstOrDefault(); Assert.AreEqual(1, firstParent.Children.Count); Assert.AreEqual(1, firstChild.GrandChildren.Count); Assert.AreEqual(_guid1, firstParent.Id); Assert.AreEqual(1, firstChild.Id); Assert.AreEqual(2, firstChild.GrandChildren.First().Id); Assert.AreEqual(_guid2, secondParent.Id); Assert.AreEqual(3, secondChild.Id); Assert.AreEqual(4, secondChild.GrandChildren.First().Id); }
private static ResultSet CreateResultSet() { var res = new ResultSet("Int", "String", "DateTime", "Double"); res.AddRow(1, "String", DateTime.Today, 1.1); res.AddRow(2, "String2", DateTime.Today, 1.2); return(res); }
public async Task AddRowSuccess() { // Setup: // ... Create a standard result set with standard data var fileFactory = MemoryFileSystem.GetFileStreamFactory(); var mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery); ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fileFactory); await resultSet.ReadResultToEnd(mockReader, CancellationToken.None); // ... Create a mock reader that has one row object[] row = Enumerable.Range(0, Common.StandardColumns).Select(i => "QQQ").ToArray(); IEnumerable <object[]> rows = new List <object[]> { row }; TestResultSet[] results = { new TestResultSet(TestResultSet.GetStandardColumns(Common.StandardColumns), rows) }; var newRowReader = GetReader(results, false, Constants.StandardQuery); // If: I add a new row to the result set await resultSet.AddRow(newRowReader); // Then: // ... There should be a new row in the list of rows Assert.Equal(Common.StandardRows + 1, resultSet.RowCount); // ... The new row should be readable and all cells contain the test value Assert.All(resultSet.GetRow(Common.StandardRows), cell => Assert.Equal("QQQ", cell.RawObject)); }
public void Should_not_return_empty() { var res = new ResultSet("c1"); res.AddRow(1); Assert.False(res.IsEmpty); }
private static void MapRow(DbDataReader dr, int numberOfColumns, ResultSet table) { var row = new object[numberOfColumns]; for (int i = 0; i < numberOfColumns; i++) { row[i] = (DBNull.Value.Equals(dr[i])) ? null : dr[i]; } table.AddRow(row); }
public void Creating_instances_from_two_rows_with_single_parent_with_two_children_gives_single_parent_with_two_children() { var resultSet = new ResultSet(); resultSet.AddRow(new ColumnValue("Child Id", 1), new ColumnValue("Parent Id", _guid1)); resultSet.AddRow(new ColumnValue("Child Id", 2), new ColumnValue("Parent Id", _guid1)); var parents = _mapper.CreateInstanceGraphs <Parent>(resultSet, _parentChildRelation); Assert.AreEqual(1, parents.Count); var parent = parents.First(); var children = parent.Children; Assert.AreEqual(1, children.First().Id); Assert.AreEqual(2, children.Last().Id); Assert.AreSame(parent, children.First().Parent); Assert.AreSame(parent, children.Last().Parent); }
public ResultSet ExecuteQuery(DbCommand command, string connectionString) { var resultSet = new ResultSet(); ExecuteQuery(command, reader => { var propertyValues = GetValues(reader).Select(x => new ColumnValue(x.Key, x.Value)); resultSet.AddRow(propertyValues); }); return(resultSet); }
public void Creating_child_instances_from_two_rows_with_two_children_referencing_same_parent_gives_two_children_referencing_same_parent_instance() { var resultSet = new ResultSet(); resultSet.AddRow(new ColumnValue("Child Id", 1), new ColumnValue("Parent Id", _guid1)); resultSet.AddRow(new ColumnValue("Child Id", 2), new ColumnValue("Parent Id", _guid1)); var children = _mapper.CreateInstanceGraphs <Child>(resultSet, _childParentRelation); Assert.AreEqual(2, children.Count); var parent = children.First().Parent; Assert.AreEqual(1, children.First().Id); Assert.AreEqual(2, children.Last().Id); Assert.AreEqual(_guid1, parent.Id); Assert.AreSame(parent, children.Last().Parent); Assert.AreEqual(2, parent.Children.Count); CollectionAssert.Contains(parent.Children, children.First()); CollectionAssert.Contains(parent.Children, children.Last()); }
private static ResultSet ReadResultSet(SqlCommand command) { using (var reader = command.ExecuteReader()) { var columns = CreateColumns(reader); var resultSet = new ResultSet(columns); var rowValues = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(rowValues); resultSet.AddRow(rowValues); } return(resultSet); } }
public async Task AddRowThrowsOnRead() { // Setup: // ... Create a standard result set with standard data var fileFactory = MemoryFileSystem.GetFileStreamFactory(); var mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery); ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fileFactory); await resultSet.ReadResultToEnd(mockReader, CancellationToken.None); // ... Create a mock reader that will throw on read var throwingReader = GetReader(new[] { new TestResultSet(5, 0) }, true, Constants.StandardQuery); // If: I add a row with a reader that throws on read // Then: // ... I should get an exception await Assert.ThrowsAnyAsync <DbException>(() => resultSet.AddRow(throwingReader)); // ... The row count should not have changed Assert.Equal(Common.StandardRows, resultSet.RowCount); }
/// <inheritdoc /> public override async Task <ResultSet> Execute(Query query) { using (SqlCommand cmd = GetCommand(query)) { cmd.Connection = conn; DbDataReader reader = await cmd.ExecuteReaderAsync(); ResultSet result = new ResultSet(reader); while (await reader.ReadAsync()) { ResultRow row = result.AddRow(reader); query.Row(row); } reader.Close(); return(result); } }
private static ResultSet CreateResultSet() { var res = new ResultSet("Int", "String", "DateTime", "Double"); res.AddRow(1, "String", DateTime.Today, 1.1); res.AddRow(2, "String2", DateTime.Today, 1.2); return res; }
public void Should_not_return_empty() { var res = new ResultSet("c1"); res.AddRow(1); Assert.IsFalse(res.IsEmpty); }