Namecheap-dot-net icon indicating copy to clipboard operation
Namecheap-dot-net copied to clipboard

Add interface to allow for mocking

Open philipmat opened this issue 5 years ago • 0 comments

NameCheapApi, or at a minimum the properties it returns, should implement interfaces in order to allow the API to be mocked for testing purposes.

  • [ ] DomainsApi should be made internal and implement public interface IDomainsApi (or is INameCheapDomainsApi more explicit?)
  • [ ] DnsApi, idem, and should implement IDnsApi

The advantage of making NameCheapApi also mockable is that it would allow a single, top-level point of mocking and DI. However, in practice, this can be handled within DI containers via services.

For example, for AutoFac:

// registration
var api = new NameCheapApi(...params...);
builder.RegisterInstance(api).As<NameCheapApi>();
builder.Register(c => c.Resolve<NameCheapApi>().Domains).As<IDomainsApi>();

// code
.ctor(IDomainsApi domainsApi) { ... }

philipmat avatar Apr 07 '19 18:04 philipmat