configcat / .net-sdk

ConfigCat SDK for .NET. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/csharp
Other
29 stars 8 forks source link

Change IConfigCatClient.Snapshot() to return IConfigCatClientSnapshot #92

Closed brian-knoll-micronetonline closed 3 months ago

brian-knoll-micronetonline commented 3 months ago

Is your feature request related to a problem? Please describe.

I am having increased difficulty testing my code that uses IConfigCatClient.Snapshot()

Describe the solution you'd like

Change IConfigCatClient.Snapshot() to return IConfigCatClientSnapshot

Describe alternatives you've considered

Testing in a way that does not Moq the result of Snapshot

Additional context

Seems like an oversight as this project seems to use interfaces in plenty of places already

adams85 commented 3 months ago

Hey @brian-knoll-micronetonline,

Seems like an oversight as this project seems to use interfaces in plenty of places already

It's not an oversight, it was a deliberate design choice to make the result type of IConfigCatClient.Snapshot() a value type, for performance considerations (to avoid heap memory allocation).

The ConfigCatClientSnapshot type, however, provides a constructor that takes an IConfigCatClientSnapshot object as its parameter. This should allow you to provide a fake implementation for testing purposes.

Does this work for you? If not, what difficulties do you experience exactly with your tests?

brian-knoll-micronetonline commented 3 months ago

That works for my use case thank you