Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: Unit testing SignalR Hubs may need updating #487

Open
1 of 3 tasks
BrennanConroy opened this issue Jun 21, 2022 · 0 comments
Open
1 of 3 tasks
Labels
7.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs

Comments

@BrennanConroy
Copy link
Member

Description

IHubClients and IHubCallerClients now hide interface members IClientProxy Client(string connectionId); and IClientProxy Caller { get; } with ISingleClientProxy Client(string connectionId); and ISingleClientProxy Caller { get; } in order to add support for client results.

This is not a breaking change to production code, unless you use reflection to call the above Client or Caller methods.

Version

.NET 7

Previous behavior

When using a testing library like Moq to unit test a SignalR Hub, you may write some code like follows:

var hub = new MyHub();
var mockCaller = new Mock<IHubCallerClients>();
var mockClientProxy = new Mock<IClientProxy>();
mockCaller.Setup(x => x.Caller).Returns(mockClientProxy.Object);
hub.Clients = mockCaller.Object;

class MyHub : Hub { }

New behavior

var hub = new MyHub();
var mockCaller = new Mock<IHubCallerClients>();
var mockClientProxy = new Mock<ISingleClientProxy>(); // <-- updated code
mockCaller.Setup(x => x.Caller).Returns(mockClientProxy.Object);
hub.Clients = mockCaller.Object;

class MyHub : Hub { }

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
  • Behavioral change: Existing code and binaries may experience different run-time behavior.

Reason for change

The change was made to add new functionality to SignalR and is non-breaking in normal use cases. The main area we see the change breaking is in test code which is easily updated.

Recommended action

Update test code to use the ISingleClientProxy interface when using reflection/reflection-based test code.

Affected APIs

IHubClients and IHubCallerClients

@aspnet aspnet locked and limited conversation to collaborators Jun 21, 2022
@gewarren gewarren added the Documented The breaking change has been published to the .NET Core docs label Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
7.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs
Projects
None yet
Development

No branches or pull requests

2 participants