-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dicky
authored and
dicky
committed
Dec 30, 2017
1 parent
7bc5c95
commit 9ab1db8
Showing
5 changed files
with
470 additions
and
14 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
ASP.NET Core Demo/UnitTests/HubDisconnectionMiddlewareTest.cs
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,59 @@ | ||
using Microsoft.AspNetCore.SignalR; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Threading.Tasks; | ||
using DotNetify; | ||
|
||
namespace UnitTests | ||
{ | ||
[TestClass] | ||
public class HubDisonnectionMiddlewareTest | ||
{ | ||
private class TestVM : BaseVM | ||
{ | ||
public string Property { get; set; } | ||
} | ||
|
||
private class CustomMiddleware : IDisconnectionMiddleware | ||
{ | ||
public event EventHandler<HubCallerContext> Invoked; | ||
|
||
public Task OnDisconnected(HubCallerContext context) | ||
{ | ||
Invoked?.Invoke(this, context); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
private CustomMiddleware _middleware; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
_middleware = new CustomMiddleware(); | ||
VMController.CreateInstance = (type, args) => type == typeof(CustomMiddleware) ? _middleware : Activator.CreateInstance(type, args); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
VMController.CreateInstance = (type, args) => Activator.CreateInstance(type, args); | ||
} | ||
|
||
[TestMethod] | ||
public void DisconnectionMiddleware_DisconnectionIntercepted() | ||
{ | ||
VMController.Register<TestVM>(); | ||
var hub = new MockDotNetifyHub() | ||
.UseMiddleware<CustomMiddleware>() | ||
.Create(); | ||
|
||
bool middlewareInvoked = false; | ||
_middleware.Invoked += (sender, e) => middlewareInvoked = true; | ||
|
||
hub.RequestVM(nameof(TestVM)); | ||
hub.OnDisconnected(); | ||
Assert.IsTrue(middlewareInvoked); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.