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

@@ -8,15 +8,16 @@ using System.Collections.Concurrent;
using System.Linq;
using Microsoft.SqlTools.Hosting.Contracts.Internal;
using Microsoft.SqlTools.Hosting.Protocol;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
{
[TestFixture]
public class RequestContextTests
{
#region Send Tests
[Fact]
[Test]
public void SendResult()
{
// Setup: Create a blocking collection to collect the output
@@ -26,12 +27,10 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
var rc = new RequestContext<CommonObjects.TestMessageContents>(CommonObjects.RequestMessage, bc);
rc.SendResult(CommonObjects.TestMessageContents.DefaultInstance);
// Then: The message writer should have sent a response
Assert.Single(bc);
Assert.Equal(MessageType.Response, bc.First().MessageType);
Assert.That(bc.Select(m => m.MessageType), Is.EqualTo(new[] { MessageType.Response }), "The message writer should have sent a response");
}
[Fact]
[Test]
public void SendEvent()
{
// Setup: Create a blocking collection to collect the output
@@ -39,14 +38,12 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
// If: I write an event with the request context
var rc = new RequestContext<CommonObjects.TestMessageContents>(CommonObjects.RequestMessage, bc);
rc.SendEvent(CommonObjects.EventType, CommonObjects.TestMessageContents.DefaultInstance);
// Then: The message writer should have sent an event
Assert.Single(bc);
Assert.Equal(MessageType.Event, bc.First().MessageType);
rc.SendEvent(CommonObjects.EventType, CommonObjects.TestMessageContents.DefaultInstance);
Assert.That(bc.Select(m => m.MessageType), Is.EqualTo(new[] { MessageType.Event }), "The message writer should have sent an event");
}
[Fact]
[Test]
public void SendError()
{
// Setup: Create a blocking collection to collect the output
@@ -56,20 +53,17 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
// If: I write an error with the request context
var rc = new RequestContext<CommonObjects.TestMessageContents>(CommonObjects.RequestMessage, bc);
rc.SendError(errorMessage, errorCode);
// Then:
// ... The message writer should have sent an error
Assert.Single(bc);
Assert.Equal(MessageType.ResponseError, bc.First().MessageType);
// ... The error object it built should have the reuired fields set
rc.SendError(errorMessage, errorCode);
Assert.That(bc.Select(m => m.MessageType), Is.EqualTo(new[] { MessageType.ResponseError }), "The message writer should have sent an error");
// ... The error object it built should have the reuired fields set
var contents = bc.ToArray()[0].GetTypedContents<Error>();
Assert.Equal(errorCode, contents.Code);
Assert.Equal(errorMessage, contents.Message);
Assert.AreEqual(errorCode, contents.Code);
Assert.AreEqual(errorMessage, contents.Message);
}
[Fact]
[Test]
public void SendException()
{
// Setup: Create a blocking collection to collect the output
@@ -79,18 +73,14 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
const string errorMessage = "error";
var e = new Exception(errorMessage);
var rc = new RequestContext<CommonObjects.TestMessageContents>(CommonObjects.RequestMessage, bc);
rc.SendError(e);
// Then:
// ... The message writer should have sent an error
Assert.Single(bc);
var firstMessage = bc.First();
Assert.Equal(MessageType.ResponseError, firstMessage.MessageType);
// ... The error object it built should have the reuired fields set
var contents = firstMessage.GetTypedContents<Error>();
Assert.Equal(e.HResult, contents.Code);
Assert.Equal(errorMessage, contents.Message);
rc.SendError(e);
Assert.That(bc.Select(m => m.MessageType), Is.EqualTo(new[] { MessageType.ResponseError }), "The message writer should have sent an error");
// ... The error object it built should have the reuired fields set
var contents = bc.First().GetTypedContents<Error>();
Assert.AreEqual(e.HResult, contents.Code);
Assert.AreEqual(errorMessage, contents.Message);
}