using System.Linq; using System.Threading; using System.Threading.Tasks; using AMWD.Net.Api.Cloudflare; using AMWD.Net.Api.Cloudflare.Zones; using Moq; using Newtonsoft.Json.Linq; namespace Cloudflare.Zones.Tests.ZoneRegistrar { [TestClass] public class GetDomainTest { private const string AccountId = "023e105f4ecef8ad9ca31a8372d0c353"; private const string DomainName = "example.com"; private Mock _clientMock; private CloudflareResponse _response; private List<(string RequestPath, IQueryParameterFilter QueryFilter)> _callbacks; [TestInitialize] public void Initialize() { _callbacks = []; _response = new CloudflareResponse(); } [TestMethod] public async Task ShouldGetRegistrarDomain() { // Arrange var client = GetClient(); // Act var result = await client.GetDomain(AccountId, DomainName); // Assert Assert.AreEqual(_response, result); Assert.AreEqual(1, _callbacks.Count); var callback = _callbacks.First(); Assert.AreEqual($"/accounts/{AccountId}/registrar/domains/{DomainName}", callback.RequestPath); Assert.IsNull(callback.QueryFilter); _clientMock.Verify(m => m.GetAsync($"/accounts/{AccountId}/registrar/domains/{DomainName}", null, It.IsAny()), Times.Once); _clientMock.VerifyNoOtherCalls(); } [DataTestMethod] [DataRow(null)] [DataRow("")] [DataRow(" ")] [ExpectedException(typeof(ArgumentNullException))] public async Task ShouldThrowArgumentNullExceptionOnDomainName(string domainName) { // Arrange var client = GetClient(); // Act var result = await client.GetDomain(AccountId, domainName); // Assert - ArgumentNullException } private ICloudflareClient GetClient() { _clientMock = new Mock(); _clientMock .Setup(m => m.GetAsync(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((requestPath, queryFilter, _) => _callbacks.Add((requestPath, queryFilter))) .ReturnsAsync(() => _response); return _clientMock.Object; } } }