Enhanced easy to catch test coverage

This commit is contained in:
2025-07-29 08:38:40 +02:00
parent a0d0607ec8
commit 50b8efbb46
5 changed files with 268 additions and 11 deletions

View File

@@ -70,7 +70,7 @@ namespace AMWD.Net.Api.Cloudflare.Dns
// Deletes (DELETE)
var deletes = new List<Identifier>();
foreach (string delete in request.Deletes ?? [])
foreach (string delete in request.Deletes)
{
delete.ValidateCloudflareId();
deletes.Add(new Identifier { Id = delete });
@@ -78,7 +78,7 @@ namespace AMWD.Net.Api.Cloudflare.Dns
// Updates (PATCH)
var patches = new List<InternalBatchUpdateRequest>();
foreach (var patch in request.Updates ?? [])
foreach (var patch in request.Updates)
{
patch.Id.ValidateCloudflareId();
@@ -90,7 +90,7 @@ namespace AMWD.Net.Api.Cloudflare.Dns
// Creates (POST)
var posts = new List<InternalDnsRecordRequest>();
foreach (var post in request.Creates ?? [])
foreach (var post in request.Creates)
{
var req = (InternalDnsRecordRequest)ValidateRequest(post);
posts.Add(req);
@@ -98,7 +98,7 @@ namespace AMWD.Net.Api.Cloudflare.Dns
// Overwrites (PUT)
var puts = new List<InternalBatchUpdateRequest>();
foreach (var put in request.Overwrites ?? [])
foreach (var put in request.Overwrites)
{
put.Id.ValidateCloudflareId();

View File

@@ -22,22 +22,22 @@
/// <summary>
/// The DNS records to delete.
/// </summary>
public IReadOnlyCollection<string>? Deletes { get; set; }
public IReadOnlyCollection<string> Deletes { get; set; } = [];
/// <summary>
/// The DNS records to update.
/// </summary>
public IReadOnlyCollection<Patch>? Updates { get; set; }
public IReadOnlyCollection<Patch> Updates { get; set; } = [];
/// <summary>
/// The DNS records to create.
/// </summary>
public IReadOnlyCollection<Post>? Creates { get; set; }
public IReadOnlyCollection<Post> Creates { get; set; } = [];
/// <summary>
/// The DNS records to overwrite.
/// </summary>
public IReadOnlyCollection<Put>? Overwrites { get; set; }
public IReadOnlyCollection<Put> Overwrites { get; set; } = [];
/// <summary>
/// Represents a request to update a DNS record.

View File

@@ -165,6 +165,34 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
}
}
[DataTestMethod]
[DataRow(HttpStatusCode.Unauthorized)]
[DataRow(HttpStatusCode.Forbidden)]
public async Task ShouldThrowAuthenticationExceptionOnStatusCodeWithoutErrors(HttpStatusCode statusCode)
{
// Arrange
_httpHandlerMock.Responses.Enqueue(new HttpResponseMessage
{
StatusCode = statusCode,
Content = new StringContent(@"{""success"": false, ""errors"": null, ""messages"": []}", Encoding.UTF8, MediaTypeNames.Application.Json),
});
var client = GetClient();
try
{
// Act
await client.GetAsync<TestClass>("foo");
Assert.Fail();
}
catch (AuthenticationException ex)
{
// Assert
Assert.IsNull(ex.InnerException);
Assert.AreEqual(string.Empty, ex.Message);
}
}
[DataTestMethod]
[DataRow(HttpStatusCode.Unauthorized)]
[DataRow(HttpStatusCode.Forbidden)]

View File

@@ -720,6 +720,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
#region LOC
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLatitudeDegrees()
{
// Arrange
((LOCRecordData)_request.Data).LatitudeDegrees = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(91)]
@@ -736,6 +755,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLatitudeMinutes()
{
// Arrange
((LOCRecordData)_request.Data).LatitudeMinutes = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(60)]
@@ -752,6 +790,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLatitudeSeconds()
{
// Arrange
((LOCRecordData)_request.Data).LatitudeSeconds = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1.0)]
[DataRow(59.9991)]
@@ -768,6 +825,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLatitudeDirection()
{
// Arrange
((LOCRecordData)_request.Data).LatitudeDirection = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public async Task ShouldThrowArgumentOutOfRangeExceptionForLocDataLatitudeDirection()
@@ -782,6 +858,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLongitudeDegrees()
{
// Arrange
((LOCRecordData)_request.Data).LongitudeDegrees = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(181)]
@@ -798,6 +893,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLongitudeMinutes()
{
// Arrange
((LOCRecordData)_request.Data).LongitudeMinutes = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(60)]
@@ -814,6 +928,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLongitudeSeconds()
{
// Arrange
((LOCRecordData)_request.Data).LongitudeSeconds = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1.0)]
[DataRow(59.9991)]
@@ -830,6 +963,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutLongitudeDirection()
{
// Arrange
((LOCRecordData)_request.Data).LongitudeDirection = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public async Task ShouldThrowArgumentOutOfRangeExceptionForLocDataLongitudeDirection()
@@ -844,6 +996,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutAltitude()
{
// Arrange
((LOCRecordData)_request.Data).Altitude = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-100_000.1)]
[DataRow(42_849_672.951)]
@@ -860,6 +1031,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutSize()
{
// Arrange
((LOCRecordData)_request.Data).Size = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(90_000_001)]
@@ -876,6 +1066,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutPrecisionHorizontal()
{
// Arrange
((LOCRecordData)_request.Data).PrecisionHorizontal = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(90_000_001)]
@@ -892,6 +1101,25 @@ namespace Cloudflare.Dns.Tests.DnsRecordsExtensions
// Assert - ArgumentOutOfRangeException
}
[TestMethod]
public async Task ShouldCreateLocDataRecordWithoutPrecisionVertical()
{
// Arrange
((LOCRecordData)_request.Data).PrecisionVertical = null;
var client = GetClient();
// Act
var response = await client.CreateDnsRecord(_request);
// Assert
Assert.IsNotNull(response);
Assert.IsTrue(response.Success);
Assert.AreEqual(_response.Result, response.Result);
_clientMock.Verify(m => m.PostAsync<DnsRecord, InternalDnsRecordRequest>($"/zones/{ZoneId}/dns_records", It.IsAny<InternalDnsRecordRequest>(), null, It.IsAny<CancellationToken>()), Times.Once);
_clientMock.VerifyNoOtherCalls();
}
[DataTestMethod]
[DataRow(-1)]
[DataRow(90_000_001)]

View File

@@ -95,12 +95,13 @@ namespace Cloudflare.Zones.Tests.ZonesExtensions
}
[DataTestMethod]
[DataRow(null)]
[DataRow("023e105f4ecef8ad9ca31a8372d0c353")]
public async Task ShouldCreateZone(string accountId)
[DataRow(null, ZoneType.Full)]
[DataRow("023e105f4ecef8ad9ca31a8372d0c353", null)]
public async Task ShouldCreateZone(string accountId, ZoneType? type)
{
// Arrange
_request.AccountId = accountId;
_request.Type = type;
var client = GetClient();
// Act