Convert most tools service tests to nunit (#1037)

* Remove xunit dependency from testdriver

* swap expected/actual as needed

* Convert Test.Common to nunit

* port hosting unit tests to nunit

* port batchparser integration tests to nunit

* port testdriver.tests to nunit

* fix target to copy dependency

* port servicelayer unittests to nunit

* more unit test fixes

* port integration tests to nunit

* fix test method type

* try using latest windows build for PRs

* reduce test memory use
This commit is contained in:
David Shiflet
2020-08-05 13:43:14 -04:00
committed by GitHub
parent bf4911795f
commit 839acf67cd
205 changed files with 4146 additions and 4329 deletions

View File

@@ -17,7 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Xunit;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
@@ -52,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
databaseSession = new ObjectExplorerService.ObjectExplorerSession("databaseUri", databaseRoot, null, null);
}
[Fact]
[Test]
public void FindCorrectPathsForTableWithServerRoot()
{
var paths = NodePathGenerator.FindNodePaths(serverSession, "Table", "testSchema", "testTable", databaseName);
@@ -64,14 +64,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable"
};
Assert.Equal(expectedPaths.Count, paths.Count);
Assert.AreEqual(expectedPaths.Count, paths.Count);
foreach (var expectedPath in expectedPaths)
{
Assert.True(paths.Contains(expectedPath));
}
}
[Fact]
[Test]
public void FindCorrectPathsForTableWithDatabaseRoot()
{
var paths = NodePathGenerator.FindNodePaths(databaseSession, "Table", "testSchema", "testTable", null);
@@ -81,14 +81,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/testDatabase/Tables/System Tables/testSchema.testTable"
};
Assert.Equal(expectedPaths.Count, paths.Count);
Assert.AreEqual(expectedPaths.Count, paths.Count);
foreach (var expectedPath in expectedPaths)
{
Assert.True(paths.Contains(expectedPath));
}
}
[Fact]
[Test]
public void FindCorrectPathsForColumnWithServerRoot()
{
var paths = NodePathGenerator.FindNodePaths(serverSession, "Column", null, "testColumn", databaseName, new List<string> { "testSchema.testTable" });
@@ -104,14 +104,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/Databases/System Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn"
};
Assert.Equal(expectedPaths.Count, paths.Count);
Assert.AreEqual(expectedPaths.Count, paths.Count);
foreach (var expectedPath in expectedPaths)
{
Assert.True(paths.Contains(expectedPath));
}
}
[Fact]
[Test]
public void FindCorrectPathsForColumnWithDatabaseRoot()
{
var paths = NodePathGenerator.FindNodePaths(databaseSession, "Column", null, "testColumn", databaseName, new List<string> { "testSchema.testTable" });
@@ -123,14 +123,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn"
};
Assert.Equal(expectedPaths.Count, paths.Count);
Assert.AreEqual(expectedPaths.Count, paths.Count);
foreach (var expectedPath in expectedPaths)
{
Assert.True(paths.Contains(expectedPath));
}
}
[Fact]
[Test]
public void FindCorrectPathsForDatabase()
{
var paths = NodePathGenerator.FindNodePaths(serverSession, "Database", null, databaseName, null);
@@ -140,25 +140,25 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/Databases/System Databases/testDatabase"
};
Assert.Equal(expectedPaths.Count, paths.Count);
Assert.AreEqual(expectedPaths.Count, paths.Count);
foreach (var expectedPath in expectedPaths)
{
Assert.True(paths.Contains(expectedPath));
}
}
[Fact]
[Test]
public void FindPathForInvalidTypeReturnsEmpty()
{
var serverPaths = NodePathGenerator.FindNodePaths(serverSession, "WrongType", "testSchema", "testTable", databaseName);
Assert.Equal(0, serverPaths.Count);
Assert.AreEqual(0, serverPaths.Count);
}
[Fact]
[Test]
public void FindPathMissingParentReturnsEmpty()
{
var serverPaths = NodePathGenerator.FindNodePaths(serverSession, "Column", "testSchema", "testColumn", databaseName);
Assert.Equal(0, serverPaths.Count);
Assert.AreEqual(0, serverPaths.Count);
}
}
}

View File

@@ -18,7 +18,7 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Xunit;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.Connection;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
@@ -35,7 +35,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private string fakeConnectionString = "Data Source=server;Initial Catalog=database;Integrated Security=False;User Id=user";
private ServerConnection serverConnection = null;
public NodeTests()
[SetUp]
public void InitNodeTests()
{
defaultServerInfo = TestObjects.GetTestServerInfo();
serverConnection = new ServerConnection(new SqlConnection(fakeConnectionString));
@@ -58,33 +59,33 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
ServiceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
}
[Fact]
[Test]
public void ServerNodeConstructorValidatesFields()
{
Assert.Throws<ArgumentNullException>(() => new ServerNode(null, ServiceProvider, serverConnection));
Assert.Throws<ArgumentNullException>(() => new ServerNode(defaultConnParams, null, serverConnection));
}
[Fact]
[Test]
public void ServerNodeConstructorShouldSetValuesCorrectly()
{
// Given a server node with valid inputs
ServerNode node = new ServerNode(defaultConnParams, ServiceProvider, serverConnection);
// Then expect all fields set correctly
Assert.False(node.IsAlwaysLeaf, "Server node should never be a leaf");
Assert.Equal(defaultConnectionDetails.ServerName, node.NodeValue);
Assert.AreEqual(defaultConnectionDetails.ServerName, node.NodeValue);
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ")";
Assert.Equal(expectedLabel, node.Label);
Assert.AreEqual(expectedLabel, node.Label);
Assert.Equal(NodeTypes.Server.ToString(), node.NodeType);
Assert.AreEqual(NodeTypes.Server.ToString(), node.NodeType);
string[] nodePath = node.GetNodePath().Split(TreeNode.PathPartSeperator);
Assert.Equal(1, nodePath.Length);
Assert.Equal(defaultConnectionDetails.ServerName, nodePath[0]);
Assert.AreEqual(1, nodePath.Length);
Assert.AreEqual(defaultConnectionDetails.ServerName, nodePath[0]);
}
[Fact]
[Test]
public void ServerNodeLabelShouldIgnoreUserNameIfEmptyOrNull()
{
// Given no username set
@@ -104,10 +105,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
string label = new ServerNode(connParams, ServiceProvider, serverConnection).Label;
// Then only server name and version shown
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + ")";
Assert.Equal(expectedLabel, label);
Assert.AreEqual(expectedLabel, label);
}
[Fact]
[Test]
public void ServerNodeConstructorShouldShowDbNameForCloud()
{
defaultServerInfo.IsCloud = true;
@@ -117,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then expect label to not include db name
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ")";
Assert.Equal(expectedLabel, node.Label);
Assert.AreEqual(expectedLabel, node.Label);
// But given a server node for a cloud DB that's not master
defaultConnectionDetails.DatabaseName = "NotMaster";
@@ -127,10 +128,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then expect label to include db name
expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ", " + defaultConnectionDetails.DatabaseName + ")";
Assert.Equal(expectedLabel, node.Label);
Assert.AreEqual(expectedLabel, node.Label);
}
[Fact]
[Test]
public void ToNodeInfoIncludeAllFields()
{
// Given a server connection
@@ -138,29 +139,29 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// When converting to NodeInfo
NodeInfo info = node.ToNodeInfo();
// Then all fields should match
Assert.Equal(node.IsAlwaysLeaf, info.IsLeaf);
Assert.Equal(node.Label, info.Label);
Assert.Equal(node.NodeType, info.NodeType);
Assert.AreEqual(node.IsAlwaysLeaf, info.IsLeaf);
Assert.AreEqual(node.Label, info.Label);
Assert.AreEqual(node.NodeType, info.NodeType);
string[] nodePath = node.GetNodePath().Split(TreeNode.PathPartSeperator);
string[] nodeInfoPathParts = info.NodePath.Split(TreeNode.PathPartSeperator);
Assert.Equal(nodePath.Length, nodeInfoPathParts.Length);
Assert.AreEqual(nodePath.Length, nodeInfoPathParts.Length);
for (int i = 0; i < nodePath.Length; i++)
{
Assert.Equal(nodePath[i], nodeInfoPathParts[i]);
Assert.AreEqual(nodePath[i], nodeInfoPathParts[i]);
}
}
[Fact]
[Test]
public void AddChildShouldSetParent()
{
TreeNode parent = new TreeNode("parent");
TreeNode child = new TreeNode("child");
Assert.Null(child.Parent);
parent.AddChild(child);
Assert.Equal(parent, child.Parent);
Assert.AreEqual(parent, child.Parent);
}
[Fact]
[Test]
public void GetChildrenShouldReturnReadonlyList()
{
TreeNode node = new TreeNode("parent");
@@ -168,7 +169,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
Assert.Throws<NotSupportedException>(() => children.Add(new TreeNode("child")));
}
[Fact]
[Test]
public void GetChildrenShouldReturnAddedNodesInOrder()
{
TreeNode parent = new TreeNode("parent");
@@ -178,33 +179,33 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
parent.AddChild(child);
}
IList<TreeNode> children = parent.GetChildren();
Assert.Equal(expectedKids.Length, children.Count);
Assert.AreEqual(expectedKids.Length, children.Count);
for (int i = 0; i < expectedKids.Length; i++)
{
Assert.Equal(expectedKids[i], children[i]);
Assert.AreEqual(expectedKids[i], children[i]);
}
}
[Fact]
[Test]
public void MultiLevelTreeShouldFormatPath()
{
TreeNode root = new TreeNode("root");
Assert.Equal("root" , root.GetNodePath());
Assert.AreEqual("root" , root.GetNodePath());
TreeNode level1Child1 = new TreeNode("L1C1 (with extra info)");
level1Child1.NodePathName = "L1C1";
TreeNode level1Child2 = new TreeNode("L1C2");
root.AddChild(level1Child1);
root.AddChild(level1Child2);
Assert.Equal("root/L1C1" , level1Child1.GetNodePath());
Assert.Equal("root/L1C2", level1Child2.GetNodePath());
Assert.AreEqual("root/L1C1" , level1Child1.GetNodePath());
Assert.AreEqual("root/L1C2", level1Child2.GetNodePath());
TreeNode level2Child1 = new TreeNode("L2C2");
level1Child1.AddChild(level2Child1);
Assert.Equal("root/L1C1/L2C2", level2Child1.GetNodePath());
Assert.AreEqual("root/L1C1/L2C2", level2Child1.GetNodePath());
}
[Fact]
[Test]
public void ServerNodeContextShouldIncludeServer()
{
// given a successful Server creation
@@ -216,13 +217,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to contain the server I created
Assert.NotNull(context);
Assert.Equal(smoServer, context.Server);
Assert.AreEqual(smoServer, context.Server);
// And the server should be the parent
Assert.Equal(smoServer, context.Parent);
Assert.AreEqual(smoServer, context.Parent);
Assert.Null(context.Database);
}
[Fact]
[Test]
public void ServerNodeContextShouldSetErrorMessageIfSqlConnectionIsNull()
{
// given a connectionInfo with no SqlConnection to use for queries
@@ -237,7 +238,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
Assert.Null(context);
}
[Fact]
[Test]
public void ServerNodeContextShouldSetErrorMessageIfConnFailureExceptionThrown()
{
// given a connectionInfo with no SqlConnection to use for queries
@@ -250,12 +251,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to be in an error state
Assert.Null(context);
Assert.Equal(
Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, SR.TreeNodeError, expectedMsg),
node.ErrorStateMessage);
}
[Fact]
[Test]
public void ServerNodeContextShouldSetErrorMessageIfExceptionThrown()
{
// given a connectionInfo with no SqlConnection to use for queries
@@ -268,12 +269,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to be in an error state
Assert.Null(context);
Assert.Equal(
Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, SR.TreeNodeError, expectedMsg),
node.ErrorStateMessage);
}
[Fact]
[Test]
public void QueryContextShouldNotCallOpenOnAlreadyOpenConnection()
{
// given a server connection that will state its connection is open
@@ -304,7 +305,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
return wrapper;
}
[Fact]
[Test]
public void QueryContextShouldReopenClosedConnectionWhenGettingServer()
{
// given a server connection that will state its connection is closed
@@ -321,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
wrapper.Verify(c => c.OpenConnection(It.IsAny<Server>()), Times.Once);
}
[Fact]
[Test]
public void QueryContextShouldReopenClosedConnectionWhenGettingParent()
{
// given a server connection that will state its connection is closed
@@ -380,7 +381,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
return node;
}
[Fact]
[Test]
public void ServerNodeChildrenShouldIncludeFoldersAndDatabases()
{
// Given a server with 1 database
@@ -404,19 +405,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
IList<TreeNode> children = node.Expand(new CancellationToken());
// Then I expect it to contain server-level folders
Assert.Equal(3, children.Count);
Assert.AreEqual(3, children.Count);
VerifyTreeNode<FolderNode>(children[0], "Folder", SR.SchemaHierarchy_Databases);
VerifyTreeNode<FolderNode>(children[1], "Folder", SR.SchemaHierarchy_Security);
VerifyTreeNode<FolderNode>(children[2], "Folder", SR.SchemaHierarchy_ServerObjects);
// And the database is contained under it
TreeNode databases = children[0];
IList<TreeNode> dbChildren = databases.Expand(new CancellationToken());
Assert.Equal(2, dbChildren.Count);
Assert.Equal(SR.SchemaHierarchy_SystemDatabases, dbChildren[0].NodeValue);
Assert.AreEqual(2, dbChildren.Count);
Assert.AreEqual(SR.SchemaHierarchy_SystemDatabases, dbChildren[0].NodeValue);
TreeNode dbNode = dbChildren[1];
Assert.Equal(dbName, dbNode.NodeValue);
Assert.Equal(dbName, dbNode.Label);
Assert.AreEqual(dbName, dbNode.NodeValue);
Assert.AreEqual(dbName, dbNode.Label);
Assert.False(dbNode.IsAlwaysLeaf);
// Note: would like to verify Database in the context, but cannot since it's a Sealed class and isn't easily mockable
@@ -427,8 +428,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
T nodeAsT = node as T;
Assert.NotNull(nodeAsT);
Assert.Equal(nodeType, nodeAsT.NodeType);
Assert.Equal(folderValue, nodeAsT.NodeValue);
Assert.AreEqual(nodeType, nodeAsT.NodeType);
Assert.AreEqual(folderValue, nodeAsT.NodeValue);
}
}
}

View File

@@ -17,7 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Moq.Protected;
using Xunit;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
@@ -42,7 +42,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
ConnectedBindingQueue connectedBindingQueue;
Mock<SqlConnectionOpener> mockConnectionOpener;
public ObjectExplorerServiceTests()
[SetUp]
public void InitObjectExplorerServiceTests()
{
connectionServiceMock = new Mock<ConnectionService>();
serviceHostMock = new Mock<IProtocolEndpoint>();
@@ -59,7 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
service.ConnectedBindingQueue = connectedBindingQueue;
}
[Fact]
[Test]
public async Task CreateSessionRequestErrorsIfConnectionDetailsIsNull()
{
object errorResponse = null;
@@ -71,7 +73,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
Assert.True(((string)errorResponse).Contains("ArgumentNullException"));
}
[Fact]
[Test]
public async Task CreateSessionRequestReturnsFalseOnConnectionFailure()
{
// Given the connection service fails to connect
@@ -97,7 +99,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
}
[Fact]
[Test]
public async Task CreateSessionRequestWithMasterConnectionReturnsServerSuccessAndNodeInfo()
{
// Given the connection service fails to connect
@@ -111,7 +113,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
await CreateSessionRequestAndVerifyServerNodeHelper(details);
}
[Fact]
[Test]
public async Task CreateSessionRequestWithEmptyConnectionReturnsServerSuccessAndNodeInfo()
{
// Given the connection service fails to connect
@@ -125,7 +127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
await CreateSessionRequestAndVerifyServerNodeHelper(details);
}
[Fact]
[Test]
public async Task CreateSessionRequestWithMsdbConnectionReturnsServerSuccessAndNodeInfo()
{
// Given the connection service fails to connect
@@ -139,7 +141,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
await CreateSessionRequestAndVerifyServerNodeHelper(details);
}
[Fact]
[Test]
public async Task CreateSessionRequestWithDefaultConnectionReturnsServerSuccessAndNodeInfo()
{
// Given the connection service fails to connect
@@ -154,19 +156,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
await CreateSessionRequestAndVerifyServerNodeHelper(details);
}
[Fact]
[Test]
public async Task ExpandNodeGivenValidSessionShouldReturnTheNodeChildren()
{
await ExpandAndVerifyServerNodes();
}
[Fact]
[Test]
public async Task RefreshNodeGivenValidSessionShouldReturnTheNodeChildren()
{
await RefreshAndVerifyServerNodes();
}
[Fact]
[Test]
public async Task ExpandNodeGivenInvalidSessionShouldReturnEmptyList()
{
ExpandParams expandParams = new ExpandParams()
@@ -182,12 +184,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallServiceExpand(expandParams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, expandParams.SessionId);
Assert.AreEqual(actual.SessionId, expandParams.SessionId);
Assert.Null(actual.Nodes);
}));
}
[Fact]
[Test]
public async Task RefreshNodeGivenInvalidSessionShouldReturnEmptyList()
{
RefreshParams expandParams = new RefreshParams()
@@ -202,12 +204,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallServiceRefresh(expandParams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, expandParams.SessionId);
Assert.AreEqual(actual.SessionId, expandParams.SessionId);
Assert.Null(actual.Nodes);
}));
}
[Fact]
[Test]
public async Task RefreshNodeGivenNullSessionShouldReturnEmptyList()
{
RefreshParams expandParams = new RefreshParams()
@@ -222,12 +224,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallServiceRefresh(expandParams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, expandParams.SessionId);
Assert.AreEqual(actual.SessionId, expandParams.SessionId);
Assert.Null(actual.Nodes);
}));
}
[Fact]
[Test]
public async Task CloseSessionGivenInvalidSessionShouldReturnEmptyList()
{
CloseSessionParams closeSessionParamsparams = new CloseSessionParams()
@@ -241,12 +243,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallCloseSession(closeSessionParamsparams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, closeSessionParamsparams.SessionId);
Assert.AreEqual(actual.SessionId, closeSessionParamsparams.SessionId);
Assert.False(actual.Success);
}));
}
[Fact]
[Test]
public async Task CloseSessionGivenValidSessionShouldCloseTheSessionAndDisconnect()
{
var session = await CreateSession();
@@ -261,7 +263,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallCloseSession(closeSessionParamsparams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, closeSessionParamsparams.SessionId);
Assert.AreEqual(actual.SessionId, closeSessionParamsparams.SessionId);
Assert.True(actual.Success);
Assert.False(service.SessionIds.Contains(session.SessionId));
}));
@@ -269,27 +271,27 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
connectionServiceMock.Verify(c => c.Disconnect(It.IsAny<DisconnectParams>()));
}
[Fact]
[Test]
public async Task FindNodesReturnsMatchingNode()
{
var session = await CreateSession();
var foundNodes = service.FindNodes(session.SessionId, "Server", null, null, null);
Assert.Equal(1, foundNodes.Count);
Assert.Equal("Server", foundNodes[0].NodeType);
Assert.Equal(session.RootNode.NodePath, foundNodes[0].ToNodeInfo().NodePath);
Assert.AreEqual(1, foundNodes.Count);
Assert.AreEqual("Server", foundNodes[0].NodeType);
Assert.AreEqual(session.RootNode.NodePath, foundNodes[0].ToNodeInfo().NodePath);
}
[Fact]
[Test]
public async Task FindNodesReturnsEmptyListForNoMatch()
{
var session = await CreateSession();
var foundNodes = service.FindNodes(session.SessionId, "Table", "testSchema", "testTable", "testDatabase");
Assert.Equal(0, foundNodes.Count);
Assert.AreEqual(0, foundNodes.Count);
}
[Fact]
[Test]
public void FindNodeCanExpandParentNodes()
{
var mockTreeNode = new Mock<TreeNode>();
@@ -342,7 +344,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallServiceExpand(expandParams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, session.SessionId);
Assert.AreEqual(actual.SessionId, session.SessionId);
Assert.NotNull(actual.SessionId);
VerifyServerNodeChildren(actual.Nodes);
}));
@@ -363,7 +365,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
test: (requestContext) => CallServiceRefresh(expandParams, requestContext),
verify: (actual =>
{
Assert.Equal(actual.SessionId, session.SessionId);
Assert.AreEqual(actual.SessionId, session.SessionId);
Assert.NotNull(actual.SessionId);
VerifyServerNodeChildren(actual.Nodes);
}));
@@ -460,10 +462,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private void VerifyServerNode(NodeInfo serverNode, ConnectionDetails details)
{
Assert.NotNull(serverNode);
Assert.Equal(NodeTypes.Server.ToString(), serverNode.NodeType);
Assert.AreEqual(NodeTypes.Server.ToString(), serverNode.NodeType);
string[] pathParts = serverNode.NodePath.Split(TreeNode.PathPartSeperator);
Assert.Equal(1, pathParts.Length);
Assert.Equal(details.ServerName, pathParts[0]);
Assert.AreEqual(1, pathParts.Length);
Assert.AreEqual(details.ServerName, pathParts[0]);
Assert.True(serverNode.Label.Contains(details.ServerName));
Assert.False(serverNode.IsLeaf);
}

View File

@@ -5,22 +5,22 @@
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class ServerVersionHelperTests
{
[Fact]
[Test]
public void GetValidForFlagShouldReturnAllGivenUnKnownVersion()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.Unknown);
ValidForFlag expected = ValidForFlag.All;
Assert.Equal(validforFlag, expected);
Assert.AreEqual(validforFlag, expected);
}
[Fact]
[Test]
public void GetValidForFlagShouldReturnTheFlagCorrectlyGivenValidVersion()
{
VerifyGetValidForFlag(SqlServerType.AzureV12, ValidForFlag.AzureV12);
@@ -33,16 +33,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyGetValidForFlag(SqlServerType.SqlOnDemand, ValidForFlag.SqlOnDemand);
}
[Fact]
[Test]
public void GetValidForFlagShouldReturnTheFlagIncludingSqlDwGivenSqlDwdatabase()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.AzureV12, true);
ValidForFlag expected = ValidForFlag.SqlDw;
Assert.Equal(validforFlag, expected);
Assert.AreEqual(validforFlag, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2005Given2005Version()
{
string serverVersion = "9.1.2.3";
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2008Given2008Version()
{
string serverVersion = "10.1.2.3";
@@ -59,7 +59,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2012Given2012Version()
{
string serverVersion = "11.1.2.3";
@@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2014Given2014Version()
{
string serverVersion = "12.1.2.3";
@@ -75,7 +75,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2016Given2016Version()
{
string serverVersion = "13.1.2.3";
@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSql2017Given2017Version()
{
string serverVersion = "14.1.2.3";
@@ -91,7 +91,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
[Test]
public void IsValidForShouldReturnTrueGivenSqlDwAndAll()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
@@ -100,7 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
[Test]
public void IsValidForShouldReturnTrueGivenSqlDwAndNone()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
@@ -109,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
[Test]
public void IsValidForShouldReturnTrueGivenSqlDwAndSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
@@ -118,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
[Test]
public void IsValidForShouldReturnTrueGivenSqlDwAndNotSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
@@ -127,7 +127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
[Test]
public void IsValidForShouldReturnTrueGivenSqlDwAndAllOnPrem()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
@@ -136,7 +136,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
[Test]
public void CalculateServerTypeShouldReturnSqlOnDemandGivenEngineEdition()
{
int engineEdition = 11;
@@ -147,7 +147,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private void VerifyIsValidFor(ValidForFlag serverValidFor, ValidForFlag validFor, bool expected)
{
bool actual = ServerVersionHelper.IsValidFor(serverValidFor, validFor);
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
private void VerifyCalculateServerType(string serverVersion, SqlServerType expected)
@@ -157,7 +157,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
ServerVersion = serverVersion
};
SqlServerType actual = ServerVersionHelper.CalculateServerType(serverInfo);
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
private void VerifyCalculateServerTypeForEngineEdition(int engineEdition, SqlServerType expected)
@@ -176,7 +176,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(serverType);
ValidForFlag expected = validForFlag;
Assert.Equal(validforFlag, expected);
Assert.AreEqual(validforFlag, expected);
}
}
}

View File

@@ -9,14 +9,14 @@ using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class SmoQueryModelTests
{
[Fact]
[Test]
public void ShouldFindDatabaseQuerierFromRealPath()
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
@@ -25,53 +25,53 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database)));
// Then I expect to get back the SqlDatabaseQuerier
Assert.NotNull(querier);
Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType());
Assert.AreEqual(typeof(SqlDatabaseQuerier), querier.GetType());
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider);
}
[Fact]
[Test]
public void ShouldFindQuerierIfInExtensionList()
{
VerifyQuerierLookup(typeof(Table), typeof(SqlTableQuerier), expectExists: true);
}
[Fact]
[Test]
public void ShouldNotFindQuerierIfNotInExtensionList()
{
VerifyQuerierLookup(typeof(Database), null, expectExists: false);
}
[Fact]
[Test]
public void SqlServerDdlTriggerQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(ServerDdlTrigger));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
[Test]
public void SqlSynonymQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(Synonym));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
[Test]
public void SqlTriggerQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(Trigger));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
[Test]
public void SqlFullTextIndexQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(FullTextIndex));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
[Test]
public void TableValuedFunctionsIncludeInlineFunctions()
{
var tableFactory = new TableValuedFunctionsChildFactory();
@@ -106,7 +106,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
if (expectExists)
{
Assert.NotNull(querier);
Assert.Equal(querierType, querier.GetType());
Assert.AreEqual(querierType, querier.GetType());
Assert.NotNull(querier.ServiceProvider);
}
else

View File

@@ -5,26 +5,26 @@
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class UsersChildFactoryTests
{
[Fact]
[Test]
public void GetStatusShouldReturnEmptyStringGivenNull()
{
string expected = string.Empty;
string actual = UserCustomeNodeHelper.GetStatus(null);
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
[Fact]
[Test]
public void GetStatusShouldReturnEmptyStringGivenNotUser()
{
string expected = string.Empty;
string actual = UserCustomeNodeHelper.GetStatus(new Database());
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
}
}