Updated core unit tests to latest recommendations
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using AMWD.Net.Api.Cloudflare;
|
using AMWD.Net.Api.Cloudflare;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.Auth
|
namespace Cloudflare.Tests.Auth
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class ApiKeyAuthenticationTest
|
public class ApiKeyAuthenticationTest
|
||||||
@@ -32,48 +32,39 @@ namespace Cloudflare.Core.Tests.Auth
|
|||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldArgumentNullExceptionForEmailAddress(string emailAddress)
|
public void ShouldArgumentNullExceptionForEmailAddress(string emailAddress)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string apiKey = "some-api-key";
|
string apiKey = "some-api-key";
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
new ApiKeyAuthentication(emailAddress, apiKey);
|
Assert.ThrowsExactly<ArgumentNullException>(() => new ApiKeyAuthentication(emailAddress, apiKey));
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldArgumentNullExceptionForApiKey(string apiKey)
|
public void ShouldArgumentNullExceptionForApiKey(string apiKey)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string emailAddress = "test@example.com";
|
string emailAddress = "test@example.com";
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
new ApiKeyAuthentication(emailAddress, apiKey);
|
Assert.ThrowsExactly<ArgumentNullException>(() => new ApiKeyAuthentication(emailAddress, apiKey));
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("test")]
|
[DataRow("test")]
|
||||||
[DataRow("test@example")]
|
[DataRow("test@example")]
|
||||||
[DataRow("example.com")]
|
[DataRow("example.com")]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldArgumentExceptionForInvalidEmailAddress(string emailAddress)
|
public void ShouldArgumentExceptionForInvalidEmailAddress(string emailAddress)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string apiKey = "some-api-key";
|
string apiKey = "some-api-key";
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
new ApiKeyAuthentication(emailAddress, apiKey);
|
Assert.ThrowsExactly<ArgumentException>(() => new ApiKeyAuthentication(emailAddress, apiKey));
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using AMWD.Net.Api.Cloudflare;
|
using AMWD.Net.Api.Cloudflare;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.Auth
|
namespace Cloudflare.Tests.Auth
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class ApiTokenAuthenticationTest
|
public class ApiTokenAuthenticationTest
|
||||||
@@ -29,15 +29,12 @@ namespace Cloudflare.Core.Tests.Auth
|
|||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldArgumentNullExceptionForEmailAddress(string apiToken)
|
public void ShouldArgumentNullExceptionForEmailAddress(string apiToken)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
new ApiTokenAuthentication(apiToken);
|
Assert.ThrowsExactly<ArgumentNullException>(() => new ApiTokenAuthentication(apiToken));
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests
|
namespace Cloudflare.Tests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class CloudflareClientTest
|
public class CloudflareClientTest
|
||||||
@@ -72,15 +72,15 @@ namespace Cloudflare.Core.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullOnMissingAuthentication()
|
public void ShouldThrowArgumentNullOnMissingAuthentication()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<ArgumentNullException>(() =>
|
||||||
|
{
|
||||||
using var client = new CloudflareClient((IAuthentication)null);
|
using var client = new CloudflareClient((IAuthentication)null);
|
||||||
|
});
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -150,7 +150,6 @@ namespace Cloudflare.Core.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullForBaseUrlOnAssertClientOptions()
|
public void ShouldThrowArgumentNullForBaseUrlOnAssertClientOptions()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -158,14 +157,14 @@ namespace Cloudflare.Core.Tests
|
|||||||
.Setup(o => o.BaseUrl)
|
.Setup(o => o.BaseUrl)
|
||||||
.Returns((string)null);
|
.Returns((string)null);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<ArgumentNullException>(() =>
|
||||||
|
{
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
});
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
|
||||||
public void ShouldThrowArgumentOutOfRangeForTimeoutOnAssertClientOptions()
|
public void ShouldThrowArgumentOutOfRangeForTimeoutOnAssertClientOptions()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -173,16 +172,16 @@ namespace Cloudflare.Core.Tests
|
|||||||
.Setup(o => o.Timeout)
|
.Setup(o => o.Timeout)
|
||||||
.Returns(TimeSpan.Zero);
|
.Returns(TimeSpan.Zero);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
});
|
||||||
// Assert - ArgumentOutOfRangeException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(-1)]
|
[DataRow(-1)]
|
||||||
[DataRow(11)]
|
[DataRow(11)]
|
||||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
|
||||||
public void ShouldThrowArgumentOutOfRangeForMaxRetriesOnAssertClientOptions(int maxRetries)
|
public void ShouldThrowArgumentOutOfRangeForMaxRetriesOnAssertClientOptions(int maxRetries)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -190,14 +189,14 @@ namespace Cloudflare.Core.Tests
|
|||||||
.Setup(o => o.MaxRetries)
|
.Setup(o => o.MaxRetries)
|
||||||
.Returns(maxRetries);
|
.Returns(maxRetries);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
});
|
||||||
// Assert - ArgumentOutOfRangeException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullForUseProxyOnAssertClientOptions()
|
public void ShouldThrowArgumentNullForUseProxyOnAssertClientOptions()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -205,10 +204,11 @@ namespace Cloudflare.Core.Tests
|
|||||||
.Setup(o => o.UseProxy)
|
.Setup(o => o.UseProxy)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<ArgumentNullException>(() =>
|
||||||
|
{
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
});
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefault()
|
private void VerifyDefault()
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.CloudflareClientTests
|
namespace Cloudflare.Tests.CloudflareClientTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class DeleteAsyncTest
|
public class DeleteAsyncTest
|
||||||
{
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
private const string BaseUrl = "http://localhost/api/v4/";
|
private const string BaseUrl = "http://localhost/api/v4/";
|
||||||
|
|
||||||
private HttpMessageHandlerMock _httpHandlerMock;
|
private HttpMessageHandlerMock _httpHandlerMock;
|
||||||
@@ -44,46 +46,46 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ObjectDisposedException))]
|
|
||||||
public async Task ShouldThrowDisposed()
|
public async Task ShouldThrowDisposed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient() as CloudflareClient;
|
var client = GetClient() as CloudflareClient;
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.DeleteAsync<object>("test");
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ObjectDisposedException
|
await client.DeleteAsync<object>("test", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.DeleteAsync<object>(path);
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentNullException
|
await client.DeleteAsync<object>(path, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public async Task ShouldThrowArgumentOnRequestPath()
|
public async Task ShouldThrowArgumentOnRequestPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.DeleteAsync<object>("foo?bar=baz");
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentException
|
await client.DeleteAsync<object>("foo?bar=baz", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -99,7 +101,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.DeleteAsync<TestClass>("test");
|
var response = await client.DeleteAsync<TestClass>("test", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -108,21 +110,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Delete, callback.Method);
|
Assert.AreEqual(HttpMethod.Delete, callback.Method);
|
||||||
Assert.AreEqual("http://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("http://localhost/api/v4/test", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -154,7 +156,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
await client.DeleteAsync<TestClass>("foo");
|
await client.DeleteAsync<TestClass>("foo", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
Assert.Fail();
|
Assert.Fail();
|
||||||
}
|
}
|
||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
@@ -179,7 +181,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.DeleteAsync<string>("some-awesome-path");
|
var response = await client.DeleteAsync<string>("some-awesome-path", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -190,14 +192,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Delete, callback.Method);
|
Assert.AreEqual(HttpMethod.Delete, callback.Method);
|
||||||
Assert.AreEqual("http://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
Assert.AreEqual("http://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -223,7 +225,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(JsonReaderException))]
|
|
||||||
public async Task ShouldThrowExceptionOnInvalidResponse()
|
public async Task ShouldThrowExceptionOnInvalidResponse()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -235,8 +236,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.DeleteAsync<TestClass>("some-path");
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
|
{
|
||||||
|
await client.DeleteAsync<TestClass>("some-path", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefaults()
|
private void VerifyDefaults()
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.CloudflareClientTests
|
namespace Cloudflare.Tests.CloudflareClientTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class GetAsyncTest
|
public class GetAsyncTest
|
||||||
{
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
private const string BaseUrl = "http://localhost/api/v4/";
|
private const string BaseUrl = "http://localhost/api/v4/";
|
||||||
|
|
||||||
private HttpMessageHandlerMock _httpHandlerMock;
|
private HttpMessageHandlerMock _httpHandlerMock;
|
||||||
@@ -44,46 +46,46 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ObjectDisposedException))]
|
|
||||||
public async Task ShouldThrowDisposed()
|
public async Task ShouldThrowDisposed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient() as CloudflareClient;
|
var client = GetClient() as CloudflareClient;
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<object>("/test");
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ObjectDisposedException
|
await client.GetAsync<object>("/test", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<object>(path);
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentNullException
|
await client.GetAsync<object>(path, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public async Task ShouldThrowArgumentOnRequestPath()
|
public async Task ShouldThrowArgumentOnRequestPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<object>("/foo?bar=baz");
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentException
|
await client.GetAsync<object>("/foo?bar=baz", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -99,7 +101,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.GetAsync<TestClass>("test");
|
var response = await client.GetAsync<TestClass>("test", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -108,21 +110,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Get, callback.Method);
|
Assert.AreEqual(HttpMethod.Get, callback.Method);
|
||||||
Assert.AreEqual("http://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("http://localhost/api/v4/test", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -154,7 +156,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
await client.GetAsync<TestClass>("foo");
|
await client.GetAsync<TestClass>("foo", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
Assert.Fail();
|
Assert.Fail();
|
||||||
}
|
}
|
||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
@@ -182,7 +184,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
await client.GetAsync<TestClass>("foo");
|
await client.GetAsync<TestClass>("foo", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
Assert.Fail();
|
Assert.Fail();
|
||||||
}
|
}
|
||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
@@ -196,7 +198,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(HttpStatusCode.Unauthorized)]
|
[DataRow(HttpStatusCode.Unauthorized)]
|
||||||
[DataRow(HttpStatusCode.Forbidden)]
|
[DataRow(HttpStatusCode.Forbidden)]
|
||||||
[ExpectedException(typeof(CloudflareException))]
|
|
||||||
public async Task ShouldThrowCloudflareExceptionOnStatusCodeWhenDeserializeFails(HttpStatusCode statusCode)
|
public async Task ShouldThrowCloudflareExceptionOnStatusCodeWhenDeserializeFails(HttpStatusCode statusCode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -208,10 +209,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<TestClass>("foo");
|
await Assert.ThrowsExactlyAsync<CloudflareException>(async () =>
|
||||||
|
{
|
||||||
// Assert - CloudflareException
|
await client.GetAsync<TestClass>("foo", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -228,7 +230,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.GetAsync<string>("some-awesome-path", new TestFilter());
|
var response = await client.GetAsync<string>("some-awesome-path", new TestFilter(), TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -239,14 +241,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Get, callback.Method);
|
Assert.AreEqual(HttpMethod.Get, callback.Method);
|
||||||
Assert.AreEqual("http://localhost/api/v4/some-awesome-path?bar=08%2F15&test=filter-text", callback.Url);
|
Assert.AreEqual("http://localhost/api/v4/some-awesome-path?bar=08%2F15&test=filter-text", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -272,7 +274,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(JsonReaderException))]
|
|
||||||
public async Task ShouldThrowExceptionOnInvalidResponse()
|
public async Task ShouldThrowExceptionOnInvalidResponse()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -284,12 +285,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<TestClass>("some-path");
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
|
{
|
||||||
|
await client.GetAsync<TestClass>("some-path", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(CloudflareException))]
|
|
||||||
public async Task ShouldThrowCloudflareExceptionWhenDeserializeFails()
|
public async Task ShouldThrowCloudflareExceptionWhenDeserializeFails()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -301,10 +304,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.GetAsync<TestClass>("foo");
|
await Assert.ThrowsExactlyAsync<CloudflareException>(async () =>
|
||||||
|
{
|
||||||
// Assert - CloudflareException
|
await client.GetAsync<TestClass>("foo", cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefaults()
|
private void VerifyDefaults()
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.CloudflareClientTests
|
namespace Cloudflare.Tests.CloudflareClientTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class PatchAsyncTest
|
public class PatchAsyncTest
|
||||||
{
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
private const string BaseUrl = "https://localhost/api/v4/";
|
private const string BaseUrl = "https://localhost/api/v4/";
|
||||||
|
|
||||||
private HttpMessageHandlerMock _httpHandlerMock;
|
private HttpMessageHandlerMock _httpHandlerMock;
|
||||||
@@ -52,46 +54,46 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ObjectDisposedException))]
|
|
||||||
public async Task ShouldThrowDisposed()
|
public async Task ShouldThrowDisposed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient() as CloudflareClient;
|
var client = GetClient() as CloudflareClient;
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PatchAsync<object, object>("test", _request);
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ObjectDisposedException
|
await client.PatchAsync<object, object>("test", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PatchAsync<object, object>(path, _request);
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentNullException
|
await client.PatchAsync<object, object>(path, _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public async Task ShouldThrowArgumentOnRequestPath()
|
public async Task ShouldThrowArgumentOnRequestPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PatchAsync<object, object>("foo?bar=baz", _request);
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentException
|
await client.PatchAsync<object, object>("foo?bar=baz", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -107,7 +109,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PatchAsync<TestClass, TestClass>("test", _request);
|
var response = await client.PatchAsync<TestClass, TestClass>("test", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -116,21 +118,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -159,7 +161,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PatchAsync<TestClass, StringContent>("test", stringContent);
|
var response = await client.PatchAsync<TestClass, StringContent>("test", stringContent, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -168,21 +170,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -211,19 +213,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
try
|
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
|
||||||
{
|
|
||||||
// Act
|
|
||||||
await client.PatchAsync<object, object>("foo", _request);
|
|
||||||
Assert.Fail();
|
|
||||||
}
|
|
||||||
catch (AuthenticationException ex)
|
|
||||||
{
|
{
|
||||||
|
await client.PatchAsync<object, object>("foo", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNull(ex.InnerException);
|
Assert.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"4711: foo & baz.{Environment.NewLine}4712: Happy Error!", ex.Message);
|
Assert.AreEqual($"4711: foo & baz.{Environment.NewLine}4712: Happy Error!", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task ShouldReturnPlainText()
|
public async Task ShouldReturnPlainText()
|
||||||
@@ -239,7 +236,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PatchAsync<string, TestClass>("some-awesome-path", _request);
|
var response = await client.PatchAsync<string, TestClass>("some-awesome-path", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -250,14 +247,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
Assert.AreEqual(HttpMethod.Patch, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -283,7 +280,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(JsonReaderException))]
|
|
||||||
public async Task ShouldThrowExceptionOnInvalidResponse()
|
public async Task ShouldThrowExceptionOnInvalidResponse()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -295,8 +291,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PatchAsync<TestClass, TestClass>("some-path", _request);
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
|
{
|
||||||
|
await client.PatchAsync<TestClass, TestClass>("some-path", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefaults()
|
private void VerifyDefaults()
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.CloudflareClientTests
|
namespace Cloudflare.Tests.CloudflareClientTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class PostAsyncTest
|
public class PostAsyncTest
|
||||||
{
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
private const string BaseUrl = "https://localhost/api/v4/";
|
private const string BaseUrl = "https://localhost/api/v4/";
|
||||||
|
|
||||||
private HttpMessageHandlerMock _httpHandlerMock;
|
private HttpMessageHandlerMock _httpHandlerMock;
|
||||||
@@ -52,46 +54,46 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ObjectDisposedException))]
|
|
||||||
public async Task ShouldThrowDisposed()
|
public async Task ShouldThrowDisposed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient() as CloudflareClient;
|
var client = GetClient() as CloudflareClient;
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PostAsync<object, object>("test", _request);
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ObjectDisposedException
|
await client.PostAsync<object, object>("test", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PostAsync<object, object>(path, _request);
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentNullException
|
await client.PostAsync<object, object>(path, _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public async Task ShouldThrowArgumentOnRequestPath()
|
public async Task ShouldThrowArgumentOnRequestPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PostAsync<object, object>("foo?bar=baz", _request);
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentException
|
await client.PostAsync<object, object>("foo?bar=baz", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -107,7 +109,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PostAsync<TestClass, TestClass>("test", _request);
|
var response = await client.PostAsync<TestClass, TestClass>("test", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -116,21 +118,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -159,7 +161,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PostAsync<TestClass, StringContent>("test", stringContent);
|
var response = await client.PostAsync<TestClass, StringContent>("test", stringContent, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -168,21 +170,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -210,7 +212,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PostAsync<TestClass, object>("posting", null);
|
var response = await client.PostAsync<TestClass, object>("posting", null, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -219,21 +221,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/posting", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/posting", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -259,19 +261,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
try
|
// Act & Assert
|
||||||
|
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
|
||||||
{
|
{
|
||||||
// Act
|
await client.PostAsync<object, object>("foo", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
await client.PostAsync<object, object>("foo", _request);
|
});
|
||||||
Assert.Fail();
|
|
||||||
}
|
|
||||||
catch (AuthenticationException ex)
|
|
||||||
{
|
|
||||||
// Assert
|
|
||||||
Assert.IsNull(ex.InnerException);
|
Assert.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"4711: foo & baz.{Environment.NewLine}4712: Happy Error!", ex.Message);
|
Assert.AreEqual($"4711: foo & baz.{Environment.NewLine}4712: Happy Error!", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task ShouldReturnPlainText()
|
public async Task ShouldReturnPlainText()
|
||||||
@@ -287,7 +284,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PostAsync<string, TestClass>("some-awesome-path", _request);
|
var response = await client.PostAsync<string, TestClass>("some-awesome-path", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -298,14 +295,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -331,7 +328,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(JsonReaderException))]
|
|
||||||
public async Task ShouldThrowExceptionOnInvalidResponse()
|
public async Task ShouldThrowExceptionOnInvalidResponse()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -343,8 +339,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PostAsync<TestClass, TestClass>("some-path", _request);
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
|
{
|
||||||
|
await client.PostAsync<TestClass, TestClass>("some-path", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -361,7 +360,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PostAsync<string, TestClass>("path", _request);
|
var response = await client.PostAsync<string, TestClass>("path", _request, cancellationToken: TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -372,14 +371,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
Assert.AreEqual(HttpMethod.Post, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/path", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/path", callback.Url);
|
||||||
Assert.AreEqual(@"{""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ using AMWD.Net.Api.Cloudflare;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.CloudflareClientTests
|
namespace Cloudflare.Tests.CloudflareClientTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class PutAsyncTest
|
public class PutAsyncTest
|
||||||
{
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
|
|
||||||
private const string BaseUrl = "https://localhost/api/v4/";
|
private const string BaseUrl = "https://localhost/api/v4/";
|
||||||
|
|
||||||
private HttpMessageHandlerMock _httpHandlerMock;
|
private HttpMessageHandlerMock _httpHandlerMock;
|
||||||
@@ -52,46 +54,46 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ObjectDisposedException))]
|
|
||||||
public async Task ShouldThrowDisposed()
|
public async Task ShouldThrowDisposed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient() as CloudflareClient;
|
var client = GetClient() as CloudflareClient;
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PutAsync<object, object>("test", _request);
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ObjectDisposedException
|
await client.PutAsync<object, object>("test", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
public async Task ShouldThrowArgumentNullOnRequestPath(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PutAsync<object, object>(path, _request);
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentNullException
|
await client.PutAsync<object, object>(path, _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public async Task ShouldThrowArgumentOnRequestPath()
|
public async Task ShouldThrowArgumentOnRequestPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PutAsync<object, object>("foo?bar=baz", _request);
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
|
{
|
||||||
// Assert - ArgumentException
|
await client.PutAsync<object, object>("foo?bar=baz", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -107,7 +109,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PutAsync<TestClass, TestClass>("test", _request);
|
var response = await client.PutAsync<TestClass, TestClass>("test", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -116,21 +118,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -159,7 +161,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PutAsync<TestClass, StringContent>("test", stringContent);
|
var response = await client.PutAsync<TestClass, StringContent>("test", stringContent, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -168,21 +170,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/test", callback.Url);
|
||||||
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
Assert.AreEqual(@"{""test"":""HERE ?""}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -210,7 +212,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PutAsync<TestClass, object>("putput", null);
|
var response = await client.PutAsync<TestClass, object>("putput", null, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -219,21 +221,21 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
Assert.IsNotNull(response.Messages);
|
Assert.IsNotNull(response.Messages);
|
||||||
Assert.IsNull(response.ResultInfo);
|
Assert.IsNull(response.ResultInfo);
|
||||||
|
|
||||||
Assert.AreEqual(0, response.Errors.Count);
|
Assert.IsEmpty(response.Errors);
|
||||||
Assert.AreEqual(0, response.Messages.Count);
|
Assert.IsEmpty(response.Messages);
|
||||||
|
|
||||||
Assert.IsNotNull(response.Result);
|
Assert.IsNotNull(response.Result);
|
||||||
Assert.AreEqual("some-string", response.Result.Str);
|
Assert.AreEqual("some-string", response.Result.Str);
|
||||||
Assert.AreEqual(123, response.Result.Int);
|
Assert.AreEqual(123, response.Result.Int);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/putput", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/putput", callback.Url);
|
||||||
Assert.IsNull(callback.Content);
|
Assert.IsNull(callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -262,7 +264,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
await client.PutAsync<object, object>("foo", _request);
|
await client.PutAsync<object, object>("foo", _request, TestContext.CancellationTokenSource.Token);
|
||||||
Assert.Fail();
|
Assert.Fail();
|
||||||
}
|
}
|
||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
@@ -287,7 +289,7 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await client.PutAsync<string, TestClass>("some-awesome-path", _request);
|
var response = await client.PutAsync<string, TestClass>("some-awesome-path", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -298,14 +300,14 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
Assert.AreEqual("This is an awesome text ;-)", response.Result);
|
||||||
|
|
||||||
Assert.AreEqual(1, _httpHandlerMock.Callbacks.Count);
|
Assert.HasCount(1, _httpHandlerMock.Callbacks);
|
||||||
|
|
||||||
var callback = _httpHandlerMock.Callbacks.First();
|
var callback = _httpHandlerMock.Callbacks.First();
|
||||||
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
Assert.AreEqual(HttpMethod.Put, callback.Method);
|
||||||
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
Assert.AreEqual("https://localhost/api/v4/some-awesome-path?bar=08%2F15", callback.Url);
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
Assert.AreEqual(@"{""string"":""Happy Testing!"",""integer"":54321}", callback.Content);
|
||||||
|
|
||||||
Assert.AreEqual(3, callback.Headers.Count);
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
||||||
@@ -331,7 +333,6 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(JsonReaderException))]
|
|
||||||
public async Task ShouldThrowExceptionOnInvalidResponse()
|
public async Task ShouldThrowExceptionOnInvalidResponse()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -343,8 +344,11 @@ namespace Cloudflare.Core.Tests.CloudflareClientTests
|
|||||||
|
|
||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
await client.PutAsync<TestClass, TestClass>("some-path", _request);
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
|
{
|
||||||
|
await client.PutAsync<TestClass, TestClass>("some-path", _request, TestContext.CancellationTokenSource.Token);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefaults()
|
private void VerifyDefaults()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using AMWD.Net.Api.Cloudflare;
|
using AMWD.Net.Api.Cloudflare;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests.Extensions
|
namespace Cloudflare.Tests.Extensions
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class EnumExtensionsTest
|
public class EnumExtensionsTest
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using AMWD.Net.Api.Cloudflare;
|
||||||
using AMWD.Net.Api.Cloudflare;
|
|
||||||
|
|
||||||
namespace Cloudflare.Tests.Extensions
|
namespace Cloudflare.Tests.Extensions
|
||||||
{
|
{
|
||||||
@@ -22,43 +21,34 @@ namespace Cloudflare.Tests.Extensions
|
|||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullExceptionForValidateId(string name)
|
public void ShouldThrowArgumentNullExceptionForValidateId(string name)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
name.ValidateCloudflareId();
|
Assert.ThrowsExactly<ArgumentNullException>(() => name.ValidateCloudflareId());
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldThrowArgumentOutOfRangeExceptionForValidateId()
|
public void ShouldThrowArgumentOutOfRangeExceptionForValidateId()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string id = new('a', 33);
|
string id = new('a', 33);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
id.ValidateCloudflareId();
|
Assert.ThrowsExactly<ArgumentException>(() => id.ValidateCloudflareId());
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("023e105f4ecef8ad9ca31a8372d0c35")]
|
[DataRow("023e105f4ecef8ad9ca31a8372d0c35")]
|
||||||
[DataRow("023e105f4ecef8ad9ca31a8372d0C353")]
|
[DataRow("023e105f4ecef8ad9ca31a8372d0C353")]
|
||||||
[DataRow("023e105f4ecef8ad9ca31a8372d0y353")]
|
[DataRow("023e105f4ecef8ad9ca31a8372d0y353")]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldThrowArgumentExceptionForValidateId(string id)
|
public void ShouldThrowArgumentExceptionForValidateId(string id)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
id.ValidateCloudflareId();
|
Assert.ThrowsExactly<ArgumentException>(() => id.ValidateCloudflareId());
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -77,28 +67,22 @@ namespace Cloudflare.Tests.Extensions
|
|||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullExceptionForValidateName(string name)
|
public void ShouldThrowArgumentNullExceptionForValidateName(string name)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
name.ValidateCloudflareName();
|
Assert.ThrowsExactly<ArgumentNullException>(() => name.ValidateCloudflareName());
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldThrowArgumentOutOfRangeExceptionForValidateName()
|
public void ShouldThrowArgumentOutOfRangeExceptionForValidateName()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string name = new('a', 254);
|
string name = new('a', 254);
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
name.ValidateCloudflareName();
|
Assert.ThrowsExactly<ArgumentException>(() => name.ValidateCloudflareName());
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -117,30 +101,24 @@ namespace Cloudflare.Tests.Extensions
|
|||||||
[DataRow(null)]
|
[DataRow(null)]
|
||||||
[DataRow("")]
|
[DataRow("")]
|
||||||
[DataRow(" ")]
|
[DataRow(" ")]
|
||||||
[ExpectedException(typeof(ArgumentNullException))]
|
|
||||||
public void ShouldThrowArgumentNullExceptionForValidateEmail(string email)
|
public void ShouldThrowArgumentNullExceptionForValidateEmail(string email)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
email.ValidateCloudflareEmailAddress();
|
Assert.ThrowsExactly<ArgumentNullException>(() => email.ValidateCloudflareEmailAddress());
|
||||||
|
|
||||||
// Assert - ArgumentNullException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("test")]
|
[DataRow("test")]
|
||||||
[DataRow("test@example")]
|
[DataRow("test@example")]
|
||||||
[DataRow("example.com")]
|
[DataRow("example.com")]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldThrowArgumentExceptionForValidateEmail(string email)
|
public void ShouldThrowArgumentExceptionForValidateEmail(string email)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
email.ValidateCloudflareEmailAddress();
|
Assert.ThrowsExactly<ArgumentException>(() => email.ValidateCloudflareEmailAddress());
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -157,16 +135,13 @@ namespace Cloudflare.Tests.Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
|
||||||
public void ShouldThrowArgumentExceptionForValidateLength()
|
public void ShouldThrowArgumentExceptionForValidateLength()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string str = "SomeExampleString";
|
string str = "SomeExampleString";
|
||||||
|
|
||||||
// Act
|
// Act & Assert
|
||||||
str.ValidateLength(10, nameof(str));
|
Assert.ThrowsExactly<ArgumentException>(() => str.ValidateLength(10, nameof(str)));
|
||||||
|
|
||||||
// Assert - ArgumentException
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Cloudflare.Core.Tests
|
namespace Cloudflare.Tests
|
||||||
{
|
{
|
||||||
internal class HttpMessageHandlerMock
|
internal class HttpMessageHandlerMock
|
||||||
{
|
{
|
||||||
@@ -25,11 +24,11 @@ namespace Cloudflare.Core.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (request.Content != null)
|
if (request.Content != null)
|
||||||
callback.Content = await request.Content.ReadAsStringAsync();
|
callback.Content = await request.Content.ReadAsStringAsync(ct);
|
||||||
|
|
||||||
Callbacks.Add(callback);
|
Callbacks.Add(callback);
|
||||||
})
|
})
|
||||||
.ReturnsAsync(() => Responses.Dequeue());
|
.ReturnsAsync(Responses.Dequeue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HttpMessageRequestCallback> Callbacks { get; } = [];
|
public List<HttpMessageRequestCallback> Callbacks { get; } = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user