mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 17:23:52 -05:00
Export headers in an empty result set (#1434)
* Minimal changes to make headers appear on empty result sets * Columns for everyone! * Updating tests - some don't pass yet * Adding some more tests to verify the changes for column/row selection * null default columns * Updates to comments as per PR comments
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
// If: I attempt to save with a null set of params
|
||||
// Then: I should get a null argument exception
|
||||
ResultSet rs = new ResultSet(
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
MemoryFileSystem.GetFileStreamFactory());
|
||||
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
||||
null,
|
||||
@@ -41,7 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
// If: I attempt to save with a null set of params
|
||||
// Then: I should get a null argument exception
|
||||
ResultSet rs = new ResultSet(
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
MemoryFileSystem.GetFileStreamFactory());
|
||||
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
||||
new SaveResultsRequestParams(),
|
||||
@@ -54,11 +54,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
// If: I attempt to save a result set that hasn't completed execution
|
||||
// Then: I should get an invalid operation exception
|
||||
ResultSet rs = new ResultSet(
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
Common.Ordinal, Common.Ordinal,
|
||||
MemoryFileSystem.GetFileStreamFactory());
|
||||
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
||||
new SaveResultsRequestParams(),
|
||||
MemoryFileSystem.GetFileStreamFactory(),
|
||||
new SaveResultsRequestParams(),
|
||||
MemoryFileSystem.GetFileStreamFactory(),
|
||||
null, null));
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
// Then: I should get an invalid operation exception
|
||||
var requestParams = new SaveResultsRequestParams {FilePath = Constants.OwnerUri};
|
||||
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
||||
requestParams, GetMockFactory(GetMockWriter().Object, null),
|
||||
requestParams, GetMockFactory(GetMockWriter().Object, null),
|
||||
null, null));
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
// ... All the rows should have been written successfully
|
||||
saveWriter.Verify(
|
||||
w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IList<DbColumnWrapper>>()),
|
||||
w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IReadOnlyList<DbColumnWrapper>>()),
|
||||
Times.Exactly(Common.StandardRows));
|
||||
}
|
||||
|
||||
@@ -150,21 +150,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
// ... All the rows should have been written successfully
|
||||
saveWriter.Verify(
|
||||
w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IList<DbColumnWrapper>>()),
|
||||
w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IReadOnlyList<DbColumnWrapper>>()),
|
||||
Times.Exactly((int) (saveParams.RowEndIndex - saveParams.RowStartIndex + 1)));
|
||||
}
|
||||
|
||||
private static Mock<IFileStreamWriter> GetMockWriter()
|
||||
{
|
||||
var mockWriter = new Mock<IFileStreamWriter>();
|
||||
mockWriter.Setup(w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IList<DbColumnWrapper>>()));
|
||||
mockWriter.Setup(w => w.WriteRow(It.IsAny<IList<DbCellValue>>(), It.IsAny<IReadOnlyList<DbColumnWrapper>>()));
|
||||
return mockWriter;
|
||||
}
|
||||
|
||||
private static IFileStreamFactory GetMockFactory(IFileStreamWriter writer, Func<string, IFileStreamReader> readerGenerator)
|
||||
{
|
||||
var mockFactory = new Mock<IFileStreamFactory>();
|
||||
mockFactory.Setup(f => f.GetWriter(It.IsAny<string>()))
|
||||
mockFactory.Setup(f => f.GetWriter(It.IsAny<string>(), It.IsAny<IReadOnlyList<DbColumnWrapper>>()))
|
||||
.Returns(writer);
|
||||
mockFactory.Setup(f => f.GetReader(It.IsAny<string>()))
|
||||
.Returns(readerGenerator);
|
||||
|
||||
Reference in New Issue
Block a user