Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
464 stars 493 forks source link

[feature request] Make DPS Queries testable #3439

Open Gamecock opened 7 months ago

Gamecock commented 7 months ago

https://github.com/Azure/azure-iot-sdk-csharp/blob/main/provisioning/service/src/Config/QueryResult.cs

The QueryResponseClass needs to be modifiable to allow testing of applications that query the DPS.

I'm happy to do the work, just looking for guidance on how you would like to proceed.

timtay-microsoft commented 6 months ago

Just to clarify, are you asking for this class to be mockable in the context of unit tests in your project that uses this SDK?

If so, I'd recommend adding an IQuery interface for the provisioningServiceClient.CreateEnrollmentGroupQuery and provisioningServiceClient.CreateEnrollmentGroupRegistrationStateQuery and provisioningServiceClient.CreateIndividualEnrollmentQuery to return instead of the concrete class Query they currently return. The interface will need to match the Query so it would look something like

public interface IQuery : IDisposable
{
    public int PageSize { get; set; }
    public string ContinuationToken { get; set; }

    public bool HasNext();
    public async Task<QueryResult> NextAsync(string continuationToken);
    public async Task<QueryResult> NextAsync();
}

Once that is checked into this repo, you should be able to make your provisioning service client return a mocked IQuery object that you have full control over.

Gamecock commented 6 months ago

Thanks, that what I was looking for.