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

@@ -7,13 +7,13 @@ using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
{
public class SqlTaskTests
{
[Fact]
[Test]
public void CreateSqlTaskGivenInvalidArgumentShouldThrowException()
{
DatabaseOperationStub operation = new DatabaseOperationStub();
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
Assert.Throws<ArgumentNullException>(() => new SqlTask(new TaskMetadata(), null, null));
}
[Fact]
[Test]
public void CreateSqlTaskShouldGenerateANewId()
{
SqlTask sqlTask = new SqlTask(new TaskMetadata(), new DatabaseOperationStub().FunctionToRun, null);
@@ -33,7 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
Assert.False(sqlTask.TaskId.CompareTo(sqlTask2.TaskId) == 0);
}
[Fact]
[Test]
public async Task RunShouldRunTheFunctionAndGetTheResult()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Succeeded;
@@ -43,20 +43,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
TaskStatus = expectedStatus
};
SqlTask sqlTask = new SqlTask(new TaskMetadata(), operation.FunctionToRun, null);
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.NotStarted);
Assert.AreEqual(SqlTaskStatus.NotStarted, sqlTask.TaskStatus);
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task => {
Assert.Equal(sqlTask.TaskStatus, expectedStatus);
Assert.Equal(sqlTask.IsCompleted, true);
Assert.AreEqual(sqlTask.TaskStatus, expectedStatus);
Assert.AreEqual(true, sqlTask.IsCompleted);
Assert.True(sqlTask.Duration > 0);
});
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.InProgress);
Assert.AreEqual(SqlTaskStatus.InProgress, sqlTask.TaskStatus);
Thread.Sleep(1000);
operation.Stop();
await taskToVerify;
}
[Fact]
[Test]
public async Task ToTaskInfoShouldReturnTaskInfo()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Succeeded;
@@ -74,15 +74,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
{
var taskInfo = sqlTask.ToTaskInfo();
Assert.Equal(taskInfo.TaskId, sqlTask.TaskId.ToString());
Assert.Equal(taskInfo.ServerName, "server name");
Assert.Equal(taskInfo.DatabaseName, "database name");
Assert.AreEqual(taskInfo.TaskId, sqlTask.TaskId.ToString());
Assert.AreEqual("server name", taskInfo.ServerName);
Assert.AreEqual("database name", taskInfo.DatabaseName);
});
operation.Stop();
await taskToVerify;
}
[Fact]
[Test]
public async Task FailedOperationShouldReturnTheFailedResult()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Failed;
@@ -92,20 +92,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
TaskStatus = expectedStatus
};
SqlTask sqlTask = new SqlTask(new TaskMetadata(), operation.FunctionToRun, operation.FunctionToCancel);
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.NotStarted);
Assert.AreEqual(SqlTaskStatus.NotStarted, sqlTask.TaskStatus);
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task => {
Assert.Equal(sqlTask.TaskStatus, expectedStatus);
Assert.Equal(sqlTask.IsCompleted, true);
Assert.AreEqual(sqlTask.TaskStatus, expectedStatus);
Assert.AreEqual(true, sqlTask.IsCompleted);
// Assert.True(sqlTask.Duration > 0);
});
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.InProgress);
Assert.AreEqual(SqlTaskStatus.InProgress, sqlTask.TaskStatus);
Thread.Sleep(1000);
operation.Stop();
await taskToVerify;
}
[Fact]
[Test]
public async Task CancelingTheTaskShouldCancelTheOperation()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Canceled;
@@ -114,20 +114,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
{
};
SqlTask sqlTask = new SqlTask(new TaskMetadata(), operation.FunctionToRun, operation.FunctionToCancel);
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.NotStarted);
Assert.AreEqual(SqlTaskStatus.NotStarted, sqlTask.TaskStatus);
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task => {
Assert.Equal(sqlTask.TaskStatus, expectedStatus);
Assert.Equal(sqlTask.IsCancelRequested, true);
Assert.AreEqual(sqlTask.TaskStatus, expectedStatus);
Assert.AreEqual(true, sqlTask.IsCancelRequested);
Assert.True(sqlTask.Duration > 0);
});
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.InProgress);
Assert.AreEqual(SqlTaskStatus.InProgress, sqlTask.TaskStatus);
Thread.Sleep(1000);
sqlTask.Cancel();
await taskToVerify;
}
[Fact]
[Test]
public async Task FailedOperationShouldFailTheTask()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Failed;
@@ -136,19 +136,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
{
};
SqlTask sqlTask = new SqlTask(new TaskMetadata(), operation.FunctionToRun, operation.FunctionToCancel);
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.NotStarted);
Assert.AreEqual(SqlTaskStatus.NotStarted, sqlTask.TaskStatus);
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task => {
Assert.Equal(sqlTask.TaskStatus, expectedStatus);
Assert.AreEqual(sqlTask.TaskStatus, expectedStatus);
Assert.True(sqlTask.Duration > 0);
});
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.InProgress);
Assert.AreEqual(SqlTaskStatus.InProgress, sqlTask.TaskStatus);
Thread.Sleep(1000);
operation.FailTheOperation();
await taskToVerify;
}
[Fact]
[Test]
public async Task RunScriptShouldReturnScriptContent()
{
SqlTaskStatus expectedStatus = SqlTaskStatus.Succeeded;
@@ -158,11 +158,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
TaskStatus = expectedStatus
};
SqlTask sqlTask = new SqlTask(new TaskMetadata(), operation.FunctionToScript, null);
Assert.Equal(sqlTask.TaskStatus, SqlTaskStatus.NotStarted);
Assert.AreEqual(SqlTaskStatus.NotStarted, sqlTask.TaskStatus);
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task => {
Assert.Equal(sqlTask.TaskStatus, expectedStatus);
Assert.Equal(sqlTask.IsCompleted, true);
Assert.AreEqual(sqlTask.TaskStatus, expectedStatus);
Assert.AreEqual(true, sqlTask.IsCompleted);
Assert.NotNull(operation.TaskScript);
Assert.True(!string.IsNullOrEmpty(operation.TaskScript.Script));
});

View File

@@ -6,7 +6,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
{
@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
DatabaseName = "database name"
};
[Fact]
[Test]
public void ManagerInstanceWithNoTaskShouldNotBreakOnCancelTask()
{
SqlTaskManager manager = new SqlTaskManager();
@@ -27,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
manager.CancelTask(Guid.NewGuid());
}
[Fact]
[Test]
public async Task VerifyCreateAndRunningTask()
{
using (SqlTaskManager manager = new SqlTaskManager())
@@ -60,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
}
[Fact]
[Test]
public async Task CancelTaskShouldCancelTheOperation()
{
using (SqlTaskManager manager = new SqlTaskManager())
@@ -76,8 +76,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
{
Assert.Equal(expectedStatus, sqlTask.TaskStatus);
Assert.Equal(sqlTask.IsCancelRequested, true);
Assert.AreEqual(expectedStatus, sqlTask.TaskStatus);
Assert.AreEqual(true, sqlTask.IsCancelRequested);
manager.Reset();
});
@@ -87,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
}
[Fact]
[Test]
public async Task VerifyScriptTask()
{
using (SqlTaskManager manager = new SqlTaskManager())

View File

@@ -13,7 +13,7 @@ using Microsoft.SqlTools.ServiceLayer.TaskServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
{
@@ -34,7 +34,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
service.InitializeService(serviceHostMock.Object);
}
[Fact]
[Test]
public async Task TaskListRequestErrorsIfParameterIsNull()
{
object errorResponse = null;
@@ -46,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
Assert.True(((string)errorResponse).Contains("ArgumentNullException"));
}
[Fact]
[Test]
public void NewTaskShouldSendNotification()
{
serviceHostMock.AddEventHandling(TaskCreatedNotification.Type, null);
@@ -64,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
It.Is<TaskProgressInfo>(t => t.TaskId == sqlTask.TaskId.ToString())), Times.AtLeastOnce());
}
[Fact]
[Test]
public async Task CancelTaskShouldCancelTheOperationAndSendNotification()
{
serviceHostMock.AddEventHandling(TaskCreatedNotification.Type, null);
@@ -93,7 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TaskServices
}
[Fact]
[Test]
public async Task TaskListTaskShouldReturnAllTasks()
{
serviceHostMock.AddEventHandling(TaskCreatedNotification.Type, null);