public async Task TestGetCustomHostnamesAsync() { var displayOptions = new DisplayOptions { Page = 1, PerPage = 20, Order = OrderType.Asc }; var filtering = new CustomHostnameFilter { CustomHostnameId = CustomHostnameTestData.CustomHostnames.First().Id }; var zone = ZoneTestData.Zones.First(); _wireMockServer .Given(Request.Create() .WithPath($"/{ZoneEndpoints.Base}/{zone.Id}/{CustomHostnameEndpoints.Base}/") .WithParam(Filtering.Page) .WithParam(Filtering.PerPage) .WithParam(Filtering.Direction) .WithParam(Filtering.Id) .UsingGet()) .RespondWith(Response.Create().WithStatusCode(200) .WithBody(WireMockResponseHelper.CreateTestResponse(CustomHostnameTestData.CustomHostnames))); using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo); var customHostnames = await client.Zones.CustomHostnames.GetAsync(zone.Id, filtering, displayOptions); customHostnames.Result.Should().BeEquivalentTo(CustomHostnameTestData.CustomHostnames); }
/// <inheritdoc /> public async Task <CloudFlareResult <IReadOnlyList <CustomHostname> > > GetAsync(string zoneId, CustomHostnameFilter filter = null, DisplayOptions displayOptions = null, CancellationToken cancellationToken = default) { var builder = new ParameterBuilderHelper(); builder .InsertValue(Filtering.Id, filter?.CustomHostnameId) .InsertValue(Filtering.Hostname, filter?.Hostname) .InsertValue(Filtering.Order, filter?.OrderType) .InsertValue(Filtering.Ssl, filter?.Ssl ?? false ? 1 : 0) .InsertValue(Filtering.Page, displayOptions?.Page) .InsertValue(Filtering.PerPage, displayOptions?.PerPage) .InsertValue(Filtering.Direction, displayOptions?.Order); var requestUri = $"{ZoneEndpoints.Base}/{zoneId}/{CustomHostnameEndpoints.Base}"; if (builder.ParameterCollection.HasKeys()) { requestUri = $"{requestUri}/?{builder.ParameterCollection}"; } return(await Connection.GetAsync <IReadOnlyList <CustomHostname> >(requestUri, cancellationToken).ConfigureAwait(false)); }