using System.Linq; using System.Threading; using System.Threading.Tasks; using AMWD.Net.Api.Cloudflare; using AMWD.Net.Api.Cloudflare.Dns; using Moq; namespace Cloudflare.Dns.Tests.CustomNameserversExtensions { [TestClass] public class ListCustomNameserverTest { public TestContext TestContext { get; set; } private const string AccountId = "023e105f4ecef8ad9ca31a8372d0c353"; private Mock _clientMock; private CloudflareResponse> _response; private List<(string RequestPath, IQueryParameterFilter QueryFilter)> _callbacks; [TestInitialize] public void Initialize() { _callbacks = []; _response = new CloudflareResponse> { Success = true, Messages = [ new ResponseInfo(1000, "Message 1") ], Errors = [ new ResponseInfo(1000, "Error 1") ], Result = [] }; } [TestMethod] public async Task ShouldListCustomNameserver() { // Arrange var client = GetClient(); // Act var response = await client.ListCustomNameserver(AccountId, TestContext.CancellationToken); // Assert Assert.IsNotNull(response); Assert.IsTrue(response.Success); Assert.AreEqual(_response.Result, response.Result); Assert.HasCount(1, _callbacks); var (requestPath, queryFilter) = _callbacks.First(); Assert.AreEqual($"/accounts/{AccountId}/custom_ns", requestPath); Assert.IsNull(queryFilter); _clientMock.Verify(m => m.GetAsync>($"/accounts/{AccountId}/custom_ns", null, TestContext.CancellationToken), Times.Once); _clientMock.VerifyNoOtherCalls(); } 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; } } }