-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in composite handler managera and added unit tests (#316)
- Loading branch information
1 parent
0b9e85d
commit 1497f35
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Reactive.Disposables; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using OmniSharp.Extensions.JsonRpc; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace JsonRpc.Tests | ||
{ | ||
public class CompositeHandlersManagerTests : AutoTestBase | ||
{ | ||
public CompositeHandlersManagerTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Handler_Instance_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add(Substitute.For<IJsonRpcHandler>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<string>(), Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add(Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Named_Handler_Instance_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<string>(), Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add("mymethod", Substitute.For<IJsonRpcHandler>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add("mymethod", Arg.Any<IJsonRpcHandler>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Handler_Factory_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add(Substitute.For<JsonRpcHandlerFactory>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<string>(), Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add(Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Named_Handler_Factory_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<string>(), Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add("mymethod", Substitute.For<JsonRpcHandlerFactory>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add("mymethod", Arg.Any<JsonRpcHandlerFactory>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Handler_Type_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add(Substitute.For<Type>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<string>(), Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add(Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Named_Handler_Type_To_Parent() | ||
{ | ||
var parent = Substitute.For<IHandlersManager>(); | ||
parent.Add(Arg.Any<string>(), Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()).Returns(Disposable.Empty); | ||
|
||
var manager = new CompositeHandlersManager(parent); | ||
manager.Add("mymethod", Substitute.For<Type>(), new JsonRpcHandlerOptions()); | ||
|
||
parent.Received(0).Add(Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
parent.Received(1).Add("mymethod", Arg.Any<Type>(), Arg.Any<JsonRpcHandlerOptions>()); | ||
manager.GetDisposable().Count.Should().Be(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters