mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-21 01:25:42 -05:00
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:
@@ -10,15 +10,16 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MessageWriterTests
|
||||
{
|
||||
#region Construction Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructMissingOutputStream()
|
||||
{
|
||||
// If: I attempt to create a message writer without an output stream
|
||||
@@ -30,17 +31,16 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
|
||||
#region WriteMessageTests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task WriteMessageNullMessage()
|
||||
{
|
||||
// If: I write a null message
|
||||
// Then: I should get an exception
|
||||
var mw = new MessageWriter(Stream.Null);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => mw.WriteMessage(null));
|
||||
var mw = new MessageWriter(Stream.Null);
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => mw.WriteMessage(null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(WriteMessageData))]
|
||||
[TestCaseSource(nameof(WriteMessageData))]
|
||||
public async Task WriteMessage(object contents, Dictionary<string, object> expectedDict)
|
||||
{
|
||||
// NOTE: This technically tests the ability of the Message class to properly serialize
|
||||
@@ -53,11 +53,11 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
{
|
||||
// If: I write a message
|
||||
var mw = new MessageWriter(outputStream);
|
||||
await mw.WriteMessage(Message.CreateResponse(CommonObjects.MessageId, contents));
|
||||
|
||||
// Then:
|
||||
// ... The returned bytes on the stream should compose a valid message
|
||||
Assert.NotEqual(0, outputStream.Position);
|
||||
await mw.WriteMessage(Message.CreateResponse(CommonObjects.MessageId, contents));
|
||||
|
||||
// Then:
|
||||
// ... The returned bytes on the stream should compose a valid message
|
||||
Assert.That(outputStream.Position, Is.Not.EqualTo(0), "outputStream.Position after WriteMessage");
|
||||
var messageDict = ValidateMessageHeaders(output, (int) outputStream.Position);
|
||||
|
||||
// ... ID, Params, Method should be present
|
||||
@@ -97,12 +97,12 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
expectedDict.Add("jsonrpc", "2.0");
|
||||
|
||||
// Make sure the number of elements in both dictionaries are the same
|
||||
Assert.Equal(expectedDict.Count, messageDict.Count);
|
||||
Assert.AreEqual(expectedDict.Count, messageDict.Count);
|
||||
|
||||
// Make sure the elements match
|
||||
foreach (var kvp in expectedDict)
|
||||
{
|
||||
Assert.Equal(expectedDict[kvp.Key], messageDict[kvp.Key]);
|
||||
Assert.AreEqual(expectedDict[kvp.Key], messageDict[kvp.Key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,11 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
|
||||
// There should be two sections to the message
|
||||
string[] outputParts = outputString.Split("\r\n\r\n");
|
||||
Assert.Equal(2, outputParts.Length);
|
||||
Assert.AreEqual(2, outputParts.Length);
|
||||
|
||||
// The first section is the headers
|
||||
string[] headers = outputParts[0].Split("\r\n");
|
||||
Assert.Equal(2, outputParts.Length);
|
||||
Assert.AreEqual(2, outputParts.Length);
|
||||
|
||||
// There should be a content-type and a content-length
|
||||
int? contentLength = null;
|
||||
@@ -126,7 +126,7 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
{
|
||||
// Headers should look like "Header-Key: HeaderValue"
|
||||
string[] headerParts = header.Split(':');
|
||||
Assert.Equal(2, headerParts.Length);
|
||||
Assert.AreEqual(2, headerParts.Length);
|
||||
|
||||
string headerKey = headerParts[0];
|
||||
string headerValue = headerParts[1].Trim();
|
||||
@@ -147,7 +147,7 @@ namespace Microsoft.SqlTools.Hosting.UnitTests.ProtocolTests
|
||||
|
||||
// Make sure the headers are correct
|
||||
Assert.True(contentTypeCorrect);
|
||||
Assert.Equal(outputParts[1].Length, contentLength);
|
||||
Assert.AreEqual(outputParts[1].Length, contentLength);
|
||||
|
||||
// Deserialize the body into a dictionary
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, object>>(outputParts[1]);
|
||||
|
||||
Reference in New Issue
Block a user