Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 123 forks source link

[QUERY] C# - How can I work with CollectionQueryResult<T> in unit tests? #205

Open ahoke-cr opened 2 years ago

ahoke-cr commented 2 years ago

Query/Question

I want to unit test my platform's services that interact with Azure Notification Hubs. I am currently attempting to write a test that deregisters a user's device using a tag identifying that user's registrations. To delete registrations, I need to get a CollectionQueryResult<RegistrationDescription> which is returned from INotificationHubClient.GetRegistrationsByTagAsync(string). CollectionQueryResult<T> has only one constructor which is internal, so I cannot initialize my own instance. As such, I am attempting to cast an IEnumerable<RegistrationDescription> via as to this type, which fails. I am using Moq and testing with Xunit.

Why is this not a Bug or a feature Request?

CollectionQueryResult<T> is sealed and has an internal constructor for some reason unbeknownst to me. I can only presume this was an intentional design decision and not an oversight.

Setup (please complete the following information if applicable):

OS: Windows 10 20H2 19042.1348 IDE: Visual Studio 2019 16.11.5 NuGet: Microsoft.Azure.NotificationHubs version 4.1.0

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

mpodwysocki commented 2 years ago

@ahoke-cr good suggestion and we should make it an interface instead of a concrete type. Thanks for the input.

ahoke-cr commented 2 years ago

@mpodwysocki Thanks for the reply! We eagerly await such an update :)

YoupHulsebos commented 2 years ago

I'm also eagerly awaiting such an update :) good to see the changes have already been merged. Is there an estimation on when a (prerelease) package wil be available on nuget?

chrisfcarroll commented 2 years ago

Hi, Is there some process for moving the Merged PR forwards to a Nuget release? Other PRs have been released since this was merged. Thanks, Chris

ahoke-cr commented 2 years ago

@chrisfcarroll it looks like, according to the latest (4.1.1) release source code zip archive, this change was included though not documented in the release notes.

chrisfcarroll commented 2 years ago

Thx for noticing that, I can raise a separate issue for publishing 4.1.1 to NuGet (the latest NuGet version is 2½ years ago)

ysbakker commented 1 year ago

Reviving this issue, hopefully this change will still be included in the library at some point. This would hugely improve testability.