optimizely / csharp-sdk

.NET based C# SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/csharp-sdk
Apache License 2.0
19 stars 20 forks source link

OptimizelyUserContext should implement an interface for mockability #289

Closed brcpar closed 2 years ago

brcpar commented 2 years ago

Similar to how Optimizely implements IOptimizely, OptimizelyUserContext should also implement an interface so that consumers of your SDK can properly mock it for unit testing.

I think it would be a fairly small change.

  1. Add an IOptimizelyUserContext interface.
  2. Implement that interface in the OptimizelyUserContext class.
  3. Update OptimizelyUserContext constructor to accept an IOptimizely instance instead of an Optimizely instance.
  4. Update the CreateUserContext method signature to return this new interface rather than the actual type.

All actual implementations remain the same.

dustin-sier commented 2 years ago

Wanted to let you know that we've actually got a release coming out shortly that addresses just this.

Link to the pull request: https://github.com/optimizely/csharp-sdk/pull/280