mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 09:35:38 -05:00
Remove SELECT * from edit/initialize Query (#288)
* Major refactor of EditDataMetadata providers * EditMetadataFactory generates "basic" EditTableMetadata objects based entirely on SMO metadata * SmoEditTableMetadata no longer depends on SMO, making it unecessary to mock it * Renamed SmoEditTableMetadata to EditTableMetadata * EditTableMetadata can be extended with DbColumnWrappers * Moving logic for extending a EditColumnMetadata into that class * I *think* this will work for async execution of initialize tasks * Fixing unit tests for new Edit(Table|Column)Metadata classes * Async stuff that works! And passes unit tests * Adding unit tests Adding .idea to gitignore * Adding message to the EditSessionReadyEvent * Fixes from dev merge * Fixing unit tests that Rider didn't catch as failing May have been a bit heavy-handed with the async/await stuff * Couple changes as per PR comments
This commit is contained in:
@@ -7,13 +7,13 @@ using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
@@ -22,18 +22,49 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public const string OwnerUri = "testFile";
|
||||
|
||||
public static IEditTableMetadata GetStandardMetadata(DbColumn[] columns, bool allKeys = true, bool isMemoryOptimized = false)
|
||||
public static async Task<EditSession> GetCustomSession(Query q, EditTableMetadata etm)
|
||||
{
|
||||
// Create a Column Metadata Provider
|
||||
// Mock metadata factory
|
||||
Mock<IEditMetadataFactory> metaFactory = new Mock<IEditMetadataFactory>();
|
||||
metaFactory
|
||||
.Setup(f => f.GetObjectMetadata(It.IsAny<DbConnection>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(etm);
|
||||
|
||||
EditSession session = new EditSession(metaFactory.Object, "tbl", "tbl");
|
||||
|
||||
EditSession.Connector connector = () => Task.FromResult<DbConnection>(null);
|
||||
EditSession.QueryRunner queryRunner = (s) => Task.FromResult(new EditSession.EditSessionQueryExecutionState(q));
|
||||
|
||||
session.Initialize(connector, queryRunner, () => Task.FromResult(0), (e) => Task.FromResult(0));
|
||||
await session.InitializeTask;
|
||||
return session;
|
||||
}
|
||||
|
||||
public static EditTableMetadata GetStandardMetadata(DbColumn[] columns, bool isMemoryOptimized = false)
|
||||
{
|
||||
// Create column metadata providers
|
||||
var columnMetas = columns.Select((c, i) =>
|
||||
new EditColumnWrapper
|
||||
{
|
||||
var ecm = new EditColumnMetadata
|
||||
{
|
||||
DbColumn = new DbColumnWrapper(c),
|
||||
EscapedName = c.ColumnName,
|
||||
Ordinal = i,
|
||||
IsKey = c.IsIdentity.HasTrue()
|
||||
}).ToArray();
|
||||
return GetMetadataProvider(columnMetas, allKeys, isMemoryOptimized);
|
||||
Ordinal = i
|
||||
};
|
||||
return ecm;
|
||||
}).ToArray();
|
||||
|
||||
// Create column wrappers
|
||||
var columnWrappers = columns.Select(c => new DbColumnWrapper(c)).ToArray();
|
||||
|
||||
// Create the table metadata
|
||||
EditTableMetadata editTableMetadata = new EditTableMetadata
|
||||
{
|
||||
Columns = columnMetas,
|
||||
EscapedMultipartName = "tbl",
|
||||
IsMemoryOptimized = isMemoryOptimized
|
||||
};
|
||||
editTableMetadata.Extend(columnWrappers);
|
||||
return editTableMetadata;
|
||||
}
|
||||
|
||||
public static DbColumn[] GetColumns(bool includeIdentity)
|
||||
@@ -42,7 +73,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
if (includeIdentity)
|
||||
{
|
||||
columns.Add(new TestDbColumn("id", true));
|
||||
columns.Add(new TestDbColumn("id") {IsKey = true, IsIdentity = true, IsAutoIncrement = true});
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
@@ -52,7 +83,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
return columns.ToArray();
|
||||
}
|
||||
|
||||
public static ResultSet GetResultSet(DbColumn[] columns, bool includeIdentity, int rowCount = 1)
|
||||
public static async Task<Query> GetQuery(DbColumn[] columns, bool includIdentity, int rowCount = 1)
|
||||
{
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
q.Batches[0].ResultSets[0] = await GetResultSet(columns, includIdentity, rowCount);
|
||||
return q;
|
||||
}
|
||||
|
||||
public static async Task<ResultSet> GetResultSet(DbColumn[] columns, bool includeIdentity, int rowCount = 1)
|
||||
{
|
||||
IEnumerable<object[]> rows = includeIdentity
|
||||
? Enumerable.Repeat(new object[] { "id", "1", "2", "3" }, rowCount)
|
||||
@@ -60,7 +98,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
var testResultSet = new TestResultSet(columns, rows);
|
||||
var reader = new TestDbDataReader(new[] { testResultSet });
|
||||
var resultSet = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory());
|
||||
resultSet.ReadResultToEnd(reader, CancellationToken.None).Wait();
|
||||
await resultSet.ReadResultToEnd(reader, CancellationToken.None);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
@@ -82,26 +120,5 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rc.SetCell(i, "123");
|
||||
}
|
||||
}
|
||||
|
||||
public static IEditTableMetadata GetMetadataProvider(EditColumnWrapper[] columnMetas, bool allKeys = false, bool isMemoryOptimized = false)
|
||||
{
|
||||
// Create a table metadata provider
|
||||
var tableMetaMock = new Mock<IEditTableMetadata>();
|
||||
if (allKeys)
|
||||
{
|
||||
// All columns should be returned as "keys"
|
||||
tableMetaMock.Setup(m => m.KeyColumns).Returns(columnMetas);
|
||||
}
|
||||
else
|
||||
{
|
||||
// All identity columns should be returned as keys
|
||||
tableMetaMock.Setup(m => m.KeyColumns).Returns(columnMetas.Where(c => c.DbColumn.IsIdentity.HasTrue()).ToList());
|
||||
}
|
||||
tableMetaMock.Setup(m => m.Columns).Returns(columnMetas);
|
||||
tableMetaMock.Setup(m => m.IsMemoryOptimized).Returns(isMemoryOptimized);
|
||||
tableMetaMock.Setup(m => m.EscapedMultipartName).Returns("tbl");
|
||||
|
||||
return tableMetaMock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
public class RowCreateTests
|
||||
{
|
||||
[Fact]
|
||||
public void RowCreateConstruction()
|
||||
public async Task RowCreateConstruction()
|
||||
{
|
||||
// Setup: Create the values to store
|
||||
const long rowId = 100;
|
||||
DbColumn[] columns = Common.GetColumns(false);
|
||||
ResultSet rs = Common.GetResultSet(columns, false);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
ResultSet rs = await Common.GetResultSet(columns, false);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
|
||||
// If: I create a RowCreate instance
|
||||
RowCreate rc = new RowCreate(rowId, rs, etm);
|
||||
@@ -42,13 +42,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void GetScript(bool includeIdentity)
|
||||
public async Task GetScript(bool includeIdentity)
|
||||
{
|
||||
// Setup: Generate the parameters for the row create
|
||||
const long rowId = 100;
|
||||
DbColumn[] columns = Common.GetColumns(includeIdentity);
|
||||
ResultSet rs = Common.GetResultSet(columns, includeIdentity);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
ResultSet rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
|
||||
// If: I ask for a script to be generated without an identity column
|
||||
RowCreate rc = new RowCreate(rowId, rs, etm);
|
||||
@@ -74,10 +74,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetScriptMissingCell()
|
||||
public async Task GetScriptMissingCell()
|
||||
{
|
||||
// Setup: Generate the parameters for the row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I ask for a script to be generated without setting any values
|
||||
// Then: An exception should be thrown for missing cells
|
||||
@@ -93,8 +93,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... Generate the parameters for the row create
|
||||
const long rowId = 100;
|
||||
DbColumn[] columns = Common.GetColumns(includeIdentity);
|
||||
ResultSet rs = Common.GetResultSet(columns, includeIdentity);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
ResultSet rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
|
||||
// ... Setup a db reader for the result of an insert
|
||||
var newRowReader = Common.GetNewRowDataReader(columns, includeIdentity);
|
||||
@@ -110,13 +110,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void GetCommand(bool includeIdentity)
|
||||
public async Task GetCommand(bool includeIdentity)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row create with cell updates
|
||||
const long rowId = 100;
|
||||
var columns = Common.GetColumns(includeIdentity);
|
||||
var rs = Common.GetResultSet(columns, includeIdentity);
|
||||
var rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowCreate rc = new RowCreate(rowId, rs, etm);
|
||||
Common.AddCells(rc, includeIdentity);
|
||||
@@ -159,10 +159,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCommandNullConnection()
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
|
||||
// If: I attempt to create a command with a null connection
|
||||
@@ -171,10 +171,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCommandMissingCell()
|
||||
public async Task GetCommandMissingCell()
|
||||
{
|
||||
// Setup: Generate the parameters for the row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
var mockConn = new TestSqlConnection(null);
|
||||
|
||||
// If: I ask for a script to be generated without setting any values
|
||||
@@ -183,10 +183,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditRowNoAdditions()
|
||||
public async Task GetEditRowNoAdditions()
|
||||
{
|
||||
// Setup: Generate a standard row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I request an edit row from the row create
|
||||
EditRow er = rc.GetEditRow(null);
|
||||
@@ -209,10 +209,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditRowWithAdditions()
|
||||
public async Task GetEditRowWithAdditions()
|
||||
{
|
||||
// Setp: Generate a row create with a cell added to it
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
rc.SetCell(0, "foo");
|
||||
|
||||
// If: I request an edit row from the row create
|
||||
@@ -244,20 +244,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public void SetCellOutOfRange(int columnId)
|
||||
public async Task SetCellOutOfRange(int columnId)
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I attempt to set a cell on a column that is out of range, I should get an exception
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => rc.SetCell(columnId, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCellNoChange()
|
||||
public async Task SetCellNoChange()
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I set a cell in the newly created row to something that doesn't need changing
|
||||
EditUpdateCellResult eucr = rc.SetCell(0, "1");
|
||||
@@ -278,16 +278,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCellHasCorrections()
|
||||
public async Task SetCellHasCorrections()
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate a result set with a single binary column
|
||||
DbColumn[] cols = {new TestDbColumn("bin", "binary", typeof(byte[]))};
|
||||
DbColumn[] cols = {new TestDbColumn
|
||||
{
|
||||
DataType = typeof(byte[]),
|
||||
DataTypeName = "binary"
|
||||
}};
|
||||
object[][] rows = {};
|
||||
var testResultSet = new TestResultSet(cols, rows);
|
||||
var testReader = new TestDbDataReader(new[] {testResultSet});
|
||||
var rs = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory());
|
||||
rs.ReadResultToEnd(testReader, CancellationToken.None).Wait();
|
||||
await rs.ReadResultToEnd(testReader, CancellationToken.None);
|
||||
|
||||
// ... Generate the metadata
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
@@ -314,10 +318,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCellNull()
|
||||
public async Task SetCellNull()
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I set a cell in the newly created row to null
|
||||
EditUpdateCellResult eucr = rc.SetCell(0, "NULL");
|
||||
@@ -341,10 +345,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public void RevertCellOutOfRange(int columnId)
|
||||
public async Task RevertCellOutOfRange(int columnId)
|
||||
{
|
||||
// Setup: Generate the row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I attempt to revert a cell that is out of range
|
||||
// Then: I should get an exception
|
||||
@@ -352,10 +356,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertCellNotSet()
|
||||
public async Task RevertCellNotSet()
|
||||
{
|
||||
// Setup: Generate the row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
|
||||
// If: I attempt to revert a cell that has not been set
|
||||
string result = rc.RevertCell(0);
|
||||
@@ -369,10 +373,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertCellThatWasSet()
|
||||
public async Task RevertCellThatWasSet()
|
||||
{
|
||||
// Setup: Generate the row create
|
||||
RowCreate rc = GetStandardRowCreate();
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
rc.SetCell(0, "1");
|
||||
|
||||
// If: I attempt to revert a cell that was set
|
||||
@@ -386,10 +390,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Null(rc.newCells[0]);
|
||||
}
|
||||
|
||||
private static RowCreate GetStandardRowCreate()
|
||||
private static async Task<RowCreate> GetStandardRowCreate()
|
||||
{
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false);
|
||||
var rs = await Common.GetResultSet(cols, false);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
return new RowCreate(100, rs, etm);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
public class RowDeleteTests
|
||||
{
|
||||
[Fact]
|
||||
public void RowDeleteConstruction()
|
||||
public async Task RowDeleteConstruction()
|
||||
{
|
||||
// Setup: Create the values to store
|
||||
DbColumn[] columns = Common.GetColumns(true);
|
||||
ResultSet rs = Common.GetResultSet(columns, true);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns, false);
|
||||
ResultSet rs = await Common.GetResultSet(columns, true);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
|
||||
// If: I create a RowCreate instance
|
||||
RowDelete rc = new RowDelete(100, rs, etm);
|
||||
@@ -40,11 +40,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void GetScriptTest(bool isMemoryOptimized)
|
||||
public async Task GetScriptTest(bool isMemoryOptimized)
|
||||
{
|
||||
DbColumn[] columns = Common.GetColumns(true);
|
||||
ResultSet rs = Common.GetResultSet(columns, true);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns, false, isMemoryOptimized);
|
||||
ResultSet rs = await Common.GetResultSet(columns, true);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns, isMemoryOptimized);
|
||||
|
||||
// If: I ask for a script to be generated for delete
|
||||
RowDelete rd = new RowDelete(0, rs, etm);
|
||||
@@ -68,7 +68,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Generate the parameters for the row delete object
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
|
||||
// If: I ask for the change to be applied
|
||||
@@ -84,13 +84,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, false)]
|
||||
public void GetCommand(bool includeIdentity, bool isMemoryOptimized)
|
||||
public async Task GetCommand(bool includeIdentity, bool isMemoryOptimized)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row delete
|
||||
var columns = Common.GetColumns(includeIdentity);
|
||||
var rs = Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns, !includeIdentity, isMemoryOptimized);
|
||||
var rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns, isMemoryOptimized);
|
||||
RowDelete rd = new RowDelete(0, rs, etm);
|
||||
|
||||
// ... Mock db connection for building the command
|
||||
@@ -128,10 +128,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCommandNullConnection()
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
RowDelete rd = GetStandardRowDelete();
|
||||
RowDelete rd = await GetStandardRowDelete();
|
||||
|
||||
// If: I attempt to create a command with a null connection
|
||||
// Then: It should throw an exception
|
||||
@@ -139,11 +139,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditRow()
|
||||
public async Task GetEditRow()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowDelete rd = new RowDelete(0, rs, etm);
|
||||
|
||||
@@ -173,10 +173,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditNullRow()
|
||||
public async Task GetEditNullRow()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
RowDelete rd = GetStandardRowDelete();
|
||||
RowDelete rd = await GetStandardRowDelete();
|
||||
|
||||
// If: I attempt to get an edit row with a null cached row
|
||||
// Then: I should get an exception
|
||||
@@ -184,10 +184,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCell()
|
||||
public async Task SetCell()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
RowDelete rd = GetStandardRowDelete();
|
||||
RowDelete rd = await GetStandardRowDelete();
|
||||
|
||||
// If: I set a cell on a delete row edit
|
||||
// Then: It should throw as invalid operation
|
||||
@@ -195,20 +195,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertCell()
|
||||
public async Task RevertCell()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
RowDelete rd = GetStandardRowDelete();
|
||||
RowDelete rd = await GetStandardRowDelete();
|
||||
|
||||
// If: I revert a cell on a delete row edit
|
||||
// Then: It should throw
|
||||
Assert.Throws<InvalidOperationException>(() => rd.RevertCell(0));
|
||||
}
|
||||
|
||||
private RowDelete GetStandardRowDelete()
|
||||
private async Task<RowDelete> GetStandardRowDelete()
|
||||
{
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false);
|
||||
var rs = await Common.GetResultSet(cols, false);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
return new RowDelete(0, rs, etm);
|
||||
}
|
||||
|
||||
@@ -25,12 +25,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative index
|
||||
[InlineData(2)] // Equal to count of columns
|
||||
[InlineData(100)] // Index larger than number of columns
|
||||
public void ValidateUpdatableColumnOutOfRange(int columnId)
|
||||
public async Task ValidateUpdatableColumnOutOfRange(int columnId)
|
||||
{
|
||||
// Setup: Create a result set
|
||||
ResultSet rs = GetResultSet(
|
||||
new DbColumn[] { new TestDbColumn("id", true), new TestDbColumn("col1")},
|
||||
ResultSet rs = await GetResultSet(
|
||||
new DbColumn[] {
|
||||
new TestDbColumn("id") {IsKey = true, IsAutoIncrement = true, IsIdentity = true},
|
||||
new TestDbColumn("col1")
|
||||
},
|
||||
new object[] { "id", "1" });
|
||||
|
||||
// If: I validate a column ID that is out of range
|
||||
@@ -40,11 +44,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateUpdatableColumnNotUpdatable()
|
||||
public async Task ValidateUpdatableColumnNotUpdatable()
|
||||
{
|
||||
// Setup: Create a result set with an identity column
|
||||
ResultSet rs = GetResultSet(
|
||||
new DbColumn[] { new TestDbColumn("id", true), new TestDbColumn("col1") },
|
||||
ResultSet rs = await GetResultSet(
|
||||
new DbColumn[] {
|
||||
new TestDbColumn("id") {IsKey = true, IsAutoIncrement = true, IsIdentity = true},
|
||||
new TestDbColumn("col1")
|
||||
},
|
||||
new object[] { "id", "1" });
|
||||
|
||||
// If: I validate a column ID that is not updatable
|
||||
@@ -55,12 +62,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetWhereClauseIsNotNullData))]
|
||||
public void GetWhereClauseSimple(DbColumn col, object val, string nullClause)
|
||||
public async Task GetWhereClauseSimple(DbColumn col, object val, string nullClause)
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with a single column
|
||||
var cols = new[] {col};
|
||||
ResultSet rs = GetResultSet(cols, new[] {val});
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(cols);
|
||||
ResultSet rs = await GetResultSet(cols, new[] {val});
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
RowEditTester rt = new RowEditTester(rs, etm);
|
||||
rt.ValidateWhereClauseSingleKey(nullClause);
|
||||
@@ -71,42 +78,69 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
get
|
||||
{
|
||||
yield return new object[] {new TestDbColumn("col"), DBNull.Value, "IS NULL"};
|
||||
yield return new object[] {new TestDbColumn("col", "VARBINARY", typeof(byte[])), new byte[5], "IS NOT NULL"};
|
||||
yield return new object[] {new TestDbColumn("col", "TEXT", typeof(string)), "abc", "IS NOT NULL"};
|
||||
yield return new object[] {new TestDbColumn("col", "NTEXT", typeof(string)), "abc", "IS NOT NULL"};
|
||||
yield return new object[] {
|
||||
new TestDbColumn
|
||||
{
|
||||
DataTypeName = "BINARY",
|
||||
DataType = typeof(byte[])
|
||||
},
|
||||
new byte[5],
|
||||
"IS NOT NULL"
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new TestDbColumn
|
||||
{
|
||||
DataType = typeof(string),
|
||||
DataTypeName = "TEXT"
|
||||
},
|
||||
"abc",
|
||||
"IS NOT NULL"
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new TestDbColumn
|
||||
{
|
||||
DataType = typeof(string),
|
||||
DataTypeName = "NTEXT",
|
||||
|
||||
},
|
||||
"abc",
|
||||
"IS NOT NULL"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWhereClauseMultipleKeyColumns()
|
||||
public async Task GetWhereClauseMultipleKeyColumns()
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with multiple key columns
|
||||
DbColumn[] cols = {new TestDbColumn("col1"), new TestDbColumn("col2")};
|
||||
ResultSet rs = GetResultSet(cols, new object[] {"abc", "def"});
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(cols);
|
||||
ResultSet rs = await GetResultSet(cols, new object[] {"abc", "def"});
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
RowEditTester rt = new RowEditTester(rs, etm);
|
||||
rt.ValidateWhereClauseMultipleKeys();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWhereClauseNoKeyColumns()
|
||||
public async Task GetWhereClauseNoKeyColumns()
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with no key columns
|
||||
DbColumn[] cols = {new TestDbColumn("col1"), new TestDbColumn("col2")};
|
||||
ResultSet rs = GetResultSet(cols, new object[] {"abc", "def"});
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(new DbColumn[] {});
|
||||
ResultSet rs = await GetResultSet(cols, new object[] {"abc", "def"});
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(new DbColumn[] {});
|
||||
|
||||
RowEditTester rt = new RowEditTester(rs, etm);
|
||||
rt.ValidateWhereClauseNoKeys();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SortingByTypeTest()
|
||||
public async Task SortingByTypeTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false);
|
||||
var rs = await Common.GetResultSet(cols, false);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
// If: I request to sort a list of the three different edit operations
|
||||
@@ -124,11 +158,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SortingUpdatesByRowIdTest()
|
||||
public async Task SortingUpdatesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false, 4);
|
||||
var rs = await Common.GetResultSet(cols, false, 4);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
// If: I sort 3 edit operations of the same type
|
||||
@@ -147,11 +181,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SortingCreatesByRowIdTest()
|
||||
public async Task SortingCreatesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false);
|
||||
var rs = await Common.GetResultSet(cols, false);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
// If: I sort 3 edit operations of the same type
|
||||
@@ -170,11 +204,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SortingDeletesByRowIdTest()
|
||||
public async Task SortingDeletesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
var cols = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(cols, false);
|
||||
var rs = await Common.GetResultSet(cols, false);
|
||||
var etm = Common.GetStandardMetadata(cols);
|
||||
|
||||
// If: I sort 3 delete operations of the same type
|
||||
@@ -192,19 +226,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Equal(1, rowEdits[2].RowId);
|
||||
}
|
||||
|
||||
private static ResultSet GetResultSet(DbColumn[] columns, object[] row)
|
||||
private static async Task<ResultSet> GetResultSet(DbColumn[] columns, object[] row)
|
||||
{
|
||||
object[][] rows = {row};
|
||||
var testResultSet = new TestResultSet(columns, rows);
|
||||
var testReader = new TestDbDataReader(new [] {testResultSet});
|
||||
var resultSet = new ResultSet(0,0, MemoryFileSystem.GetFileStreamFactory());
|
||||
resultSet.ReadResultToEnd(testReader, CancellationToken.None).Wait();
|
||||
await resultSet.ReadResultToEnd(testReader, CancellationToken.None);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
private class RowEditTester : RowEditBase
|
||||
{
|
||||
public RowEditTester(ResultSet rs, IEditTableMetadata meta) : base(0, rs, meta) { }
|
||||
public RowEditTester(ResultSet rs, EditTableMetadata meta) : base(0, rs, meta) { }
|
||||
|
||||
public void ValidateColumn(int columnId)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Setup: Create the values to store
|
||||
const long rowId = 0;
|
||||
ResultSet rs = QueryExecution.Common.GetBasicExecutedBatch().ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
|
||||
// If: I create a RowUpdate instance
|
||||
RowUpdate rc = new RowUpdate(rowId, rs, etm);
|
||||
@@ -40,10 +40,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCell()
|
||||
public async Task SetCell()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
RowUpdate ru = GetStandardRowUpdate();
|
||||
RowUpdate ru = await GetStandardRowUpdate();
|
||||
|
||||
// If: I set a cell that can be updated
|
||||
EditUpdateCellResult eucr = ru.SetCell(0, "col1");
|
||||
@@ -69,7 +69,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate a result set with a single binary column
|
||||
DbColumn[] cols = { new TestDbColumn("bin", "binary", typeof(byte[])) };
|
||||
DbColumn[] cols =
|
||||
{
|
||||
new TestDbColumn
|
||||
{
|
||||
DataType = typeof(byte[]),
|
||||
DataTypeName = "binary"
|
||||
}
|
||||
};
|
||||
object[][] rows = { new object[]{new byte[] {0x00}}};
|
||||
var testResultSet = new TestResultSet(cols, rows);
|
||||
var testReader = new TestDbDataReader(new[] { testResultSet });
|
||||
@@ -102,12 +109,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCellImplicitRevertTest()
|
||||
public async Task SetCellImplicitRevertTest()
|
||||
{
|
||||
// Setup: Create a fake table to update
|
||||
DbColumn[] columns = Common.GetColumns(true);
|
||||
ResultSet rs = Common.GetResultSet(columns, true);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
ResultSet rs = await Common.GetResultSet(columns, true);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns);
|
||||
|
||||
// If:
|
||||
// ... I add updates to all the cells in the row
|
||||
@@ -139,12 +146,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void GetScriptTest(bool isMemoryOptimized)
|
||||
public async Task GetScriptTest(bool isMemoryOptimized)
|
||||
{
|
||||
// Setup: Create a fake table to update
|
||||
DbColumn[] columns = Common.GetColumns(true);
|
||||
ResultSet rs = Common.GetResultSet(columns, true);
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(columns, false, isMemoryOptimized);
|
||||
ResultSet rs = await Common.GetResultSet(columns, true);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(columns, isMemoryOptimized);
|
||||
|
||||
// If: I ask for a script to be generated for update
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
@@ -177,13 +184,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(false, false)]
|
||||
public void GetCommand(bool includeIdentity, bool isMemoryOptimized)
|
||||
public async Task GetCommand(bool includeIdentity, bool isMemoryOptimized)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update with cell updates
|
||||
var columns = Common.GetColumns(includeIdentity);
|
||||
var rs = Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns, !includeIdentity, isMemoryOptimized);
|
||||
var rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns, isMemoryOptimized);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
Common.AddCells(ru, includeIdentity);
|
||||
|
||||
@@ -231,10 +238,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCommandNullConnection()
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
RowUpdate ru = GetStandardRowUpdate();
|
||||
RowUpdate ru = await GetStandardRowUpdate();
|
||||
|
||||
// If: I attempt to create a command with a null connection
|
||||
// Then: It should throw an exception
|
||||
@@ -242,11 +249,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditRow()
|
||||
public async Task GetEditRow()
|
||||
{
|
||||
// Setup: Create a row update with a cell set
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
ru.SetCell(0, "foo");
|
||||
@@ -282,10 +289,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEditNullRow()
|
||||
public async Task GetEditNullRow()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
RowUpdate ru = GetStandardRowUpdate();
|
||||
RowUpdate ru = await GetStandardRowUpdate();
|
||||
|
||||
// If: I attempt to get an edit row with a null cached row
|
||||
// Then: I should get an exception
|
||||
@@ -300,8 +307,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
var columns = Common.GetColumns(includeIdentity);
|
||||
var rs = Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns, !includeIdentity);
|
||||
var rs = await Common.GetResultSet(columns, includeIdentity);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
long oldBytesWritten = rs.totalBytesWritten;
|
||||
|
||||
@@ -323,8 +330,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
var columns = Common.GetColumns(true);
|
||||
var rs = Common.GetResultSet(columns, true);
|
||||
var etm = Common.GetStandardMetadata(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, true);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
|
||||
// If: I ask for the changes to be applied with a null db reader
|
||||
@@ -336,12 +343,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public void RevertCellOutOfRange(int columnId)
|
||||
public async Task RevertCellOutOfRange(int columnId)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
|
||||
@@ -351,12 +358,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertCellNotSet()
|
||||
public async Task RevertCellNotSet()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
var columns = Common.GetColumns(true);
|
||||
var rs = Common.GetResultSet(columns, true);
|
||||
var rs = await Common.GetResultSet(columns, true);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
|
||||
@@ -371,12 +378,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertCellThatWasSet()
|
||||
public async Task RevertCellThatWasSet()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
RowUpdate ru = new RowUpdate(0, rs, etm);
|
||||
ru.SetCell(0, "1");
|
||||
@@ -392,10 +399,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.DoesNotContain(0, ru.cellUpdates.Keys);
|
||||
}
|
||||
|
||||
private RowUpdate GetStandardRowUpdate()
|
||||
private async Task<RowUpdate> GetStandardRowUpdate()
|
||||
{
|
||||
var columns = Common.GetColumns(false);
|
||||
var rs = Common.GetResultSet(columns, false);
|
||||
var rs = await Common.GetResultSet(columns, false);
|
||||
var etm = Common.GetStandardMetadata(columns);
|
||||
return new RowUpdate(0, rs, etm);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Setup:
|
||||
// ... Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
eds.ActiveSessions[Common.OwnerUri] = GetDefaultSession();
|
||||
eds.ActiveSessions[Common.OwnerUri] = await GetDefaultSession();
|
||||
|
||||
// ... Create a session param that returns the common owner uri
|
||||
var mockParams = new EditCreateRowParams { OwnerUri = Common.OwnerUri };
|
||||
@@ -94,7 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
eds.ActiveSessions[Common.OwnerUri] = GetDefaultSession();
|
||||
eds.ActiveSessions[Common.OwnerUri] = await GetDefaultSession();
|
||||
|
||||
// If: I ask to dispose of an existing session
|
||||
var efv = new EventFlowValidator<EditDisposeResult>()
|
||||
@@ -117,7 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
eds.ActiveSessions[Constants.OwnerUri] = GetDefaultSession();
|
||||
eds.ActiveSessions[Constants.OwnerUri] = await GetDefaultSession();
|
||||
|
||||
// If: I validly ask to delete a row
|
||||
var efv = new EventFlowValidator<EditDeleteRowResult>()
|
||||
@@ -139,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
eds.ActiveSessions[Constants.OwnerUri] = GetDefaultSession();
|
||||
eds.ActiveSessions[Constants.OwnerUri] = await GetDefaultSession();
|
||||
|
||||
// If: I ask to create a row from a non existant session
|
||||
var efv = new EventFlowValidator<EditCreateRowResult>()
|
||||
@@ -161,7 +161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Create an edit data service with a session that has an pending edit
|
||||
var eds = new EditDataService(null, null, null);
|
||||
var session = GetDefaultSession();
|
||||
var session = await GetDefaultSession();
|
||||
session.EditCache[0] = new Mock<RowEditBase>().Object;
|
||||
eds.ActiveSessions[Constants.OwnerUri] = session;
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
var session = GetDefaultSession();
|
||||
var session = await GetDefaultSession();
|
||||
eds.ActiveSessions[Constants.OwnerUri] = session;
|
||||
var edit = new Mock<RowEditBase>();
|
||||
edit.Setup(e => e.SetCell(It.IsAny<int>(), It.IsAny<string>())).Returns(new EditUpdateCellResult
|
||||
@@ -223,7 +223,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Setup: Create an edit data service with a session
|
||||
// Setup: Create an edit data service with a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
var session = GetDefaultSession();
|
||||
var session = await GetDefaultSession();
|
||||
eds.ActiveSessions[Constants.OwnerUri] = session;
|
||||
|
||||
// If: I validly ask for rows
|
||||
@@ -277,119 +277,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... There should not be a session
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
|
||||
// ... There should not be a wait handler
|
||||
Assert.Empty(eds.InitializeWaitHandles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeInProgress()
|
||||
{
|
||||
// Setup: Create an edit data service with an "in-progress initialize"
|
||||
var eds = new EditDataService(null, null, null);
|
||||
eds.InitializeWaitHandles[Common.OwnerUri] = new TaskCompletionSource<bool>();
|
||||
|
||||
// If:
|
||||
// ... I ask to initialize a session when an initialize task is already in progress
|
||||
var initParams = new EditInitializeParams
|
||||
{
|
||||
ObjectName = "table",
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ObjectType = "table"
|
||||
};
|
||||
var efv = new EventFlowValidator<EditInitializeResult>()
|
||||
.AddErrorValidation<string>(Assert.NotNull)
|
||||
.Complete();
|
||||
await eds.HandleInitializeRequest(initParams, efv.Object);
|
||||
|
||||
// Then:
|
||||
// ... An error event should have been raised
|
||||
efv.Validate();
|
||||
|
||||
// ... There should not be a session
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeQueryCreateFailed()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a query execution service that will throw on creation of the query
|
||||
var qes = QueryExecution.Common.GetPrimedExecutionService(null, false, false, null);
|
||||
|
||||
// ... Create an edit data service that uses the mocked up query service
|
||||
var eds = new EditDataService(qes, null, null);
|
||||
|
||||
// If:
|
||||
// ... I initialize a session
|
||||
var initParams = new EditInitializeParams
|
||||
{
|
||||
ObjectName = "table",
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ObjectType = "table"
|
||||
};
|
||||
var efv = new EventFlowValidator<EditInitializeResult>()
|
||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||
.Complete();
|
||||
await eds.HandleInitializeRequest(initParams, efv.Object);
|
||||
|
||||
// Then:
|
||||
// ... We should have gotten an error back
|
||||
efv.Validate();
|
||||
|
||||
// ... There should not be any sessions created
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
|
||||
// ... There should not be a wait handle
|
||||
Assert.Empty(eds.InitializeWaitHandles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeQueryExecutionFails()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a query execution service that will throw on execution of the query
|
||||
var qes = QueryExecution.Common.GetPrimedExecutionService(null, true, true, null);
|
||||
|
||||
// ... Create an edit data service that uses the mocked up query service
|
||||
var eds = new EditDataService(qes, null, null);
|
||||
|
||||
// If:
|
||||
// ... I initialize a session
|
||||
var initParams = new EditInitializeParams
|
||||
{
|
||||
ObjectName = "table",
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ObjectType = "table"
|
||||
};
|
||||
var efv = new EventFlowValidator<EditInitializeResult>()
|
||||
.AddResultValidation(Assert.NotNull)
|
||||
.AddEventValidation(EditSessionReadyEvent.Type, esrp =>
|
||||
{
|
||||
Assert.NotNull(esrp);
|
||||
Assert.False(esrp.Success);
|
||||
}).Complete();
|
||||
await eds.HandleInitializeRequest(initParams, efv.Object);
|
||||
await eds.InitializeWaitHandles[Common.OwnerUri].Task;
|
||||
|
||||
// Then:
|
||||
// ... We should have started execution, but failed
|
||||
efv.Validate();
|
||||
|
||||
// ... There should not be any sessions created
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
|
||||
// ... There should not be a wait handle. It should have been cleaned up by now
|
||||
Assert.Empty(eds.InitializeWaitHandles);
|
||||
}
|
||||
|
||||
private static EditSession GetDefaultSession()
|
||||
private static async Task<EditSession> GetDefaultSession()
|
||||
{
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = await Common.GetCustomSession(q, etm);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,40 +28,55 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region Construction Tests
|
||||
|
||||
[Fact]
|
||||
public void SessionConstructionNullQuery()
|
||||
public void SessionConstructionNullMetadataFactory()
|
||||
{
|
||||
// If: I create a session object without a null query
|
||||
// If: I create a session object with a null metadata factory
|
||||
// Then: It should throw an exception
|
||||
Assert.Throws<ArgumentNullException>(() => new EditSession(null, Common.GetStandardMetadata(new DbColumn[] {})));
|
||||
Assert.Throws<ArgumentNullException>(() => new EditSession(null, Constants.OwnerUri, Constants.OwnerUri));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SessionConstructionNullMetadataProvider()
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\r\n")]
|
||||
public void SessionConstructionNullObjectName(string objName)
|
||||
{
|
||||
// If: I create a session object without a null metadata provider
|
||||
// If: I create a session object with a null or whitespace object name
|
||||
// Then: It should throw an exception
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
Assert.Throws<ArgumentNullException>(() => new EditSession(rs, null));
|
||||
Mock<IEditMetadataFactory> mockFactory = new Mock<IEditMetadataFactory>();
|
||||
Assert.Throws<ArgumentException>(() => new EditSession(mockFactory.Object, objName, Constants.OwnerUri));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\r\n")]
|
||||
public void SessionConstructionNullObjectType(string objType)
|
||||
{
|
||||
// If: I create a session object with a null or whitespace object type
|
||||
// Then: It should throw an exception
|
||||
Mock<IEditMetadataFactory> mockFactory = new Mock<IEditMetadataFactory>();
|
||||
Assert.Throws<ArgumentException>(() => new EditSession(mockFactory.Object, Constants.OwnerUri, objType));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SessionConstructionValid()
|
||||
{
|
||||
// If: I create a session object with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
// If: I create a session object with a proper arguments
|
||||
Mock<IEditMetadataFactory> mockFactory = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(mockFactory.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// Then:
|
||||
// ... The edit cache should exist and be empty
|
||||
Assert.NotNull(s.EditCache);
|
||||
Assert.Empty(s.EditCache);
|
||||
// ... The edit cache should not exist
|
||||
Assert.Null(s.EditCache);
|
||||
|
||||
// ... The session shouldn't be initialized
|
||||
Assert.False(s.IsInitialized);
|
||||
Assert.Null(s.EditCache);
|
||||
Assert.Null(s.CommitTask);
|
||||
|
||||
// ... The next row ID should be equivalent to the number of rows in the result set
|
||||
Assert.Equal(q.Batches[0].ResultSets[0].RowCount, s.NextRowId);
|
||||
// ... The next row ID should be the default long
|
||||
Assert.Equal(default(long), s.NextRowId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -118,15 +133,28 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region Create Row Tests
|
||||
|
||||
[Fact]
|
||||
public void CreateRowAddFailure()
|
||||
public void CreateRowNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to create a row without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.CreateRow());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateRowAddFailure()
|
||||
{
|
||||
// NOTE: This scenario should theoretically never occur, but is tested for completeness
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = await Common.GetCustomSession(q, etm);
|
||||
|
||||
// ... Add a mock edit to the edit cache to cause the .TryAdd to fail
|
||||
var mockEdit = new Mock<RowEditBase>().Object;
|
||||
@@ -145,13 +173,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateRowSuccess()
|
||||
public async Task CreateRowSuccess()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = await Common.GetCustomSession(q, etm);
|
||||
|
||||
// If: I add a row to the session
|
||||
EditCreateRowResult result = s.CreateRow();
|
||||
@@ -172,48 +200,48 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateRowDefaultTest()
|
||||
public async Task CreateRowDefaultTest()
|
||||
{
|
||||
// Setup:
|
||||
// ... We will have 3 columns
|
||||
DbColumn[] cols =
|
||||
DbColumnWrapper[] cols =
|
||||
{
|
||||
new TestDbColumn("col1", false), // No default
|
||||
new TestDbColumn("col2", false), // Has default (defined below)
|
||||
new TestDbColumn("filler", false) // Filler column so we can use the common code
|
||||
new DbColumnWrapper(new TestDbColumn("col1")), // No default
|
||||
new DbColumnWrapper(new TestDbColumn("col2")), // Has default (defined below)
|
||||
new DbColumnWrapper(new TestDbColumn("filler")) // Filler column so we can use the common code
|
||||
};
|
||||
|
||||
// ... Metadata provider will return 3 columns
|
||||
EditColumnWrapper[] metas =
|
||||
EditColumnMetadata[] metas =
|
||||
{
|
||||
new EditColumnWrapper // No default
|
||||
new EditColumnMetadata // No default
|
||||
{
|
||||
DbColumn = new DbColumnWrapper(cols[0]),
|
||||
DefaultValue = null,
|
||||
EscapedName = cols[0].ColumnName,
|
||||
Ordinal = 0,
|
||||
IsKey = false
|
||||
},
|
||||
new EditColumnWrapper // Has default
|
||||
new EditColumnMetadata // Has default
|
||||
{
|
||||
DbColumn = new DbColumnWrapper(cols[1]),
|
||||
DefaultValue = "default",
|
||||
EscapedName = cols[0].ColumnName,
|
||||
Ordinal = 0,
|
||||
IsKey = false
|
||||
},
|
||||
new EditColumnWrapper()
|
||||
new EditColumnMetadata()
|
||||
};
|
||||
var etm = Common.GetMetadataProvider(metas, true);
|
||||
var etm = new EditTableMetadata
|
||||
{
|
||||
Columns = metas,
|
||||
EscapedMultipartName = "tbl",
|
||||
IsMemoryOptimized = false
|
||||
};
|
||||
etm.Extend(cols);
|
||||
|
||||
// ... Create a result set
|
||||
var rs = Common.GetResultSet(cols, false, 1);
|
||||
var q = await Common.GetQuery(cols, false);
|
||||
|
||||
// ... Create a session from all this
|
||||
var session = new EditSession(rs, etm);
|
||||
EditSession s = await Common.GetCustomSession(q, etm);
|
||||
|
||||
// If: I add a row to the session, on a table that has defaults
|
||||
var result = session.CreateRow();
|
||||
var result = s.CreateRow();
|
||||
|
||||
// Then:
|
||||
// ... Result should not be null, new row ID should be > 0
|
||||
@@ -233,13 +261,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RowIdOutOfRangeData))]
|
||||
public void RowIdOutOfRange(long rowId, Action<EditSession, long> testAction)
|
||||
public async Task RowIdOutOfRange(long rowId, Action<EditSession, long> testAction)
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// If: I delete a row that is out of range for the result set
|
||||
// Then: I should get an exception
|
||||
@@ -253,26 +278,260 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Delete Row
|
||||
Action<EditSession, long> delAction = (s, l) => s.DeleteRow(l);
|
||||
yield return new object[] { -1L, delAction };
|
||||
yield return new object[] {(long) QueryExecution.Common.StandardRows, delAction};
|
||||
yield return new object[] { 100L, delAction };
|
||||
|
||||
// Update Cell
|
||||
Action<EditSession, long> upAction = (s, l) => s.UpdateCell(l, 0, null);
|
||||
yield return new object[] { -1L, upAction };
|
||||
yield return new object[] {(long) QueryExecution.Common.StandardRows, upAction};
|
||||
yield return new object[] { 100L, upAction };
|
||||
|
||||
// Revert Row
|
||||
Action<EditSession, long> revertRowAction = (s, l) => s.RevertRow(l);
|
||||
yield return new object[] {-1L, revertRowAction};
|
||||
yield return new object[] {0L, revertRowAction}; // This is invalid b/c there isn't an edit pending for this row
|
||||
yield return new object[] {(long) QueryExecution.Common.StandardRows, revertRowAction};
|
||||
yield return new object[] {100L, revertRowAction};
|
||||
|
||||
// Revert Cell
|
||||
Action<EditSession, long> revertCellAction = (s, l) => s.RevertCell(l, 0);
|
||||
yield return new object[] {-1L, revertRowAction};
|
||||
yield return new object[] {0L, revertRowAction}; // This is invalid b/c there isn't an edit pending for this row
|
||||
yield return new object[] {(long) QueryExecution.Common.StandardRows, revertRowAction};
|
||||
yield return new object[] {100L, revertRowAction};
|
||||
}
|
||||
}
|
||||
|
||||
#region Initialize Tests
|
||||
|
||||
[Fact]
|
||||
public void InitializeAlreadyInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session and fake that it has been initialized
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
s.IsInitialized = true;
|
||||
|
||||
// If: I initialize it
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.Initialize(null, null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeAlreadyInitializing()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session and fake that it is in progress of initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
s.InitializeTask = new Task(() => { });
|
||||
|
||||
// If: I initialize it
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.Initialize(null, null, null, null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(InitializeNullParamsData))]
|
||||
public void InitializeNullParams(EditSession.Connector c, EditSession.QueryRunner qr,
|
||||
Func<Task> sh, Func<Exception, Task> fh)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session that hasn't been initialized
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I initialize it with a missing parameter
|
||||
// Then: It should throw an exception
|
||||
Assert.ThrowsAny<ArgumentException>(() => s.Initialize(c, qr, sh, fh));
|
||||
}
|
||||
|
||||
public static IEnumerable<object> InitializeNullParamsData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new object[] {null, DoNothingQueryRunner, DoNothingSuccessHandler, DoNothingFailureHandler};
|
||||
yield return new object[] {DoNothingConnector, null, DoNothingSuccessHandler, DoNothingFailureHandler};
|
||||
yield return new object[] {DoNothingConnector, DoNothingQueryRunner, null, DoNothingFailureHandler};
|
||||
yield return new object[] {DoNothingConnector, DoNothingQueryRunner, DoNothingSuccessHandler, null};
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeMetadataFails()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a metadata factory that throws
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
emf.Setup(f => f.GetObjectMetadata(It.IsAny<DbConnection>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws<Exception>();
|
||||
|
||||
// ... Create a session that hasn't been initialized
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// ... Create a mock for verifying the failure handler will be called
|
||||
var successHandler = DoNothingSuccessMock;
|
||||
var failureHandler = DoNothingFailureMock;
|
||||
|
||||
// If: I initalize the session with a metadata factory that will fail
|
||||
s.Initialize(DoNothingConnector, DoNothingQueryRunner, successHandler.Object, failureHandler.Object);
|
||||
await s.InitializeTask;
|
||||
|
||||
// Then:
|
||||
// ... The session should not be initialized
|
||||
Assert.False(s.IsInitialized);
|
||||
|
||||
// ... The failure handler should have been called once
|
||||
failureHandler.Verify(f => f(It.IsAny<Exception>()), Times.Once);
|
||||
|
||||
// ... The success handler should not have been called at all
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeQueryFailException()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a metadata factory that will return some generic column information
|
||||
var b = QueryExecution.Common.GetBasicExecutedBatch();
|
||||
var etm = Common.GetStandardMetadata(b.ResultSets[0].Columns);
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
emf.Setup(f => f.GetObjectMetadata(It.IsAny<DbConnection>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(etm);
|
||||
|
||||
// ... Create a session that hasn't been initialized
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// ... Create a query runner that will fail via exception
|
||||
Mock<EditSession.QueryRunner> qr = new Mock<EditSession.QueryRunner>();
|
||||
qr.Setup(r => r(It.IsAny<string>())).Throws(new Exception("qqq"));
|
||||
|
||||
// ... Create a mock for verifying the failure handler will be called
|
||||
var successHandler = DoNothingSuccessMock;
|
||||
var failureHandler = DoNothingFailureMock;
|
||||
|
||||
// If: I initialize the session with a query runner that will fail
|
||||
s.Initialize(DoNothingConnector, qr.Object, successHandler.Object, failureHandler.Object);
|
||||
await s.InitializeTask;
|
||||
|
||||
// Then:
|
||||
// ... The session should not be initialized
|
||||
Assert.False(s.IsInitialized);
|
||||
|
||||
// ... The failure handler should have been called once
|
||||
failureHandler.Verify(f => f(It.IsAny<Exception>()), Times.Once);
|
||||
|
||||
// ... The success handler should not have been called at all
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("It fail.")]
|
||||
public async Task InitializeQueryFailReturnNull(string message)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a metadata factory that will return some generic column information
|
||||
var b = QueryExecution.Common.GetBasicExecutedBatch();
|
||||
var etm = Common.GetStandardMetadata(b.ResultSets[0].Columns);
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
emf.Setup(f => f.GetObjectMetadata(It.IsAny<DbConnection>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(etm);
|
||||
|
||||
// ... Create a session that hasn't been initialized
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// ... Create a query runner that will fail via returning a null query
|
||||
Mock<EditSession.QueryRunner> qr = new Mock<EditSession.QueryRunner>();
|
||||
qr.Setup(r => r(It.IsAny<string>()))
|
||||
.Returns(Task.FromResult(new EditSession.EditSessionQueryExecutionState(null, message)));
|
||||
|
||||
// ... Create a mock for verifying the failure handler will be called
|
||||
var successHandler = DoNothingSuccessMock;
|
||||
var failureHandler = DoNothingFailureMock;
|
||||
|
||||
// If: I initialize the session with a query runner that will fail
|
||||
s.Initialize(DoNothingConnector, qr.Object, successHandler.Object, failureHandler.Object);
|
||||
await s.InitializeTask;
|
||||
|
||||
// Then:
|
||||
// ... The session should not be initialized
|
||||
Assert.False(s.IsInitialized);
|
||||
|
||||
// ... The failure handler should have been called once
|
||||
failureHandler.Verify(f => f(It.IsAny<Exception>()), Times.Once);
|
||||
|
||||
// ... The success handler should not have been called at all
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeSuccess()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a metadata factory that will return some generic column information
|
||||
var q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
var rs = q.Batches[0].ResultSets[0];
|
||||
var etm = Common.GetStandardMetadata(rs.Columns);
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
emf.Setup(f => f.GetObjectMetadata(It.IsAny<DbConnection>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(etm);
|
||||
|
||||
// ... Create a session that hasn't been initialized
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// ... Create a query runner that will return a successful query
|
||||
Mock<EditSession.QueryRunner> qr = new Mock<EditSession.QueryRunner>();
|
||||
qr.Setup(r => r(It.IsAny<string>()))
|
||||
.Returns(Task.FromResult(new EditSession.EditSessionQueryExecutionState(q, null)));
|
||||
|
||||
// ... Create a mock for verifying the failure handler will be called
|
||||
var successHandler = DoNothingSuccessMock;
|
||||
var failureHandler = DoNothingFailureMock;
|
||||
|
||||
// If: I initialize the session with a query runner that will fail
|
||||
s.Initialize(DoNothingConnector, qr.Object, successHandler.Object, failureHandler.Object);
|
||||
await s.InitializeTask;
|
||||
|
||||
// Then:
|
||||
// ... The failure handler should not have been called
|
||||
failureHandler.Verify(f => f(It.IsAny<Exception>()), Times.Never);
|
||||
|
||||
// ... The success handler should have been called
|
||||
successHandler.Verify(f => f(), Times.Once);
|
||||
|
||||
// ... The session should have been initialized
|
||||
Assert.True(s.IsInitialized);
|
||||
Assert.Equal(rs.RowCount, s.NextRowId);
|
||||
Assert.NotNull(s.EditCache);
|
||||
Assert.Empty(s.EditCache);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete Row Tests
|
||||
|
||||
[Fact]
|
||||
public void DeleteRowAddFailure()
|
||||
public void DeleteRowNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to delete a row without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.DeleteRow(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteRowAddFailure()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a mock edit to the edit cache to cause the .TryAdd to fail
|
||||
var mockEdit = new Mock<RowEditBase>().Object;
|
||||
@@ -288,13 +547,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteRowSuccess()
|
||||
public async Task DeleteRowSuccess()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
var s = await GetBasicSession();
|
||||
|
||||
// If: I add a row to the session
|
||||
s.DeleteRow(0);
|
||||
@@ -309,28 +565,24 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region Revert Row Tests
|
||||
|
||||
[Fact]
|
||||
public void RevertRowOutOfRange()
|
||||
public void RevertRowNotInitialized()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I revert a row that doesn't have any pending changes
|
||||
// If: I ask to revert a row without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => s.RevertRow(0));
|
||||
Assert.Throws<InvalidOperationException>(() => s.RevertRow(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevertRowSuccess()
|
||||
public async Task RevertRowSuccess()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a mock edit to the edit cache to cause the .TryAdd to fail
|
||||
var mockEdit = new Mock<RowEditBase>().Object;
|
||||
@@ -346,17 +598,44 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#endregion
|
||||
|
||||
#region Revert Cell Tests
|
||||
|
||||
[Fact]
|
||||
public void RevertCellNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to revert a cell without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.RevertCell(0, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update Cell Tests
|
||||
|
||||
[Fact]
|
||||
public void UpdateCellExisting()
|
||||
public void UpdateCellNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to update a cell without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.UpdateCell(0, 0, ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateCellExisting()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a mock edit to the edit cache to cause the .TryAdd to fail
|
||||
var mockEdit = new Mock<RowEditBase>();
|
||||
@@ -373,14 +652,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateCellNew()
|
||||
public async Task UpdateCellNew()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// If: I update a cell on a row that does not have a pending edit
|
||||
s.UpdateCell(0, 0, "");
|
||||
@@ -395,14 +671,27 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region SubSet Tests
|
||||
|
||||
[Fact]
|
||||
public async Task SubsetNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to update a cell without initializing
|
||||
// Then: I should get an exception
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => s.GetRows(0, 100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRowsNoEdits()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = await Common.GetCustomSession(q, etm);
|
||||
|
||||
// If: I ask for 3 rows from session skipping the first
|
||||
EditRow[] rows = await s.GetRows(1, 3);
|
||||
@@ -439,10 +728,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a cell update to it
|
||||
s.UpdateCell(1, 0, "foo");
|
||||
@@ -472,10 +758,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a row deletion
|
||||
s.DeleteRow(1);
|
||||
@@ -505,10 +788,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a row creation
|
||||
s.CreateRow();
|
||||
@@ -536,10 +816,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add a few row creations
|
||||
s.CreateRow();
|
||||
@@ -561,17 +838,27 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region Script Edits Tests
|
||||
|
||||
[Fact]
|
||||
public void ScriptEditsNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to script edits without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.ScriptEdits(string.Empty));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\r\n")]
|
||||
public void ScriptNullOrEmptyOutput(string outputPath)
|
||||
public async Task ScriptNullOrEmptyOutput(string outputPath)
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// If: I try to script the edit cache with a null or whitespace output path
|
||||
// Then: It should throw an exception
|
||||
@@ -579,14 +866,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScriptProvidedOutputPath()
|
||||
public async Task ScriptProvidedOutputPath()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session with a proper query and metadata
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
EditSession s = new EditSession(rs, etm);
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Add two mock edits that will generate a script
|
||||
Mock<RowEditBase> edit = new Mock<RowEditBase>();
|
||||
@@ -613,10 +897,23 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region Commit Tests
|
||||
|
||||
[Fact]
|
||||
public void CommitNullConnection()
|
||||
public void CommitEditsNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a session without initializing
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object, Constants.OwnerUri, Constants.OwnerUri);
|
||||
|
||||
// If: I ask to script edits without initializing
|
||||
// Then: I should get an exception
|
||||
Assert.Throws<InvalidOperationException>(() => s.CommitEdits(null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CommitNullConnection()
|
||||
{
|
||||
// Setup: Create a basic session
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// If: I attempt to commit with a null connection
|
||||
// Then: I should get an exception
|
||||
@@ -625,11 +922,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CommitNullSuccessHandler()
|
||||
public async Task CommitNullSuccessHandler()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a basic session
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Mock db connection
|
||||
DbConnection conn = new TestSqlConnection(null);
|
||||
@@ -640,11 +937,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CommitNullFailureHandler()
|
||||
public async Task CommitNullFailureHandler()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a basic session
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
|
||||
// ... Mock db connection
|
||||
DbConnection conn = new TestSqlConnection(null);
|
||||
@@ -655,11 +952,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CommitInProgress()
|
||||
public async Task CommitInProgress()
|
||||
{
|
||||
// Setup:
|
||||
// ... Basic session and db connection
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
DbConnection conn = new TestSqlConnection(null);
|
||||
|
||||
// ... Mock a task that has not completed
|
||||
@@ -677,7 +974,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Basic session and db connection
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
DbConnection conn = new TestSqlConnection(null);
|
||||
|
||||
// ... Add a mock commands for fun
|
||||
@@ -721,7 +1018,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Setup:
|
||||
// ... Basic session and db connection
|
||||
EditSession s = GetBasicSession();
|
||||
EditSession s = await GetBasicSession();
|
||||
DbConnection conn = new TestSqlConnection(null);
|
||||
|
||||
// ... Add a mock edit that will explode on generating a command
|
||||
@@ -760,12 +1057,51 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#endregion
|
||||
|
||||
private static EditSession GetBasicSession()
|
||||
private static EditSession.Connector DoNothingConnector
|
||||
{
|
||||
get { return () => Task.FromResult<DbConnection>(null); }
|
||||
}
|
||||
|
||||
private static EditSession.QueryRunner DoNothingQueryRunner
|
||||
{
|
||||
get { return q => Task.FromResult<EditSession.EditSessionQueryExecutionState>(null); }
|
||||
}
|
||||
|
||||
private static Func<Task> DoNothingSuccessHandler
|
||||
{
|
||||
get { return () => Task.FromResult(0); }
|
||||
}
|
||||
|
||||
private static Func<Exception, Task> DoNothingFailureHandler
|
||||
{
|
||||
get { return e => Task.FromResult(0); }
|
||||
}
|
||||
|
||||
private static Mock<Func<Task>> DoNothingSuccessMock
|
||||
{
|
||||
get {
|
||||
Mock<Func<Task>> successHandler = new Mock<Func<Task>>();
|
||||
successHandler.Setup(f => f()).Returns(Task.FromResult(0));
|
||||
return successHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private static Mock<Func<Exception, Task>> DoNothingFailureMock
|
||||
{
|
||||
get
|
||||
{
|
||||
Mock<Func<Exception, Task>> failureHandler = new Mock<Func<Exception, Task>>();
|
||||
failureHandler.Setup(f => f(It.IsAny<Exception>())).Returns(Task.FromResult(0));
|
||||
return failureHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<EditSession> GetBasicSession()
|
||||
{
|
||||
Query q = QueryExecution.Common.GetBasicExecutedQuery();
|
||||
ResultSet rs = q.Batches[0].ResultSets[0];
|
||||
IEditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
return new EditSession(rs, etm);
|
||||
EditTableMetadata etm = Common.GetStandardMetadata(rs.Columns);
|
||||
return await Common.GetCustomSession(q, etm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user