Changed folder structure, added explicit nullable for extensions.
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests
|
||||
{
|
||||
internal class PurgeRequest
|
||||
{
|
||||
[JsonProperty("purge_everything")]
|
||||
public bool? PurgeEverything { get; set; }
|
||||
|
||||
[JsonProperty("tags")]
|
||||
public IList<string> Tags { get; set; }
|
||||
|
||||
[JsonProperty("hosts")]
|
||||
public IList<string> Hostnames { get; set; }
|
||||
|
||||
[JsonProperty("prefixes")]
|
||||
public IList<string> Prefixes { get; set; }
|
||||
|
||||
[JsonProperty("files")]
|
||||
public IList<string> Urls { get; set; }
|
||||
|
||||
[JsonProperty("files")]
|
||||
public IList<UrlWithHeaders> UrlsWithHeaders { get; set; }
|
||||
}
|
||||
}
|
||||
42
Extensions/Cloudflare.Zones/Enums/NameserverType.cs
Normal file
42
Extensions/Cloudflare.Zones/Enums/NameserverType.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// The nameserver type.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum NameserverType
|
||||
{
|
||||
/// <summary>
|
||||
/// Cloudflare standard.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "cloudflare.standard")]
|
||||
CloudflareStandard = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Cloudflare random.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "cloudflare.standard.random")]
|
||||
CloudflareRandom = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Custom specified by account.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "custom.account")]
|
||||
CustomAccount = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Custom specified by tenant.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "custom.tenant")]
|
||||
CustomTenant = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Custom specified by zone.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "custom.zone")]
|
||||
CustomZone = 5,
|
||||
}
|
||||
}
|
||||
30
Extensions/Cloudflare.Zones/Enums/ZoneMode.cs
Normal file
30
Extensions/Cloudflare.Zones/Enums/ZoneMode.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Zone modes.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum ZoneMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Standard.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "standard")]
|
||||
Standard = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Only as CDN.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "cdn_only")]
|
||||
CdnOnly = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Only as DNS.
|
||||
/// </summary>
|
||||
[EnumMember(Value = "dns_only")]
|
||||
DnsOnly = 3,
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Newtonsoft.Json.Converters;
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Field to order zones by.
|
||||
/// Possible fields to order zones by.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum ZonesOrderBy
|
||||
@@ -12,7 +12,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// An account ID.
|
||||
/// </summary>
|
||||
/// <value>account.id</value>
|
||||
public string AccountId { get; set; }
|
||||
public string? AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An account Name.
|
||||
@@ -33,19 +33,19 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <example>Dev Account</example>
|
||||
/// <example>contains:Test</example>
|
||||
/// <value>account.name</value>
|
||||
public string AccountName { get; set; }
|
||||
public string? AccountName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Direction to order zones.
|
||||
/// </summary>
|
||||
/// <value>direction</value>
|
||||
public SortDirection? OrderDirection { get; set; }
|
||||
public SortDirection? Direction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to match all search requirements or at least one (any).
|
||||
/// </summary>
|
||||
/// <value>match</value>
|
||||
public FilterMatchType? MatchType { get; set; }
|
||||
public FilterMatchType? Match { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A domain name.
|
||||
@@ -68,7 +68,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <example>ends_with:arpa</example>
|
||||
/// <example>starts_with:dev</example>
|
||||
/// <value>name</value>
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Field to order zones by.
|
||||
@@ -99,17 +99,19 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
|
||||
#pragma warning disable CS8602, CS8604 // There will be no null value below.
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(AccountId))
|
||||
dict.Add("account.id", AccountId);
|
||||
dict.Add("account.id", AccountId.Trim());
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(AccountName))
|
||||
dict.Add("account.name", AccountName);
|
||||
dict.Add("account.name", AccountName.Trim());
|
||||
|
||||
if (OrderDirection.HasValue && Enum.IsDefined(typeof(SortDirection), OrderDirection.Value))
|
||||
dict.Add("direction", OrderDirection.Value.GetEnumMemberValue());
|
||||
if (Direction.HasValue && Enum.IsDefined(typeof(SortDirection), Direction.Value))
|
||||
dict.Add("direction", Direction.Value.GetEnumMemberValue());
|
||||
|
||||
if (MatchType.HasValue && Enum.IsDefined(typeof(FilterMatchType), MatchType.Value))
|
||||
dict.Add("match", MatchType.Value.GetEnumMemberValue());
|
||||
if (Match.HasValue && Enum.IsDefined(typeof(FilterMatchType), Match.Value))
|
||||
dict.Add("match", Match.Value.GetEnumMemberValue());
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Name))
|
||||
dict.Add("name", Name);
|
||||
@@ -126,6 +128,8 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (Status.HasValue && Enum.IsDefined(typeof(ZoneStatus), Status.Value))
|
||||
dict.Add("status", Status.Value.GetEnumMemberValue());
|
||||
|
||||
#pragma warning restore CS8602, CS8604
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Filters
|
||||
{
|
||||
internal class CreateZoneHoldFilter : IQueryParameterFilter
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Filters
|
||||
{
|
||||
internal class DeleteZoneHoldFilter : IQueryParameterFilter
|
||||
{
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Requests
|
||||
{
|
||||
internal class InternalCreateZoneRequest
|
||||
{
|
||||
public InternalCreateZoneRequest(AccountBase account, string name)
|
||||
{
|
||||
Account = account;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
[JsonProperty("account")]
|
||||
public AccountBase Account { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public ZoneType? Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Requests
|
||||
{
|
||||
internal class InternalEditZoneRequest
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public ZoneType? Type { get; set; }
|
||||
|
||||
[JsonProperty("vanity_name_servers")]
|
||||
public IList<string>? VanityNameServers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Requests
|
||||
{
|
||||
internal class InternalPurgeCacheRequest
|
||||
{
|
||||
[JsonProperty("purge_everything")]
|
||||
public bool? PurgeEverything { get; set; }
|
||||
|
||||
[JsonProperty("tags")]
|
||||
public IList<string>? Tags { get; set; }
|
||||
|
||||
[JsonProperty("hosts")]
|
||||
public IList<string>? Hostnames { get; set; }
|
||||
|
||||
[JsonProperty("prefixes")]
|
||||
public IList<string>? Prefixes { get; set; }
|
||||
|
||||
[JsonProperty("files")]
|
||||
public IList<string>? Urls { get; set; }
|
||||
|
||||
[JsonProperty("files")]
|
||||
public IList<PurgeUrlWithHeaders>? UrlsWithHeaders { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Requests
|
||||
{
|
||||
internal class InternalUpdateDnsSettingsRequest
|
||||
{
|
||||
[JsonProperty("flatten_all_cnames")]
|
||||
public bool? FlattenAllCnames { get; set; }
|
||||
|
||||
[JsonProperty("foundation_dns")]
|
||||
public bool? FoundationDns { get; set; }
|
||||
|
||||
[JsonProperty("multi_provider")]
|
||||
public bool? MultiProvider { get; set; }
|
||||
|
||||
[JsonProperty("nameservers")]
|
||||
public Nameserver? Nameservers { get; set; }
|
||||
|
||||
[JsonProperty("ns_ttl")]
|
||||
public int? NameserverTtl { get; set; }
|
||||
|
||||
[JsonProperty("secondary_overrides")]
|
||||
public bool? SecondaryOverrides { get; set; }
|
||||
|
||||
[JsonProperty("soa")]
|
||||
public StartOfAuthority? Soa { get; set; }
|
||||
|
||||
[JsonProperty("zone_mode")]
|
||||
public ZoneMode? Mode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Internals.Requests
|
||||
{
|
||||
internal class UrlWithHeaders
|
||||
internal class PurgeUrlWithHeaders
|
||||
{
|
||||
[JsonProperty("headers")]
|
||||
public Dictionary<string, string> Headers { get; set; } = [];
|
||||
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
}
|
||||
22
Extensions/Cloudflare.Zones/Models/Nameserver.cs
Normal file
22
Extensions/Cloudflare.Zones/Models/Nameserver.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// A nameserver.
|
||||
/// </summary>
|
||||
public class Nameserver
|
||||
{
|
||||
/// <summary>
|
||||
/// The nameserver type.
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public virtual NameserverType Type { get; set; }
|
||||
|
||||
// TODO: DEPRECATED? - not available on API request.
|
||||
///// <summary>
|
||||
///// Configured nameserver set to be used for this zone.
|
||||
///// </summary>
|
||||
///// <value>Range: <c>1 <=</c> X <c><= 5</c></value>
|
||||
//[JsonProperty("ns_set")]
|
||||
//public virtual int NameserverSet { get; set; }
|
||||
}
|
||||
}
|
||||
83
Extensions/Cloudflare.Zones/Models/StartOfAuthority.cs
Normal file
83
Extensions/Cloudflare.Zones/Models/StartOfAuthority.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// The SOA (Start of Authority) record.
|
||||
/// </summary>
|
||||
public class StartOfAuthority
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartOfAuthority"/> class.
|
||||
/// </summary>
|
||||
/// <param name="primaryNameserver">The primary nameserver.</param>
|
||||
/// <param name="zoneAdministrator">The zone administrator. First dot will be interpreted as @-sign.</param>
|
||||
/// <param name="ttl">The time to live of the SOA record.</param>
|
||||
/// <param name="refresh">Time in seconds after which secondary servers should re-check the SOA record to see if the zone has been updated.</param>
|
||||
/// <param name="retry">Time in seconds after which secondary servers should retry queries after the primary server was unresponsive.</param>
|
||||
/// <param name="expire">Time in seconds of being unable to query the primary server after which secondary servers should stop serving the zone.</param>
|
||||
/// <param name="minimumTtl">The time to live (TTL) for negative caching of records within the zone.</param>
|
||||
public StartOfAuthority(string primaryNameserver, string zoneAdministrator, int ttl, int refresh, int retry, int expire, int minimumTtl)
|
||||
{
|
||||
PrimaryNameserver = primaryNameserver;
|
||||
ZoneAdministrator = zoneAdministrator;
|
||||
Ttl = ttl;
|
||||
Refresh = refresh;
|
||||
Retry = retry;
|
||||
Expire = expire;
|
||||
MinimumTtl = minimumTtl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds of being unable to query the primary server after which secondary servers should stop serving the zone.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>86400 <=</c> X <c><= 2419200</c></value>
|
||||
[JsonProperty("expire")]
|
||||
public virtual int Expire { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time to live (TTL) for negative caching of records within the zone.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>60 <=</c> X <c><= 86400</c></value>
|
||||
[JsonProperty("min_ttl")]
|
||||
public virtual int MinimumTtl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The primary nameserver, which may be used for outbound zone transfers.
|
||||
/// </summary>
|
||||
[JsonProperty("mname", NullValueHandling = NullValueHandling.Include)]
|
||||
public virtual string PrimaryNameserver { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds after which secondary servers should re-check the SOA record to see if the zone has been updated.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>600 <=</c> X <c><= 86400</c></value>
|
||||
[JsonProperty("refresh")]
|
||||
public virtual int Refresh { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds after which secondary servers should retry queries after the primary server was unresponsive.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>600 <=</c> X <c><= 86400</c></value>
|
||||
[JsonProperty("retry")]
|
||||
public virtual int Retry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The email address of the zone administrator, with the first label representing the local part of the email address.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The first dot is interpreted as @ sign.
|
||||
/// <br/>
|
||||
/// admin.example.com => admin@example.com
|
||||
/// <br/>
|
||||
/// test\.user.example.org => test.user@example.org
|
||||
/// </remarks>
|
||||
[JsonProperty("rname", NullValueHandling = NullValueHandling.Include)]
|
||||
public virtual string ZoneAdministrator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time to live (TTL) of the SOA record itself.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>300 <=</c> X <c><= 86400</c></value>
|
||||
[JsonProperty("ttl")]
|
||||
public virtual int Ttl { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// </summary>
|
||||
// <= 32 characters
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The account the zone belongs to.
|
||||
/// </summary>
|
||||
[JsonProperty("account")]
|
||||
public AccountBase Account { get; set; }
|
||||
public AccountBase? Account { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last time proof of ownership was detected and the zone was made active.
|
||||
@@ -45,7 +45,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// Metadata about the zone.
|
||||
/// </summary>
|
||||
[JsonProperty("meta")]
|
||||
public ZoneMetaData Meta { get; set; }
|
||||
public ZoneMetaData? Meta { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the zone was last modified.
|
||||
@@ -58,37 +58,37 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// </summary>
|
||||
// <= 253 characters
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name servers Cloudflare assigns to a zone.
|
||||
/// </summary>
|
||||
[JsonProperty("name_servers")]
|
||||
public IReadOnlyList<string> NameServers { get; set; }
|
||||
public IReadOnlyList<string>? NameServers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DNS host at the time of switching to Cloudflare.
|
||||
/// </summary>
|
||||
[JsonProperty("original_dnshost")]
|
||||
public string OriginalDnshost { get; set; }
|
||||
public string? OriginalDnshost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Original name servers before moving to Cloudflare.
|
||||
/// </summary>
|
||||
[JsonProperty("original_name_servers")]
|
||||
public IReadOnlyList<string> OriginalNameServers { get; set; }
|
||||
public IReadOnlyList<string>? OriginalNameServers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Registrar for the domain at the time of switching to Cloudflare.
|
||||
/// </summary>
|
||||
[JsonProperty("original_registrar")]
|
||||
public string OriginalRegistrar { get; set; }
|
||||
public string? OriginalRegistrar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The owner of the zone.
|
||||
/// </summary>
|
||||
[JsonProperty("owner")]
|
||||
public OwnerBase Owner { get; set; }
|
||||
public OwnerBase? Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the zone is only using Cloudflare DNS services.
|
||||
@@ -115,6 +115,6 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <em>This is only available for Business and Enterprise plans.</em>
|
||||
/// </summary>
|
||||
[JsonProperty("vanity_name_servers")]
|
||||
public IReadOnlyList<string> VanityNameServers { get; set; }
|
||||
public IReadOnlyList<string>? VanityNameServers { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
59
Extensions/Cloudflare.Zones/Models/ZoneDnsSetting.cs
Normal file
59
Extensions/Cloudflare.Zones/Models/ZoneDnsSetting.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// The DNS settings.
|
||||
/// </summary>
|
||||
public class ZoneDnsSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether to flatten all CNAME records in the zone. Note that, due to DNS limitations,
|
||||
/// a CNAME record at the zone apex will always be flattened.
|
||||
/// </summary>
|
||||
[JsonProperty("flatten_all_cnames")]
|
||||
public bool FlattenAllCnames { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable Foundation DNS Advanced Nameservers on the zone.
|
||||
/// </summary>
|
||||
[JsonProperty("foundation_dns")]
|
||||
public bool FoundationDns { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable multi-provider DNS, which causes Cloudflare to activate the zone even when non-Cloudflare NS records exist,
|
||||
/// and to respect NS records at the zone apex during outbound zone transfers.
|
||||
/// </summary>
|
||||
[JsonProperty("multi_provider")]
|
||||
public bool MultiProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Settings determining the nameservers through which the zone should be available.
|
||||
/// </summary>
|
||||
[JsonProperty("nameservers")]
|
||||
public Nameserver? Nameservers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time to live (TTL) of the zone's nameserver (NS) records.
|
||||
/// </summary>
|
||||
// 30 <= X <= 86400
|
||||
[JsonProperty("ns_ttl")]
|
||||
public int NameserverTtl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows a Secondary DNS zone to use (proxied) override records and CNAME flattening at the zone apex.
|
||||
/// </summary>
|
||||
[JsonProperty("secondary_overrides")]
|
||||
public bool SecondaryOverrides { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Components of the zone's SOA record.
|
||||
/// </summary>
|
||||
[JsonProperty("soa")]
|
||||
public StartOfAuthority? SOA { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the zone mode is a regular or CDN/DNS only zone.
|
||||
/// </summary>
|
||||
[JsonProperty("zone_mode")]
|
||||
public ZoneMode Mode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// Gets or sets an information whether subdomains are included in the hold.
|
||||
/// </summary>
|
||||
[JsonProperty("include_subdomains")]
|
||||
public string IncludeSubdomains { get; set; }
|
||||
public string? IncludeSubdomains { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time after which the zone is no longer on hold.
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
/// </summary>
|
||||
// <= 32 characters
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
37
Extensions/Cloudflare.Zones/Requests/CreateZoneRequest.cs
Normal file
37
Extensions/Cloudflare.Zones/Requests/CreateZoneRequest.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to create a new zone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Request to create a new zone.
|
||||
/// </remarks>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="name">The domain name.</param>
|
||||
public class CreateZoneRequest(string accountId, string name)
|
||||
{
|
||||
/// <summary>
|
||||
/// The account identifier.
|
||||
/// </summary>
|
||||
public string AccountId { get; set; } = accountId;
|
||||
|
||||
/// <summary>
|
||||
/// The domain name.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// The zone type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// A full zone implies that DNS is hosted with Cloudflare.
|
||||
/// A partial zone is typically a partner-hosted zone or a CNAME setup.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If not set, Cloudflare will use <see cref="ZoneType.Full"/> as default.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public ZoneType? Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,17 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <summary>
|
||||
/// A request to edit a zone.
|
||||
/// </summary>
|
||||
public class EditZoneRequest
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="EditZoneRequest"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="id">The zone identifier.</param>
|
||||
public class EditZoneRequest(string id)
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Identifier.
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
public string Id { get; set; } = id;
|
||||
|
||||
/// <summary>
|
||||
/// A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup.
|
||||
@@ -24,6 +29,6 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <br/>
|
||||
/// <em>This is only available for Business and Enterprise plans.</em>
|
||||
/// </summary>
|
||||
public IList<string> VanityNameServers { get; set; }
|
||||
public IList<string>? VanityNameServers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Update DNS settings request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="UpdateDnsSettingsRequest"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="id">The zone identifier.</param>
|
||||
public class UpdateDnsSettingsRequest(string id)
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The zone identifier.
|
||||
/// </summary>
|
||||
public string Id { get; set; } = id;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to flatten all CNAME records in the zone. Note that, due to DNS limitations,
|
||||
/// a CNAME record at the zone apex will always be flattened.
|
||||
/// </summary>
|
||||
public bool? FlattenAllCnames { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable Foundation DNS Advanced Nameservers on the zone.
|
||||
/// </summary>
|
||||
public bool? FoundationDns { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable multi-provider DNS, which causes Cloudflare to activate the zone even when non-Cloudflare NS records exist,
|
||||
/// and to respect NS records at the zone apex during outbound zone transfers.
|
||||
/// </summary>
|
||||
public bool? MultiProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Settings determining the nameservers through which the zone should be available.
|
||||
/// </summary>
|
||||
public Nameserver? Nameservers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time to live (TTL) of the zone's nameserver (NS) records.
|
||||
/// </summary>
|
||||
/// <value>Unit: seconds. Range: <c>30 <=</c> X <c><= 86400</c></value>
|
||||
public int? NameserverTtl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows a Secondary DNS zone to use (proxied) override records and CNAME flattening at the zone apex.
|
||||
/// </summary>
|
||||
public bool? SecondaryOverrides { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Components of the zone's SOA record.
|
||||
/// </summary>
|
||||
public StartOfAuthority? SOA { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the zone mode is a regular or CDN/DNS only zone.
|
||||
/// </summary>
|
||||
public ZoneMode? Mode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,11 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <summary>
|
||||
/// Url with headers to purge.
|
||||
/// </summary>
|
||||
public class ZonePurgeCachedUrlRequest
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="ZonePurgeCachedUrlRequest"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="url">The url to purge.</param>
|
||||
public class ZonePurgeCachedUrlRequest(string url)
|
||||
{
|
||||
/// <summary>
|
||||
/// Defined headers to specifiy the purge request.
|
||||
@@ -15,6 +19,6 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <summary>
|
||||
/// The file url to purge.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
public string Url { get; set; } = url;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Zones.InternalRequests
|
||||
{
|
||||
internal class CreateRequest
|
||||
{
|
||||
[JsonProperty("account")]
|
||||
public AccountBase Account { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public ZoneType Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones.Zones.InternalRequests
|
||||
{
|
||||
internal class EditRequest
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public ZoneType? Type { get; set; }
|
||||
|
||||
[JsonProperty("vanity_name_servers")]
|
||||
public IList<string> VanityNameServers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to create a new zone.
|
||||
/// </summary>
|
||||
public class CreateZoneRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The account identifier.
|
||||
/// </summary>
|
||||
public string AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The domain name.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The zone type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A full zone implies that DNS is hosted with Cloudflare.
|
||||
/// A partial zone is typically a partner-hosted zone or a CNAME setup.
|
||||
/// </remarks>
|
||||
public ZoneType Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
@@ -24,11 +24,11 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
public static Task<CloudflareResponse<ZoneIdResponse>> PurgeCachedContent(this ICloudflareClient client, string zoneId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
zoneId.ValidateCloudflareId();
|
||||
var req = new PurgeRequest
|
||||
var req = new InternalPurgeCacheRequest
|
||||
{
|
||||
PurgeEverything = true
|
||||
};
|
||||
return client.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,15 +60,12 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
zoneId.ValidateCloudflareId();
|
||||
|
||||
if (urls == null)
|
||||
throw new ArgumentNullException(nameof(urls));
|
||||
|
||||
var req = new PurgeRequest();
|
||||
var req = new InternalPurgeCacheRequest();
|
||||
|
||||
if (urls.Any(u => u.Headers.Count > 0))
|
||||
{
|
||||
req.UrlsWithHeaders = urls.Where(u => !string.IsNullOrWhiteSpace(u.Url))
|
||||
.Select(u => new UrlWithHeaders
|
||||
.Select(u => new PurgeUrlWithHeaders
|
||||
{
|
||||
Url = u.Url,
|
||||
Headers = u.Headers
|
||||
@@ -81,7 +78,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
req.Urls = urls.Where(u => !string.IsNullOrWhiteSpace(u.Url)).Select(u => u.Url).ToList();
|
||||
}
|
||||
|
||||
return client.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,11 +108,11 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (tags == null)
|
||||
throw new ArgumentNullException(nameof(tags));
|
||||
|
||||
var req = new PurgeRequest
|
||||
var req = new InternalPurgeCacheRequest
|
||||
{
|
||||
Tags = tags.Where(t => !string.IsNullOrWhiteSpace(t)).ToList()
|
||||
};
|
||||
return client.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,11 +142,11 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (hosts == null)
|
||||
throw new ArgumentNullException(nameof(hosts));
|
||||
|
||||
var req = new PurgeRequest
|
||||
var req = new InternalPurgeCacheRequest
|
||||
{
|
||||
Hostnames = hosts.Where(h => !string.IsNullOrWhiteSpace(h)).ToList()
|
||||
};
|
||||
return client.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,11 +176,11 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (prefixes == null)
|
||||
throw new ArgumentNullException(nameof(prefixes));
|
||||
|
||||
var req = new PurgeRequest
|
||||
var req = new InternalPurgeCacheRequest
|
||||
{
|
||||
Prefixes = prefixes.Where(h => !string.IsNullOrWhiteSpace(h)).ToList()
|
||||
};
|
||||
return client.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{zoneId}/purge_cache", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Extensions/Cloudflare.Zones/ZoneDnsSettingsExtensions.cs
Normal file
96
Extensions/Cloudflare.Zones/ZoneDnsSettingsExtensions.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends the <see cref="ICloudflareClient"/> with methods for working with zones.
|
||||
/// </summary>
|
||||
public static class ZoneDnsSettingsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Show DNS settings for a zone.
|
||||
/// </summary>
|
||||
/// <param name="client">The <see cref="ICloudflareClient"/>.</param>
|
||||
/// <param name="zoneId">The zone ID.</param>
|
||||
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
|
||||
public static Task<CloudflareResponse<ZoneDnsSetting>> ShowZoneDnsSettings(this ICloudflareClient client, string zoneId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
zoneId.ValidateCloudflareId();
|
||||
return client.GetAsync<ZoneDnsSetting>($"zones/{zoneId}/dns_settings", cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update DNS settings for a zone.
|
||||
/// </summary>
|
||||
/// <param name="client">The <see cref="ICloudflareClient"/>.</param>
|
||||
/// <param name="request">The update request.</param>
|
||||
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
|
||||
public static Task<CloudflareResponse<ZoneDnsSetting>> UpdateZoneDnsSettings(this ICloudflareClient client, UpdateDnsSettingsRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
request.Id.ValidateCloudflareId();
|
||||
|
||||
if (request.Mode.HasValue && !Enum.IsDefined(typeof(ZoneMode), request.Mode))
|
||||
throw new ArgumentOutOfRangeException(nameof(request.Mode), request.Mode, "Value must be one of the ZoneMode enum values.");
|
||||
|
||||
if (request.Nameservers != null && !Enum.IsDefined(typeof(NameserverType), request.Nameservers.Type))
|
||||
throw new ArgumentOutOfRangeException(nameof(request.Nameservers.Type), request.Nameservers.Type, "Value must be one of the NameserverType enum values.");
|
||||
|
||||
if (request.NameserverTtl.HasValue && (request.NameserverTtl < 30 || 86400 < request.NameserverTtl))
|
||||
throw new ArgumentOutOfRangeException(nameof(request.NameserverTtl), request.NameserverTtl, "Value must be between 30 and 86400.");
|
||||
|
||||
if (request.SOA != null)
|
||||
{
|
||||
if (request.SOA.Expire < 86400 || 2419200 < request.SOA.Expire)
|
||||
throw new ArgumentOutOfRangeException(nameof(request.SOA.Expire), request.SOA.Expire, "Value must be between 86400 and 2419200.");
|
||||
|
||||
if (request.SOA.MinimumTtl < 60 || 86400 < request.SOA.MinimumTtl)
|
||||
throw new ArgumentOutOfRangeException(nameof(request.SOA.MinimumTtl), request.SOA.MinimumTtl, "Value must be between 60 and 86400.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.SOA.PrimaryNameserver))
|
||||
throw new ArgumentNullException(nameof(request.SOA.PrimaryNameserver));
|
||||
|
||||
if (request.SOA.Refresh < 600 || 86400 < request.SOA.Refresh)
|
||||
throw new ArgumentOutOfRangeException(nameof(request.SOA.Refresh), request.SOA.Refresh, "Value must be between 600 and 86400.");
|
||||
|
||||
if (request.SOA.Retry < 600 || 86400 < request.SOA.Retry)
|
||||
throw new ArgumentOutOfRangeException(nameof(request.SOA.Retry), request.SOA.Retry, "Value must be between 600 and 86400.");
|
||||
|
||||
if (request.SOA.Ttl < 300 || 86400 < request.SOA.Ttl)
|
||||
throw new ArgumentOutOfRangeException(nameof(request.SOA.Ttl), request.SOA.Ttl, "Value must be between 300 and 86400.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.SOA.ZoneAdministrator))
|
||||
throw new ArgumentNullException(nameof(request.SOA.ZoneAdministrator));
|
||||
}
|
||||
|
||||
var req = new InternalUpdateDnsSettingsRequest
|
||||
{
|
||||
FlattenAllCnames = request.FlattenAllCnames,
|
||||
FoundationDns = request.FoundationDns,
|
||||
Mode = request.Mode,
|
||||
MultiProvider = request.MultiProvider,
|
||||
Nameservers = request.Nameservers,
|
||||
NameserverTtl = request.NameserverTtl,
|
||||
SecondaryOverrides = request.SecondaryOverrides,
|
||||
};
|
||||
|
||||
if (request.SOA != null)
|
||||
{
|
||||
req.Soa = new StartOfAuthority
|
||||
(
|
||||
expire: request.SOA.Expire,
|
||||
minimumTtl: request.SOA.MinimumTtl,
|
||||
primaryNameserver: request.SOA.PrimaryNameserver,
|
||||
refresh: request.SOA.Refresh,
|
||||
retry: request.SOA.Retry,
|
||||
ttl: request.SOA.Ttl,
|
||||
zoneAdministrator: request.SOA.ZoneAdministrator
|
||||
);
|
||||
}
|
||||
|
||||
return client.PatchAsync<ZoneDnsSetting, InternalUpdateDnsSettingsRequest>($"zones/{request.Id}/dns_settings", req, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Zones.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
/// <param name="client">The <see cref="ICloudflareClient"/>.</param>
|
||||
/// <param name="options">Filter options (optional).</param>
|
||||
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
|
||||
public static Task<CloudflareResponse<IReadOnlyList<Zone>>> ListZones(this ICloudflareClient client, ListZonesFilter options = null, CancellationToken cancellationToken = default)
|
||||
public static Task<CloudflareResponse<IReadOnlyList<Zone>>> ListZones(this ICloudflareClient client, ListZonesFilter? options = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return client.GetAsync<IReadOnlyList<Zone>>("zones", options, cancellationToken);
|
||||
}
|
||||
@@ -52,17 +52,15 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (!RegexPatterns.ZoneName.IsMatch(request.Name))
|
||||
throw new ArgumentException("Does not match the zone name pattern", nameof(request.Name));
|
||||
|
||||
if (!Enum.IsDefined(typeof(ZoneType), request.Type))
|
||||
if (request.Type.HasValue && !Enum.IsDefined(typeof(ZoneType), request.Type))
|
||||
throw new ArgumentOutOfRangeException(nameof(request.Type));
|
||||
|
||||
var req = new CreateRequest
|
||||
var req = new InternalCreateZoneRequest(account: new AccountBase { Id = request.AccountId }, name: request.Name)
|
||||
{
|
||||
Account = new AccountBase { Id = request.AccountId },
|
||||
Name = request.Name,
|
||||
Type = request.Type
|
||||
};
|
||||
|
||||
return client.PostAsync<Zone, CreateRequest>("zones", req, cancellationToken: cancellationToken);
|
||||
return client.PostAsync<Zone, InternalCreateZoneRequest>("zones", req, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -96,7 +94,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (request.Type.HasValue && !Enum.IsDefined(typeof(ZoneType), request.Type.Value))
|
||||
throw new ArgumentOutOfRangeException(nameof(request.Type));
|
||||
|
||||
var req = new EditRequest();
|
||||
var req = new InternalEditZoneRequest();
|
||||
|
||||
if (request.Type.HasValue)
|
||||
req.Type = request.Type.Value;
|
||||
@@ -104,7 +102,7 @@ namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
if (request.VanityNameServers != null)
|
||||
req.VanityNameServers = request.VanityNameServers.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
|
||||
|
||||
return client.PatchAsync<Zone, EditRequest>($"zones/{request.Id}", req, cancellationToken);
|
||||
return client.PatchAsync<Zone, InternalEditZoneRequest>($"zones/{request.Id}", req, cancellationToken);
|
||||
}
|
||||
|
||||
// Triggeres a new activation check for a PENDING Zone. This can be triggered every 5 min for paygo/ent customers, every hour for FREE Zones.
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Filters;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Zones
|
||||
{
|
||||
@@ -1,6 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<NrtRevisionFormat>{semvertag:main}{!:-dev}</NrtRevisionFormat>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
|
||||
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using Moq;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
private CloudflareResponse<ZoneIdResponse> _response;
|
||||
|
||||
private List<(string RequestPath, PurgeRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
private List<(string RequestPath, InternalPurgeCacheRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -90,7 +89,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -111,8 +110,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, PurgeRequest>(It.IsAny<string>(), It.IsAny<PurgeRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, PurgeRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>(It.IsAny<string>(), It.IsAny<InternalPurgeCacheRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalPurgeCacheRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using Moq;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
private CloudflareResponse<ZoneIdResponse> _response;
|
||||
|
||||
private List<(string RequestPath, PurgeRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
private List<(string RequestPath, InternalPurgeCacheRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -93,7 +92,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -114,8 +113,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, PurgeRequest>(It.IsAny<string>(), It.IsAny<PurgeRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, PurgeRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>(It.IsAny<string>(), It.IsAny<InternalPurgeCacheRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalPurgeCacheRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using Moq;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
private CloudflareResponse<ZoneIdResponse> _response;
|
||||
|
||||
private List<(string RequestPath, PurgeRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
private List<(string RequestPath, InternalPurgeCacheRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -91,7 +90,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -112,8 +111,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, PurgeRequest>(It.IsAny<string>(), It.IsAny<PurgeRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, PurgeRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>(It.IsAny<string>(), It.IsAny<InternalPurgeCacheRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalPurgeCacheRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using Moq;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
private CloudflareResponse<ZoneIdResponse> _response;
|
||||
|
||||
private List<(string RequestPath, PurgeRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
private List<(string RequestPath, InternalPurgeCacheRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -58,8 +57,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
// Arrange
|
||||
var list = new List<ZonePurgeCachedUrlRequest>
|
||||
{
|
||||
new ZonePurgeCachedUrlRequest { Url = "https://example.com/foo.txt" },
|
||||
new ZonePurgeCachedUrlRequest { Url = "https://example.com/bar.baz" },
|
||||
new("https://example.com/foo.txt"),
|
||||
new("https://example.com/bar.baz"),
|
||||
};
|
||||
|
||||
var client = GetClient();
|
||||
@@ -90,7 +89,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -100,8 +99,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
// Arrange
|
||||
var list = new List<ZonePurgeCachedUrlRequest>
|
||||
{
|
||||
new ZonePurgeCachedUrlRequest { Url = "https://example.com/foo.txt", Headers = new Dictionary<string, string> { { "X-Test1", "Test" } } },
|
||||
new ZonePurgeCachedUrlRequest { Url = "https://example.com/bar.baz", Headers = new Dictionary<string, string> { { "X-Test2", "Test" } } },
|
||||
new("https://example.com/foo.txt") { Headers = new Dictionary<string, string> { { "X-Test1", "Test" } } },
|
||||
new("https://example.com/bar.baz") { Headers = new Dictionary<string, string> { { "X-Test2", "Test" } } },
|
||||
};
|
||||
|
||||
var client = GetClient();
|
||||
@@ -134,7 +133,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -155,8 +154,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, PurgeRequest>(It.IsAny<string>(), It.IsAny<PurgeRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, PurgeRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>(It.IsAny<string>(), It.IsAny<InternalPurgeCacheRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalPurgeCacheRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Cache.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Cache
|
||||
@@ -20,7 +20,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
private CloudflareResponse<ZoneIdResponse> _response;
|
||||
|
||||
private List<(string RequestPath, PurgeRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
private List<(string RequestPath, InternalPurgeCacheRequest Request, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -81,7 +81,7 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
|
||||
Assert.IsNull(callback.QueryFilter);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, PurgeRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<PurgeRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>($"zones/{ZoneId}/purge_cache", It.IsAny<InternalPurgeCacheRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace Cloudflare.Zones.Tests.Cache
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, PurgeRequest>(It.IsAny<string>(), It.IsAny<PurgeRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, PurgeRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.Setup(m => m.PostAsync<ZoneIdResponse, InternalPurgeCacheRequest>(It.IsAny<string>(), It.IsAny<InternalPurgeCacheRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalPurgeCacheRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, queryFilter, _) => _callbacks.Add((requestPath, request, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.DnsSettings
|
||||
{
|
||||
[TestClass]
|
||||
public class ShowDnsSettingsTest
|
||||
{
|
||||
private const string ZoneId = "023e105f4ecef8ad9ca31a8372d0c353";
|
||||
|
||||
private Mock<ICloudflareClient> _clientMock;
|
||||
|
||||
private CloudflareResponse<ZoneDnsSetting> _response;
|
||||
|
||||
private List<(string RequestPath, IQueryParameterFilter QueryFilter)> _callbacks;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_callbacks = [];
|
||||
|
||||
_response = new CloudflareResponse<ZoneDnsSetting>
|
||||
{
|
||||
Success = true,
|
||||
Messages = [
|
||||
new ResponseInfo
|
||||
{
|
||||
Code = 1000,
|
||||
Message = "Message 1",
|
||||
}
|
||||
],
|
||||
Errors = [
|
||||
new ResponseInfo
|
||||
{
|
||||
Code = 1000,
|
||||
Message = "Error 1",
|
||||
}
|
||||
],
|
||||
Result = new ZoneDnsSetting
|
||||
{
|
||||
FlattenAllCnames = false,
|
||||
FoundationDns = false,
|
||||
MultiProvider = false,
|
||||
Nameservers = new Nameserver
|
||||
{
|
||||
Type = NameserverType.CloudflareStandard,
|
||||
},
|
||||
NameserverTtl = 86400,
|
||||
SecondaryOverrides = false,
|
||||
SOA = new StartOfAuthority
|
||||
(
|
||||
expire: 604800,
|
||||
minimumTtl: 1800,
|
||||
primaryNameserver: "kristina.ns.cloudflare.com",
|
||||
refresh: 10000,
|
||||
retry: 2400,
|
||||
zoneAdministrator: "admin.example.com",
|
||||
ttl: 3600
|
||||
),
|
||||
Mode = ZoneMode.DnsOnly
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ShouldGetDnsSetting()
|
||||
{
|
||||
// Arrange
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
var response = await client.ShowZoneDnsSettings(ZoneId);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(response);
|
||||
Assert.IsTrue(response.Success);
|
||||
Assert.AreEqual(_response?.Result, response.Result);
|
||||
|
||||
Assert.AreEqual(1, _callbacks?.Count);
|
||||
|
||||
var callback = _callbacks?.First();
|
||||
Assert.AreEqual($"zones/{ZoneId}/dns_settings", callback?.RequestPath);
|
||||
|
||||
Assert.IsNull(callback?.QueryFilter);
|
||||
|
||||
_clientMock?.Verify(m => m.GetAsync<ZoneDnsSetting>($"zones/{ZoneId}/dns_settings", null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock?.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
private ICloudflareClient GetClient()
|
||||
{
|
||||
if (_response == null) throw new InvalidOperationException();
|
||||
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.GetAsync<ZoneDnsSetting>(It.IsAny<string>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, IQueryParameterFilter, CancellationToken>((requestPath, queryFilter, _) => _callbacks?.Add((requestPath, queryFilter)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.DnsSettings
|
||||
{
|
||||
[TestClass]
|
||||
public class UpdateDnsSettingsTest
|
||||
{
|
||||
private const string ZoneId = "023e105f4ecef8ad9ca31a8372d0c353";
|
||||
|
||||
private Mock<ICloudflareClient> _clientMock;
|
||||
|
||||
private CloudflareResponse<ZoneDnsSetting> _response;
|
||||
|
||||
private List<(string RequestPath, InternalUpdateDnsSettingsRequest Request)> _callbacks;
|
||||
|
||||
private UpdateDnsSettingsRequest _request;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_callbacks = [];
|
||||
|
||||
_response = new CloudflareResponse<ZoneDnsSetting>
|
||||
{
|
||||
Success = true,
|
||||
Messages = [
|
||||
new ResponseInfo
|
||||
{
|
||||
Code = 1000,
|
||||
Message = "Message 1",
|
||||
}
|
||||
],
|
||||
Errors = [
|
||||
new ResponseInfo
|
||||
{
|
||||
Code = 1000,
|
||||
Message = "Error 1",
|
||||
}
|
||||
],
|
||||
Result = new ZoneDnsSetting
|
||||
{
|
||||
FlattenAllCnames = false,
|
||||
FoundationDns = false,
|
||||
MultiProvider = false,
|
||||
Nameservers = new Nameserver
|
||||
{
|
||||
Type = NameserverType.CloudflareStandard,
|
||||
},
|
||||
NameserverTtl = 86400,
|
||||
SecondaryOverrides = false,
|
||||
SOA = new StartOfAuthority
|
||||
(
|
||||
expire: 604800,
|
||||
minimumTtl: 1800,
|
||||
primaryNameserver: "kristina.ns.cloudflare.com",
|
||||
refresh: 10000,
|
||||
retry: 2400,
|
||||
zoneAdministrator: "admin.example.com",
|
||||
ttl: 3600
|
||||
),
|
||||
Mode = ZoneMode.DnsOnly
|
||||
}
|
||||
};
|
||||
|
||||
_request = new UpdateDnsSettingsRequest(ZoneId)
|
||||
{
|
||||
FlattenAllCnames = true,
|
||||
FoundationDns = false,
|
||||
MultiProvider = false,
|
||||
Nameservers = new Nameserver
|
||||
{
|
||||
Type = NameserverType.CloudflareRandom
|
||||
},
|
||||
NameserverTtl = 86400,
|
||||
SecondaryOverrides = false,
|
||||
SOA = new StartOfAuthority
|
||||
(
|
||||
expire: 604800,
|
||||
minimumTtl: 1800,
|
||||
primaryNameserver: "ns1.example.org",
|
||||
refresh: 28800,
|
||||
retry: 3600,
|
||||
ttl: 43200,
|
||||
zoneAdministrator: "admin.example.org"
|
||||
),
|
||||
Mode = ZoneMode.Standard
|
||||
};
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ShouldUpdateDnsSettingsFull()
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null) throw new InvalidOperationException();
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
var response = await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(response);
|
||||
Assert.IsTrue(response.Success);
|
||||
Assert.AreEqual(_response?.Result, response.Result);
|
||||
|
||||
Assert.AreEqual(1, _callbacks?.Count);
|
||||
|
||||
var callback = _callbacks?.First();
|
||||
Assert.AreEqual($"zones/{ZoneId}/dns_settings", callback?.RequestPath);
|
||||
|
||||
Assert.IsNotNull(callback?.Request);
|
||||
Assert.IsTrue(callback?.Request.FlattenAllCnames);
|
||||
Assert.IsFalse(callback?.Request.FoundationDns);
|
||||
Assert.IsFalse(callback?.Request.MultiProvider);
|
||||
Assert.IsNotNull(callback?.Request.Nameservers);
|
||||
Assert.AreEqual(NameserverType.CloudflareRandom, callback?.Request.Nameservers.Type);
|
||||
Assert.AreEqual(86400, callback?.Request.NameserverTtl);
|
||||
Assert.IsFalse(callback?.Request.SecondaryOverrides);
|
||||
Assert.IsNotNull(callback?.Request.Soa);
|
||||
Assert.AreEqual(604800, callback?.Request.Soa.Expire);
|
||||
Assert.AreEqual(1800, callback?.Request.Soa.MinimumTtl);
|
||||
Assert.AreEqual("ns1.example.org", callback?.Request.Soa.PrimaryNameserver);
|
||||
Assert.AreEqual(28800, callback?.Request.Soa.Refresh);
|
||||
Assert.AreEqual(3600, callback?.Request.Soa.Retry);
|
||||
Assert.AreEqual(43200, callback?.Request.Soa.Ttl);
|
||||
Assert.AreEqual("admin.example.org", callback?.Request.Soa.ZoneAdministrator);
|
||||
Assert.AreEqual(ZoneMode.Standard, callback?.Request.Mode);
|
||||
|
||||
_clientMock?.Verify(m => m.PatchAsync<ZoneDnsSetting, InternalUpdateDnsSettingsRequest>($"zones/{ZoneId}/dns_settings", It.IsAny<InternalUpdateDnsSettingsRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock?.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ShouldUpdateDnsSettingsNone()
|
||||
{
|
||||
// Arrange
|
||||
var request = new UpdateDnsSettingsRequest(ZoneId);
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
var response = await client.UpdateZoneDnsSettings(request);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(response);
|
||||
Assert.IsTrue(response.Success);
|
||||
Assert.AreEqual(_response?.Result, response.Result);
|
||||
|
||||
Assert.AreEqual(1, _callbacks?.Count);
|
||||
|
||||
var callback = _callbacks?.First();
|
||||
Assert.AreEqual($"zones/{ZoneId}/dns_settings", callback?.RequestPath);
|
||||
|
||||
Assert.IsNotNull(callback?.Request);
|
||||
Assert.IsNull(callback?.Request.FlattenAllCnames);
|
||||
Assert.IsNull(callback?.Request.FoundationDns);
|
||||
Assert.IsNull(callback?.Request.MultiProvider);
|
||||
Assert.IsNull(callback?.Request.Nameservers);
|
||||
Assert.IsNull(callback?.Request.NameserverTtl);
|
||||
Assert.IsNull(callback?.Request.SecondaryOverrides);
|
||||
Assert.IsNull(callback?.Request.Soa);
|
||||
Assert.IsNull(callback?.Request.Mode);
|
||||
|
||||
_clientMock?.Verify(m => m.PatchAsync<ZoneDnsSetting, InternalUpdateDnsSettingsRequest>($"zones/{ZoneId}/dns_settings", It.IsAny<InternalUpdateDnsSettingsRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock?.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidMode()
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null) throw new InvalidOperationException();
|
||||
_request.Mode = 0;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidNameserverType()
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.Nameservers == null) throw new InvalidOperationException();
|
||||
_request.Nameservers.Type = 0;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(29)]
|
||||
[DataRow(86401)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidNameserverTtl(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null) throw new InvalidOperationException();
|
||||
_request.NameserverTtl = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(86399)]
|
||||
[DataRow(2419201)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidSoaExpire(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.Expire = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(59)]
|
||||
[DataRow(86401)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidSoaMinimumTtl(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.MinimumTtl = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow("")]
|
||||
[DataRow(" ")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public async Task ShouldThrowArgumentNullExceptionForMissingSoaNameserver(string nameserver)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.PrimaryNameserver = nameserver;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentNullException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(599)]
|
||||
[DataRow(86401)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidSoaRefresh(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.Refresh = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(599)]
|
||||
[DataRow(86401)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidSoaRetry(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.Retry = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(299)]
|
||||
[DataRow(86401)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public async Task ShouldThrowArgumentOutOfRangeExceptionForInvalidSoaTtl(int ttl)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.Ttl = ttl;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentOutOfRangeException
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow("")]
|
||||
[DataRow(" ")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public async Task ShouldThrowArgumentNullExceptionForMissingSoaAdministrator(string admin)
|
||||
{
|
||||
// Arrange
|
||||
if (_request == null || _request.SOA == null) throw new InvalidOperationException();
|
||||
_request.SOA.ZoneAdministrator = admin;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
await client.UpdateZoneDnsSettings(_request);
|
||||
|
||||
// Assert - ArgumentNullException
|
||||
}
|
||||
|
||||
private ICloudflareClient GetClient()
|
||||
{
|
||||
if (_response == null) throw new InvalidOperationException();
|
||||
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PatchAsync<ZoneDnsSetting, InternalUpdateDnsSettingsRequest>(It.IsAny<string>(), It.IsAny<InternalUpdateDnsSettingsRequest>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalUpdateDnsSettingsRequest, CancellationToken>((requestPath, request, _) => _callbacks?.Add((requestPath, request)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Filters;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Hold
|
||||
@@ -12,8 +13,8 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
[TestClass]
|
||||
public class CreateZoneHoldTest
|
||||
{
|
||||
private readonly DateTime _date = new(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
private const string ZoneId = "023e105f4ecef8ad9ca31a8372d0c353";
|
||||
private readonly DateTime DateTime = new(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
|
||||
private Mock<ICloudflareClient> _clientMock;
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
Result = new ZoneHold
|
||||
{
|
||||
Hold = true,
|
||||
HoldAfter = DateTime,
|
||||
HoldAfter = _date,
|
||||
IncludeSubdomains = "true"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Filters;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Hold
|
||||
@@ -12,8 +13,8 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
[TestClass]
|
||||
public class DeleteZoneHoldTest
|
||||
{
|
||||
private readonly DateTime _date = new(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
private const string ZoneId = "023e105f4ecef8ad9ca31a8372d0c353";
|
||||
private readonly DateTime Date = new(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
|
||||
private Mock<ICloudflareClient> _clientMock;
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
Result = new ZoneHold
|
||||
{
|
||||
Hold = true,
|
||||
HoldAfter = Date,
|
||||
HoldAfter = _date,
|
||||
IncludeSubdomains = "true"
|
||||
}
|
||||
};
|
||||
@@ -86,7 +87,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
var response = await client.DeleteZoneHold(ZoneId, holdAfter: Date);
|
||||
var response = await client.DeleteZoneHold(ZoneId, holdAfter: _date);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(response);
|
||||
@@ -100,7 +101,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
Assert.IsNotNull(callback.QueryFilter);
|
||||
|
||||
Assert.IsInstanceOfType<DeleteZoneHoldFilter>(callback.QueryFilter);
|
||||
Assert.AreEqual(Date, ((DeleteZoneHoldFilter)callback.QueryFilter).HoldAfter);
|
||||
Assert.AreEqual(_date, ((DeleteZoneHoldFilter)callback.QueryFilter).HoldAfter);
|
||||
|
||||
_clientMock.Verify(m => m.DeleteAsync<ZoneHold>($"zones/{ZoneId}/hold", It.IsAny<DeleteZoneHoldFilter>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
@@ -124,7 +125,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
public void ShouldReturnQueryParameter()
|
||||
{
|
||||
// Arrange
|
||||
var filter = new DeleteZoneHoldFilter { HoldAfter = Date };
|
||||
var filter = new DeleteZoneHoldFilter { HoldAfter = _date };
|
||||
|
||||
// Act
|
||||
var dict = filter.GetQueryParameters();
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
[TestClass]
|
||||
public class GetZoneHoldTest
|
||||
{
|
||||
private readonly DateTime _date = new DateTime(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
private const string ZoneId = "023e105f4ecef8ad9ca31a8372d0c353";
|
||||
private readonly DateTime DateTime = new DateTime(2024, 10, 10, 20, 30, 40, 0, DateTimeKind.Utc);
|
||||
|
||||
private Mock<ICloudflareClient> _clientMock;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Cloudflare.Zones.Tests.Hold
|
||||
Result = new ZoneHold
|
||||
{
|
||||
Hold = true,
|
||||
HoldAfter = DateTime,
|
||||
HoldAfter = _date,
|
||||
IncludeSubdomains = "false"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Zones.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Zones
|
||||
@@ -19,7 +19,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
|
||||
private CloudflareResponse<Zone> _response;
|
||||
|
||||
private List<(string RequestPath, CreateRequest Request)> _callbacks;
|
||||
private List<(string RequestPath, InternalCreateZoneRequest Request)> _callbacks;
|
||||
|
||||
private CreateZoneRequest _request;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
],
|
||||
Result = new Zone
|
||||
{
|
||||
Id = "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
Id = ZoneId,
|
||||
Account = new AccountBase
|
||||
{
|
||||
Id = "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
@@ -97,18 +97,16 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
}
|
||||
};
|
||||
|
||||
_request = new CreateZoneRequest
|
||||
{
|
||||
AccountId = "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
Name = "example.com",
|
||||
Type = ZoneType.Full
|
||||
};
|
||||
_request = new CreateZoneRequest("023e105f4ecef8ad9ca31a8372d0c353", "example.com");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ShouldReturnCreatedZone()
|
||||
[DataTestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow(ZoneType.Full)]
|
||||
public async Task ShouldReturnCreatedZone(ZoneType? type)
|
||||
{
|
||||
// Arrange
|
||||
_request.Type = type;
|
||||
var client = GetClient();
|
||||
|
||||
// Act
|
||||
@@ -129,7 +127,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
Assert.AreEqual(_request.Name, callback.Request.Name);
|
||||
Assert.AreEqual(_request.Type, callback.Request.Type);
|
||||
|
||||
_clientMock.Verify(m => m.PostAsync<Zone, CreateRequest>("zones", It.IsAny<CreateRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PostAsync<Zone, InternalCreateZoneRequest>("zones", It.IsAny<InternalCreateZoneRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -182,8 +180,8 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PostAsync<Zone, CreateRequest>(It.IsAny<string>(), It.IsAny<CreateRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, CreateRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, _, _) => _callbacks.Add((requestPath, request)))
|
||||
.Setup(m => m.PostAsync<Zone, InternalCreateZoneRequest>(It.IsAny<string>(), It.IsAny<InternalCreateZoneRequest>(), It.IsAny<IQueryParameterFilter>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalCreateZoneRequest, IQueryParameterFilter, CancellationToken>((requestPath, request, _, _) => _callbacks.Add((requestPath, request)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AMWD.Net.Api.Cloudflare;
|
||||
using AMWD.Net.Api.Cloudflare.Zones;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Zones.InternalRequests;
|
||||
using AMWD.Net.Api.Cloudflare.Zones.Internals.Requests;
|
||||
using Moq;
|
||||
|
||||
namespace Cloudflare.Zones.Tests.Zones
|
||||
@@ -19,7 +19,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
|
||||
private CloudflareResponse<Zone> _response;
|
||||
|
||||
private List<(string RequestPath, EditRequest Request)> _callbacks;
|
||||
private List<(string RequestPath, InternalEditZoneRequest Request)> _callbacks;
|
||||
|
||||
private EditZoneRequest _request;
|
||||
|
||||
@@ -97,9 +97,8 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
}
|
||||
};
|
||||
|
||||
_request = new EditZoneRequest
|
||||
_request = new EditZoneRequest(ZoneId)
|
||||
{
|
||||
Id = ZoneId,
|
||||
Type = ZoneType.Full,
|
||||
VanityNameServers = ["ns1.example.org", "ns2.example.org"]
|
||||
};
|
||||
@@ -129,7 +128,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
Assert.AreEqual(_request.Type.Value, callback.Request.Type.Value);
|
||||
Assert.IsNull(callback.Request.VanityNameServers);
|
||||
|
||||
_clientMock.Verify(m => m.PatchAsync<Zone, EditRequest>($"zones/{ZoneId}", It.IsAny<EditRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PatchAsync<Zone, InternalEditZoneRequest>($"zones/{ZoneId}", It.IsAny<InternalEditZoneRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
Assert.IsTrue(callback.Request.VanityNameServers.Contains("ns1.example.org"));
|
||||
Assert.IsTrue(callback.Request.VanityNameServers.Contains("ns2.example.org"));
|
||||
|
||||
_clientMock.Verify(m => m.PatchAsync<Zone, EditRequest>($"zones/{ZoneId}", It.IsAny<EditRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.Verify(m => m.PatchAsync<Zone, InternalEditZoneRequest>($"zones/{ZoneId}", It.IsAny<InternalEditZoneRequest>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_clientMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
@@ -196,8 +195,8 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
{
|
||||
_clientMock = new Mock<ICloudflareClient>();
|
||||
_clientMock
|
||||
.Setup(m => m.PatchAsync<Zone, EditRequest>(It.IsAny<string>(), It.IsAny<EditRequest>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, EditRequest, CancellationToken>((requestPath, request, _) => _callbacks.Add((requestPath, request)))
|
||||
.Setup(m => m.PatchAsync<Zone, InternalEditZoneRequest>(It.IsAny<string>(), It.IsAny<InternalEditZoneRequest>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, InternalEditZoneRequest, CancellationToken>((requestPath, request, _) => _callbacks.Add((requestPath, request)))
|
||||
.ReturnsAsync(() => _response);
|
||||
|
||||
return _clientMock.Object;
|
||||
|
||||
@@ -178,12 +178,12 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
{
|
||||
AccountId = "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
AccountName = "Example Account Name",
|
||||
MatchType = FilterMatchType.Any,
|
||||
Match = FilterMatchType.Any,
|
||||
Name = "example.com",
|
||||
PerPage = 13,
|
||||
Page = 5,
|
||||
OrderBy = ZonesOrderBy.AccountName,
|
||||
OrderDirection = SortDirection.Descending,
|
||||
Direction = SortDirection.Descending,
|
||||
Status = ZoneStatus.Active
|
||||
};
|
||||
|
||||
@@ -261,7 +261,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
// Arrange
|
||||
var filter = new ListZonesFilter
|
||||
{
|
||||
OrderDirection = 0
|
||||
Direction = 0
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -278,7 +278,7 @@ namespace Cloudflare.Zones.Tests.Zones
|
||||
// Arrange
|
||||
var filter = new ListZonesFilter
|
||||
{
|
||||
MatchType = 0
|
||||
Match = 0
|
||||
};
|
||||
|
||||
// Act
|
||||
|
||||
Reference in New Issue
Block a user