Namecheap-dot-net
Namecheap-dot-net copied to clipboard
Add interface to allow for mocking
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 interfaceIDomainsApi
(or isINameCheapDomainsApi
more explicit?) - [ ]
DnsApi
, idem, and should implementIDnsApi
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) { ... }