mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 17:24:00 -05:00
Add tests to improve code coverage (#187)
* DbColumn and ReliableConnection tests * More retry connection tests * More tests * Fix broken peek definition integration tests * Fix test bug * Add a couple batch tests * Add some more tests * More tests for code coverage. * Validation and Diagnostic tests * A few more tests * A few mote test changes. * Update file path tests to run on Windows only
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
||||
{
|
||||
public class MessageDispatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void SetRequestHandlerWithOverrideTest()
|
||||
{
|
||||
RequestType<int, int> requestType = RequestType<int, int>.Create("test/requestType");
|
||||
var dispatcher = new MessageDispatcher(new Mock<ChannelBase>().Object);
|
||||
dispatcher.SetRequestHandler<int, int>(
|
||||
requestType,
|
||||
(i, j) =>
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
},
|
||||
true);
|
||||
Assert.True(dispatcher.requestHandlers.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetEventHandlerTest()
|
||||
{
|
||||
EventType<int> eventType = EventType<int>.Create("test/eventType");
|
||||
var dispatcher = new MessageDispatcher(new Mock<ChannelBase>().Object);
|
||||
dispatcher.SetEventHandler<int>(
|
||||
eventType,
|
||||
(i, j) =>
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
Assert.True(dispatcher.eventHandlers.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetEventHandlerWithOverrideTest()
|
||||
{
|
||||
EventType<int> eventType = EventType<int>.Create("test/eventType");
|
||||
var dispatcher = new MessageDispatcher(new Mock<ChannelBase>().Object);
|
||||
dispatcher.SetEventHandler<int>(
|
||||
eventType,
|
||||
(i, j) =>
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
},
|
||||
true);
|
||||
Assert.True(dispatcher.eventHandlers.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnListenTaskCompletedFaultedTaskTest()
|
||||
{
|
||||
Task t = null;
|
||||
|
||||
try
|
||||
{
|
||||
t = Task.Run(() =>
|
||||
{
|
||||
throw new Exception();
|
||||
});
|
||||
t.Wait();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
bool handlerCalled = false;
|
||||
var dispatcher = new MessageDispatcher(new Mock<ChannelBase>().Object);
|
||||
dispatcher.UnhandledException += (s, e) => handlerCalled = true;
|
||||
dispatcher.OnListenTaskCompleted(t);
|
||||
Assert.True(handlerCalled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user