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

@@ -9,13 +9,13 @@ using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Hosting.Protocol.Channel;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
{
public class MessageDispatcherTests
{
[Fact]
[Test]
public void SetRequestHandlerWithOverrideTest()
{
RequestType<int, int> requestType = RequestType<int, int>.Create("test/requestType");
@@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
Assert.True(dispatcher.requestHandlers.Count > 0);
}
[Fact]
[Test]
public void SetEventHandlerTest()
{
EventType<int> eventType = EventType<int>.Create("test/eventType");
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
Assert.True(dispatcher.eventHandlers.Count > 0);
}
[Fact]
[Test]
public void SetEventHandlerWithOverrideTest()
{
EventType<int> eventType = EventType<int>.Create("test/eventType");
@@ -59,7 +59,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
Assert.True(dispatcher.eventHandlers.Count > 0);
}
[Fact]
[Test]
public void OnListenTaskCompletedFaultedTaskTest()
{
Task t = null;

View File

@@ -10,7 +10,7 @@ using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.Hosting.Protocol.Serializers;
using Newtonsoft.Json;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
{
@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
this.messageSerializer = new V8MessageSerializer();
}
[Fact]
[Test]
public void ReadsMessage()
{
MemoryStream inputStream = new MemoryStream();
@@ -38,12 +38,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Seek(0, SeekOrigin.Begin);
Message messageResult = messageReader.ReadMessage().Result;
Assert.Equal("testEvent", messageResult.Method);
Assert.AreEqual("testEvent", messageResult.Method);
inputStream.Dispose();
}
[Fact]
[Test]
public void ReadsManyBufferedMessages()
{
MemoryStream inputStream = new MemoryStream();
@@ -73,13 +73,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
for (int i = 0; i < overflowMessageCount; i++)
{
Message messageResult = messageReader.ReadMessage().Result;
Assert.Equal("testEvent", messageResult.Method);
Assert.AreEqual("testEvent", messageResult.Method);
}
inputStream.Dispose();
}
[Fact]
[Test]
public void ReadMalformedMissingHeaderTest()
{
using (MemoryStream inputStream = new MemoryStream())
@@ -93,13 +93,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
// Then:
// ... An exception should be thrown while reading
Assert.ThrowsAsync<ArgumentException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<ArgumentException>(() => messageReader.ReadMessage(), "An exception should be thrown while reading");
}
}
[Fact]
[Test]
public void ReadMalformedContentLengthNonIntegerTest()
{
using (MemoryStream inputStream = new MemoryStream())
@@ -113,13 +111,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
// Then:
// ... An exception should be thrown while reading
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage(), "An exception should be thrown while reading") ;
}
}
[Fact]
[Test]
public void ReadMissingContentLengthHeaderTest()
{
using (MemoryStream inputStream = new MemoryStream())
@@ -133,13 +129,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
// Then:
// ... An exception should be thrown while reading
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage(), "An exception should be thrown while reading");
}
}
[Fact]
[Test]
public void ReadMalformedContentLengthTooShortTest()
{
using (MemoryStream inputStream = new MemoryStream())
@@ -157,16 +151,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
// Then:
// ... The first read should fail with an exception while deserializing
Assert.ThrowsAsync<JsonReaderException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<JsonReaderException>(() => messageReader.ReadMessage(), "The first read should fail with an exception while deserializing");
// ... The second read should fail with an exception while reading headers
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<MessageParseException>(() => messageReader.ReadMessage(), "The second read should fail with an exception while reading headers");
}
}
[Fact]
[Test]
public void ReadMalformedThenValidTest()
{
// If:
@@ -183,18 +174,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
// Then:
// ... An exception should be thrown while reading the first one
Assert.ThrowsAsync<ArgumentException>(() => messageReader.ReadMessage()).Wait();
Assert.ThrowsAsync<ArgumentException>(() => messageReader.ReadMessage(), "An exception should be thrown while reading the first one");
// ... A test event should be successfully read from the second one
Message messageResult = messageReader.ReadMessage().Result;
Assert.NotNull(messageResult);
Assert.Equal("testEvent", messageResult.Method);
Assert.AreEqual("testEvent", messageResult.Method);
}
}
[Fact]
[Test]
public void ReaderResizesBufferForLargeMessages()
{
MemoryStream inputStream = new MemoryStream();
@@ -215,12 +204,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Seek(0, SeekOrigin.Begin);
Message messageResult = messageReader.ReadMessage().Result;
Assert.Equal("testEvent", messageResult.Method);
Assert.AreEqual("testEvent", messageResult.Method);
inputStream.Dispose();
}
[Fact]
[Test]
public void ReaderDoesNotModifyDateStrings()
{
MemoryStream inputStream = new MemoryStream();
@@ -240,7 +229,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
inputStream.Seek(0, SeekOrigin.Begin);
Message messageResult = messageReader.ReadMessage().Result;
Assert.Equal(dateString, messageResult.Contents.Value<string>("someString"));
Assert.AreEqual(dateString, messageResult.Contents.Value<string>("someString"));
inputStream.Dispose();
}

View File

@@ -10,7 +10,7 @@ using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.Hosting.Protocol.Serializers;
using Newtonsoft.Json.Linq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
{
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
this.messageSerializer = new V8MessageSerializer();
}
[Fact]
[Test]
public void SerializeMessageTest()
{
// serialize\deserialize a request
@@ -35,29 +35,29 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
var serializedMessage = this.messageSerializer.SerializeMessage(message);
Assert.NotNull(serializedMessage);
var deserializedMessage = this.messageSerializer.DeserializeMessage(serializedMessage);
Assert.Equal(message.Id, deserializedMessage.Id);
Assert.AreEqual(message.Id, deserializedMessage.Id);
// serialize\deserialize a response
message.MessageType = MessageType.Response;
serializedMessage = this.messageSerializer.SerializeMessage(message);
Assert.NotNull(serializedMessage);
deserializedMessage = this.messageSerializer.DeserializeMessage(serializedMessage);
Assert.Equal(message.Id, deserializedMessage.Id);
Assert.AreEqual(message.Id, deserializedMessage.Id);
// serialize\deserialize a response with an error
message.Error = JToken.FromObject("error");
serializedMessage = this.messageSerializer.SerializeMessage(message);
Assert.NotNull(serializedMessage);
deserializedMessage = this.messageSerializer.DeserializeMessage(serializedMessage);
Assert.Equal(message.Error, deserializedMessage.Error);
Assert.AreEqual(message.Error, deserializedMessage.Error);
// serialize\deserialize an unknown response type
serializedMessage.Remove("type");
serializedMessage.Add("type", JToken.FromObject("dontknowthisone"));
Assert.Equal(this.messageSerializer.DeserializeMessage(serializedMessage).MessageType, MessageType.Unknown);
Assert.AreEqual(MessageType.Unknown, this.messageSerializer.DeserializeMessage(serializedMessage).MessageType);
}
[Fact]
[Test]
public async Task WritesMessage()
{
MemoryStream outputStream = new MemoryStream();
@@ -74,14 +74,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
byte[] buffer = new byte[128];
await outputStream.ReadAsync(buffer, 0, expectedHeaderString.Length);
Assert.Equal(
Assert.AreEqual(
expectedHeaderString,
Encoding.ASCII.GetString(buffer, 0, expectedHeaderString.Length));
// Read the message
await outputStream.ReadAsync(buffer, 0, Common.ExpectedMessageByteCount);
Assert.Equal(Common.TestEventString,
Assert.AreEqual(Common.TestEventString,
Encoding.UTF8.GetString(buffer, 0, Common.ExpectedMessageByteCount));
outputStream.Dispose();