mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Unit tests, part 1
This commit is contained in:
@@ -18,6 +18,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.Test.Utility
|
||||
@@ -97,179 +98,18 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
}
|
||||
}
|
||||
|
||||
public class TestDataReader : DbDataReader
|
||||
{
|
||||
|
||||
#region Test Specific Implementations
|
||||
|
||||
internal string SqlCommandText { get; set; }
|
||||
|
||||
private const string tableNameTestCommand = "SELECT name FROM sys.tables";
|
||||
|
||||
private List<Dictionary<string, string>> tableNamesTest = new List<Dictionary<string, string>>
|
||||
{
|
||||
new Dictionary<string, string> { {"name", "table1"} },
|
||||
new Dictionary<string, string> { {"name", "table2"} }
|
||||
};
|
||||
|
||||
private IEnumerator<Dictionary<string, string>> tableEnumerator;
|
||||
|
||||
#endregion
|
||||
|
||||
public override bool GetBoolean(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override byte GetByte(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override char GetChar(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GetDataTypeName(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override DateTime GetDateTime(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override decimal GetDecimal(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override double GetDouble(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerator GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetOrdinal(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GetName(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override long GetInt64(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetInt32(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override short GetInt16(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Guid GetGuid(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override float GetFloat(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Type GetFieldType(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string GetString(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object GetValue(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetValues(object[] values)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool IsDBNull(int ordinal)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool NextResult()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Read()
|
||||
{
|
||||
if (tableEnumerator == null)
|
||||
{
|
||||
switch (SqlCommandText)
|
||||
{
|
||||
case tableNameTestCommand:
|
||||
tableEnumerator = ((IEnumerable<Dictionary<string, string>>)tableNamesTest).GetEnumerator();
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
return tableEnumerator.MoveNext();
|
||||
}
|
||||
|
||||
public override int Depth { get; }
|
||||
public override bool IsClosed { get; }
|
||||
public override int RecordsAffected { get; }
|
||||
|
||||
public override object this[string name]
|
||||
{
|
||||
get { return tableEnumerator.Current[name]; }
|
||||
}
|
||||
|
||||
public override object this[int ordinal]
|
||||
{
|
||||
get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[ordinal]]; }
|
||||
}
|
||||
|
||||
public override int FieldCount { get; }
|
||||
public override bool HasRows { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test mock class for IDbCommand
|
||||
/// </summary>
|
||||
public class TestSqlCommand : DbCommand
|
||||
{
|
||||
internal TestSqlCommand(Dictionary<string, string>[][] data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
internal Dictionary<string, string>[][] Data { get; set; }
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -306,7 +146,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
|
||||
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
|
||||
{
|
||||
return new TestDataReader {SqlCommandText = CommandText};
|
||||
return new TestDbDataReader(Data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +155,13 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
/// </summary>
|
||||
public class TestSqlConnection : DbConnection
|
||||
{
|
||||
internal TestSqlConnection(Dictionary<string, string>[][] data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
internal Dictionary<string, string>[][] Data { get; set; }
|
||||
|
||||
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -342,7 +189,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
|
||||
protected override DbCommand CreateDbCommand()
|
||||
{
|
||||
return new TestSqlCommand();
|
||||
return new TestSqlCommand(Data);
|
||||
}
|
||||
|
||||
public override void ChangeDatabase(string databaseName)
|
||||
@@ -358,7 +205,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
public DbConnection CreateSqlConnection(string connectionString)
|
||||
{
|
||||
return new TestSqlConnection()
|
||||
return new TestSqlConnection(null)
|
||||
{
|
||||
ConnectionString = connectionString
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user