public void Build_OneElementWithArrayEmptyArray_RowsCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build( "[" + "{ \"name\":\"John\", \"hometown\": \"New York\", \"children\":" + "[{\"age\": 6}, {\"name\": \"Helen\", \"age\": 5}]" + ", \"job\": \"lawyer\" }" + ", { \"name\":\"Andrew\", \"hometown\": \"Chicago\" " + ", \"job\": \"engineer\" }" + "]" ); Assert.That(result.Rows, Has.Count.EqualTo(3)); Assert.That(result.Rows[0].ItemArray.Length, Is.EqualTo(5)); Assert.That(result.Rows[0].ItemArray[0], Is.EqualTo("John")); Assert.That(result.Rows[0].ItemArray[1], Is.EqualTo("New York")); Assert.That(result.Rows[0].ItemArray[2], Is.EqualTo(6)); Assert.That(result.Rows[0].ItemArray[3], Is.EqualTo(DBNull.Value)); Assert.That(result.Rows[0].ItemArray[4], Is.EqualTo("lawyer")); Assert.That(result.Rows[1].ItemArray[0], Is.EqualTo("John")); Assert.That(result.Rows[1].ItemArray[1], Is.EqualTo("New York")); Assert.That(result.Rows[1].ItemArray[2], Is.EqualTo(5)); Assert.That(result.Rows[1].ItemArray[3], Is.EqualTo("Helen")); Assert.That(result.Rows[1].ItemArray[4], Is.EqualTo("lawyer")); Assert.That(result.Rows[2].ItemArray[0], Is.EqualTo("Andrew")); Assert.That(result.Rows[2].ItemArray[1], Is.EqualTo("Chicago")); Assert.That(result.Rows[2].ItemArray[2], Is.EqualTo(DBNull.Value)); Assert.That(result.Rows[2].ItemArray[3], Is.EqualTo(DBNull.Value)); Assert.That(result.Rows[2].ItemArray[4], Is.EqualTo("engineer")); }
public void Build_TwoElementsOneattribute_ColumnCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\" }, { \"name\":\"Paul\" }]"); Assert.That(result.Columns, Has.Count.EqualTo(1)); Assert.That(result.Columns[0].ColumnName, Is.EqualTo("name")); }
public void Build_OneElementTwoattributes_ColumnsCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\", \"age\":31 }]"); Assert.That(result.Columns, Has.Count.EqualTo(2)); Assert.That(result.Columns[0].ColumnName, Is.EqualTo("name")); Assert.That(result.Columns[1].ColumnName, Is.EqualTo("age")); }
public void Build_OneElementOneattribute_RowCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\" }]"); Assert.That(result.Rows, Has.Count.EqualTo(1)); Assert.That(result.Rows[0].ItemArray.Length, Is.EqualTo(1)); Assert.That(result.Rows[0].ItemArray[0], Is.EqualTo("John")); }
public void Build_OneElementWithArray_ColumnsCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\", \"hometown\":\"New York\", \"children\":[{\"name\": \"Mike\", \"age\": \"6\"}, {\"name\": \"Helen\", \"age\": \"6\"}] }]"); Assert.That(result.Columns, Has.Count.EqualTo(4)); Assert.That(result.Columns[0].ColumnName, Is.EqualTo("name")); Assert.That(result.Columns[1].ColumnName, Is.EqualTo("hometown")); Assert.That(result.Columns[2].ColumnName, Is.EqualTo("children.name")); Assert.That(result.Columns[3].ColumnName, Is.EqualTo("children.age")); }
public void Build_OneElementWithArrayAndPostElementAndMissingAttribute_ColumnsCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\", \"hometown\":\"New York\", \"children\":[{\"age\": \"6\"}, {\"name\": \"Helen\", \"age\": \"6\"}], \"job\": \"lawyer\" }]"); Assert.That(result.Columns, Has.Count.EqualTo(5)); Assert.That(result.Columns[0].ColumnName, Is.EqualTo("name")); Assert.That(result.Columns[1].ColumnName, Is.EqualTo("hometown")); Assert.That(result.Columns[2].ColumnName, Is.EqualTo("children.age").Or.EqualTo("children.name")); Assert.That(result.Columns[3].ColumnName, Is.EqualTo("children.name").Or.EqualTo("children.age")); Assert.That(result.Columns[4].ColumnName, Is.EqualTo("job")); }
public void Build_EmptyDocument_EmptyResultSet() { var builder = new JsonResultSet(); var json = "[" + "{ \"name\":\"John\", \"hometown\": \"New York\", \"children\":" + "[{\"age\": 6}, {\"name\": \"Helen\", \"age\": 5}]" + ", \"job\": \"lawyer\" " + ", \"dishes\": [{ \"name\":\"pasta\"}, {\"name\": \"chicken\"}] " + "}" + "]"; Assert.Throws <InvalidOperationException>(() => builder.Build(json)); }
public void Build_OneElementWithArray_RowsCorrectlyReturned() { var builder = new JsonResultSet(); var result = builder.Build("[{ \"name\":\"John\", \"age\":31, \"children\":[{\"name\": \"Mike\"}, {\"name\": \"Helen\"}] }]"); Assert.That(result.Rows, Has.Count.EqualTo(2)); Assert.That(result.Rows[0].ItemArray.Length, Is.EqualTo(3)); Assert.That(result.Rows[0].ItemArray[0], Is.EqualTo("John")); Assert.That(result.Rows[0].ItemArray[1], Is.EqualTo(31)); Assert.That(result.Rows[0].ItemArray[2], Is.EqualTo("Mike")); Assert.That(result.Rows[1].ItemArray[0], Is.EqualTo("John")); Assert.That(result.Rows[1].ItemArray[1], Is.EqualTo(31)); Assert.That(result.Rows[1].ItemArray[2], Is.EqualTo("Helen")); }
public ICorrectness TestQuery <TResult>(Func <TObjectContext, TResult> queryFactory, string expectedResultJson, bool strictOrder = false) { IResultSet expectedResult = null; IResultSet actualResult = null; // If no expected result was specified, execute on the database if (string.IsNullOrEmpty(expectedResultJson)) { expectedResult = CreateExpectedResult(queryFactory); actualResult = new JsonResultSet("[]"); } else { expectedResult = new JsonResultSet(expectedResultJson); actualResult = this.GetResultSet( CreateInspectedFakeConnection, ctx => queryFactory(ctx)); } return(new Correctness(expectedResult, actualResult, strictOrder)); }