1
0

Reorganized namespaces
All checks were successful
Branch Build / build-test-deploy (push) Successful in 1m19s

This commit is contained in:
2026-03-17 17:25:13 +01:00
parent 79567c730c
commit 3f8cece95c
21 changed files with 1337 additions and 1404 deletions

View File

@@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Channel implementations (SMS, WhatsApp, ...) are extensions to the `ILinkMobilityClient` interface.
- Reorganized namespaces to reflect parts of the API
### Removed
- `IQueryParameter` as no usage on API docs found (for now)
## [v0.1.1] - 2026-03-13

View File

@@ -10,11 +10,11 @@ So I decided to implement the current available API myself with a more modern (a
---
Published under [MIT License] (see [**tl;dr**Legal])
Published under [MIT License] (see [choose a license])
[LINK Mobility REST API]: https://developer.linkmobility.eu/
[outdated repository]: https://github.com/websms-com/websmscom-csharp
[.NET Standard 2.0]: https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0
[MIT License]: LICENSE.txt
[**tl;dr**Legal]: https://www.tldrlegal.com/license/mit-license
[choose a license]: https://choosealicense.com/licenses/mit/

View File

@@ -1,7 +1,8 @@
namespace AMWD.Net.Api.LinkMobility
{
/// <summary>
/// Custom status codes as defined by <see href="https://developer.linkmobility.eu/sms-api/rest-api#section/Status-codes">Link Mobility</see>.
/// Custom status codes as defined by
/// <see href="https://developer.linkmobility.eu/sms-api/rest-api#section/Status-codes">LINK Mobility</see>.
/// </summary>
public enum StatusCodes : int
{

View File

@@ -15,8 +15,7 @@ namespace AMWD.Net.Api.LinkMobility
/// <typeparam name="TRequest">The type of the request.</typeparam>
/// <param name="requestPath">The path of the API endpoint.</param>
/// <param name="request">The request data.</param>
/// <param name="queryParams">Optional query parameters.</param>
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, IQueryParameter? queryParams = null, CancellationToken cancellationToken = default);
Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, CancellationToken cancellationToken = default);
}
}

View File

@@ -7,6 +7,7 @@ using System.Security.Authentication;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Net.Api.LinkMobility.Utils;
namespace AMWD.Net.Api.LinkMobility
{
@@ -79,12 +80,12 @@ namespace AMWD.Net.Api.LinkMobility
}
/// <inheritdoc/>
public async Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, IQueryParameter? queryParams = null, CancellationToken cancellationToken = default)
public async Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ValidateRequestPath(requestPath);
string requestUrl = BuildRequestUrl(requestPath, queryParams);
string requestUrl = BuildRequestUrl(requestPath);
var httpContent = ConvertRequest(request);
var httpRequest = new HttpRequestMessage
@@ -99,7 +100,7 @@ namespace AMWD.Net.Api.LinkMobility
return response;
}
private string BuildRequestUrl(string requestPath, IQueryParameter? queryParams = null)
private string BuildRequestUrl(string requestPath)
{
string path = requestPath.Trim().TrimStart('/');
var param = new Dictionary<string, string>();
@@ -110,13 +111,6 @@ namespace AMWD.Net.Api.LinkMobility
param[kvp.Key] = kvp.Value;
}
var customQueryParams = queryParams?.GetQueryParameters();
if (customQueryParams?.Count > 0)
{
foreach (var kvp in customQueryParams)
param[kvp.Key] = kvp.Value;
}
if (param.Count == 0)
return path;

View File

@@ -1,13 +0,0 @@
namespace AMWD.Net.Api.LinkMobility
{
/// <summary>
/// Represents options defined via query parameters.
/// </summary>
public interface IQueryParameter
{
/// <summary>
/// Retrieves the query parameters.
/// </summary>
IReadOnlyDictionary<string, string> GetQueryParameters();
}
}

View File

@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Specifies the type of sender address.

View File

@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Defines the types of delivery methods on a report.

View File

@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Specifies the message type.

View File

@@ -1,4 +1,4 @@
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Request to send a text message to a list of recipients.

View File

@@ -1,4 +1,4 @@
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Request to send a text message to a list of recipients.

View File

@@ -2,7 +2,7 @@
using System.Threading.Tasks;
using AMWD.Net.Api.LinkMobility.Utils;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Text
{
/// <summary>
/// Implementation of text messaging (SMS). <see href="https://developer.linkmobility.eu/sms-api/rest-api">API</see>

View File

@@ -1,6 +1,6 @@
using System.Globalization;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Utils
{
internal static class SerializerExtensions
{

View File

@@ -1,9 +1,15 @@
namespace AMWD.Net.Api.LinkMobility
using AMWD.Net.Api.LinkMobility.Utils;
namespace AMWD.Net.Api.LinkMobility.Webhook
{
/// <summary>
/// Representes the response to an incoming message notification. (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
/// Representes the response to an incoming message notification.
/// (See <see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
/// </summary>
public class IncomingMessageNotificationResponse
/// <remarks>
/// This notification acknowlegement is the same for all webhooks of LINK Mobility.
/// </remarks>
public class NotificationResponse
{
/// <summary>
/// Gets or sets the status code of the response.

View File

@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
{
/// <summary>
/// Defines the delivery status of a message on a report.

View File

@@ -0,0 +1,30 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
{
/// <summary>
/// Defines the type of notification.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum TextMessageType
{
/// <summary>
/// Notification of an incoming text message.
/// </summary>
[EnumMember(Value = "text")]
Text = 1,
/// <summary>
/// Notification of an incoming binary message.
/// </summary>
[EnumMember(Value = "binary")]
Binary = 2,
/// <summary>
/// Notification of a delivery report.
/// </summary>
[EnumMember(Value = "deliveryReport")]
DeliveryReport = 3
}
}

View File

@@ -1,19 +1,20 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
using AMWD.Net.Api.LinkMobility.Text;
using AMWD.Net.Api.LinkMobility.Utils;
namespace AMWD.Net.Api.LinkMobility
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
{
/// <summary>
/// Represents a notification for an incoming message or delivery report. (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
/// Represents a notification for an incoming text message or delivery report.
/// (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
/// </summary>
public class IncomingMessageNotification
public class TextNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="IncomingMessageNotification"/> class.
/// Initializes a new instance of the <see cref="TextNotification"/> class.
/// </summary>
/// <param name="notificationId">The notification id.</param>
/// <param name="transferId">The transfer id.</param>
public IncomingMessageNotification(string notificationId, string transferId)
public TextNotification(string notificationId, string transferId)
{
NotificationId = notificationId;
TransferId = transferId;
@@ -23,7 +24,7 @@ namespace AMWD.Net.Api.LinkMobility
/// Defines the content type of your notification.
/// </summary>
[JsonProperty("messageType")]
public Type MessageType { get; set; }
public TextMessageType MessageType { get; set; }
/// <summary>
/// 20 digit long identification of your notification.
@@ -32,7 +33,7 @@ namespace AMWD.Net.Api.LinkMobility
public string NotificationId { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// Unique transfer-id to connect the deliveryReport to the initial message.
/// </summary>
@@ -40,7 +41,7 @@ namespace AMWD.Net.Api.LinkMobility
public string TransferId { get; set; }
/// <summary>
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
/// <br/>
/// Indicates whether you received message is a SMS or a flash-SMS.
/// </summary>
@@ -54,7 +55,7 @@ namespace AMWD.Net.Api.LinkMobility
public string? SenderAddress { get; set; }
/// <summary>
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
/// <br/>
/// <see cref="AddressType.International"/> - defines the number format of the mobile originated <see cref="SenderAddress"/>.
/// International numbers always includes the country prefix.
@@ -72,7 +73,7 @@ namespace AMWD.Net.Api.LinkMobility
public string? RecipientAddress { get; set; }
/// <summary>
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
/// <br/>
/// Defines the number format of the mobile originated message.
/// </summary>
@@ -80,7 +81,7 @@ namespace AMWD.Net.Api.LinkMobility
public AddressType? RecipientAddressType { get; set; }
/// <summary>
/// <see cref="Type.Text"/>:
/// <see cref="Text.TextMessageType.Text"/>:
/// <br/>
/// Text body of the message encoded in <c>UTF-8</c>.
/// In the case of concatenated SMS it will contain the complete content of all segments.
@@ -89,7 +90,7 @@ namespace AMWD.Net.Api.LinkMobility
public string? TextMessageContent { get; set; }
/// <summary>
/// <see cref="Type.Binary"/>:
/// <see cref="Text.TextMessageType.Binary"/>:
/// <br/>
/// Indicates whether a user-data-header is included within a <c>Base64</c> encoded byte segment.
/// </summary>
@@ -97,7 +98,7 @@ namespace AMWD.Net.Api.LinkMobility
public bool? UserDataHeaderPresent { get; set; }
/// <summary>
/// <see cref="Type.Binary"/>:
/// <see cref="Text.TextMessageType.Binary"/>:
/// <br/>
/// Content of a binary SMS in an array of <c>Base64</c> strings (URL safe).
/// </summary>
@@ -105,7 +106,7 @@ namespace AMWD.Net.Api.LinkMobility
public IReadOnlyCollection<string>? BinaryMessageContent { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// Status of the message.
/// </summary>
@@ -113,7 +114,7 @@ namespace AMWD.Net.Api.LinkMobility
public DeliveryStatus? DeliveryReportMessageStatus { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// ISO 8601 timestamp. Point of time sending the message to recipients address.
/// </summary>
@@ -121,7 +122,7 @@ namespace AMWD.Net.Api.LinkMobility
public DateTime? SentOn { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// ISO 8601 timestamp. Point of time of submitting the message to the mobile operators network.
/// </summary>
@@ -129,7 +130,7 @@ namespace AMWD.Net.Api.LinkMobility
public DateTime? DeliveredOn { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// Type of delivery used to send the message.
/// </summary>
@@ -137,7 +138,7 @@ namespace AMWD.Net.Api.LinkMobility
public DeliveryType? DeliveredAs { get; set; }
/// <summary>
/// <see cref="Type.DeliveryReport"/>:
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
/// <br/>
/// In the case of a delivery report, the <see cref="ClientMessageId"/> contains the optional submitted message id.
/// </summary>
@@ -145,43 +146,18 @@ namespace AMWD.Net.Api.LinkMobility
public string? ClientMessageId { get; set; }
/// <summary>
/// Defines the type of notification.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum Type
{
/// <summary>
/// Notification of an incoming text message.
/// </summary>
[EnumMember(Value = "text")]
Text = 1,
/// <summary>
/// Notification of an incoming binary message.
/// </summary>
[EnumMember(Value = "binary")]
Binary = 2,
/// <summary>
/// Notification of a delivery report.
/// </summary>
[EnumMember(Value = "deliveryReport")]
DeliveryReport = 3
}
/// <summary>
/// Tries to parse the given content as <see cref="IncomingMessageNotification"/>.
/// Tries to parse the given content as <see cref="TextNotification"/>.
/// </summary>
/// <param name="json">The given content (should be the notification json).</param>
/// <param name="notification">The deserialized notification.</param>
/// <returns>
/// <see langword="true"/> if the content could be parsed; otherwise, <see langword="false"/>.
/// </returns>
public static bool TryParse(string json, out IncomingMessageNotification? notification)
public static bool TryParse(string json, out TextNotification? notification)
{
try
{
notification = json.DeserializeObject<IncomingMessageNotification>();
notification = json.DeserializeObject<TextNotification>();
return notification != null;
}
catch

View File

@@ -145,7 +145,7 @@ namespace LinkMobility.Tests
var client = GetClient();
// Act
var response = await client.PostAsync<TestClass, TestClass>("test", _request, null, TestContext.CancellationToken);
var response = await client.PostAsync<TestClass, TestClass>("test", _request, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
@@ -166,57 +166,12 @@ namespace LinkMobility.Tests
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Exactly(2));
VerifyNoOtherCalls();
}
[TestMethod]
public async Task ShouldAddCustomQueryParameters()
{
// Arrange
var queryParams = new TestParams();
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(@"{ ""string"": ""some-string"", ""integer"": 123 }", Encoding.UTF8, "application/json"),
});
var client = GetClient();
// Act
var response = await client.PostAsync<TestClass, TestClass>("params/path", _request, queryParams, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
Assert.AreEqual("https://localhost/rest/params/path?test=query+text", callback.Url);
Assert.AreEqual(@"{""string"":""Happy Testing"",""integer"":54321}", callback.Content);
Assert.HasCount(3, callback.Headers);
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
Assert.AreEqual("application/json", callback.Headers["Accept"]);
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
VerifyNoOtherCalls();
}
[TestMethod]
public void ShouldDisposeHttpClient()
{
@@ -227,9 +182,7 @@ namespace LinkMobility.Tests
client.Dispose();
// Assert
_httpMessageHandlerMock.Mock
.Protected()
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
VerifyNoOtherCalls();
}
@@ -245,9 +198,7 @@ namespace LinkMobility.Tests
client.Dispose();
// Assert
_httpMessageHandlerMock.Mock
.Protected()
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
VerifyNoOtherCalls();
}
@@ -320,7 +271,7 @@ namespace LinkMobility.Tests
// Act & Assert
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
{
await client.PostAsync<object, TestClass>("/request/path", _request, null, TestContext.CancellationToken);
await client.PostAsync<object, TestClass>("/request/path", _request, TestContext.CancellationToken);
});
}
@@ -336,7 +287,7 @@ namespace LinkMobility.Tests
// Act & Assert
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
{
await client.PostAsync<object, TestClass>(path, _request, null, TestContext.CancellationToken);
await client.PostAsync<object, TestClass>(path, _request, TestContext.CancellationToken);
});
}
@@ -349,7 +300,7 @@ namespace LinkMobility.Tests
// Act & Assert
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
{
await client.PostAsync<object, TestClass>("foo?bar=baz", _request, null, TestContext.CancellationToken);
await client.PostAsync<object, TestClass>("foo?bar=baz", _request, TestContext.CancellationToken);
});
}
@@ -366,7 +317,7 @@ namespace LinkMobility.Tests
var client = GetClient();
// Act
var response = await client.PostAsync<TestClass, TestClass>("/request/path", _request, null, TestContext.CancellationToken);
var response = await client.PostAsync<TestClass, TestClass>("/request/path", _request, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
@@ -389,9 +340,7 @@ namespace LinkMobility.Tests
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
VerifyNoOtherCalls();
@@ -411,7 +360,7 @@ namespace LinkMobility.Tests
var client = GetClient();
// Act
var response = await client.PostAsync<TestClass, HttpContent>("/request/path", stringContent, null, TestContext.CancellationToken);
var response = await client.PostAsync<TestClass, HttpContent>("/request/path", stringContent, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
@@ -434,9 +383,7 @@ namespace LinkMobility.Tests
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
VerifyNoOtherCalls();
@@ -455,7 +402,7 @@ namespace LinkMobility.Tests
var client = GetClient();
// Act
var response = await client.PostAsync<TestClass, object>("posting", null, null, TestContext.CancellationToken);
var response = await client.PostAsync<TestClass, object>("posting", null, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
@@ -479,9 +426,7 @@ namespace LinkMobility.Tests
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
}
[TestMethod]
@@ -501,7 +446,7 @@ namespace LinkMobility.Tests
// Act & Assert
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
{
await client.PostAsync<object, TestClass>("foo", _request, null, TestContext.CancellationToken);
await client.PostAsync<object, TestClass>("foo", _request, TestContext.CancellationToken);
});
Assert.IsNull(ex.InnerException);
Assert.AreEqual($"HTTP auth missing: {statusCode}", ex.Message);
@@ -524,7 +469,7 @@ namespace LinkMobility.Tests
// Act & Assert
var ex = await Assert.ThrowsExactlyAsync<ApplicationException>(async () =>
{
await client.PostAsync<object, TestClass>("foo", _request, null, TestContext.CancellationToken);
await client.PostAsync<object, TestClass>("foo", _request, TestContext.CancellationToken);
});
Assert.IsNull(ex.InnerException);
Assert.AreEqual($"Unknown HTTP response: {statusCode}", ex.Message);
@@ -545,7 +490,7 @@ namespace LinkMobility.Tests
// Act & Assert
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
{
await client.PostAsync<TestClass, TestClass>("some-path", _request, null, TestContext.CancellationToken);
await client.PostAsync<TestClass, TestClass>("some-path", _request, TestContext.CancellationToken);
});
}
@@ -563,7 +508,7 @@ namespace LinkMobility.Tests
var client = GetClient();
// Act
string response = await client.PostAsync<string, TestClass>("path", _request, null, TestContext.CancellationToken);
string response = await client.PostAsync<string, TestClass>("path", _request, TestContext.CancellationToken);
// Assert
Assert.IsNotNull(response);
@@ -586,9 +531,7 @@ namespace LinkMobility.Tests
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
_httpMessageHandlerMock.Mock
.Protected()
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
VerifyNoOtherCalls();
@@ -638,16 +581,5 @@ namespace LinkMobility.Tests
[JsonProperty("integer")]
public int Int { get; set; }
}
private class TestParams : IQueryParameter
{
public IReadOnlyDictionary<string, string> GetQueryParameters()
{
return new Dictionary<string, string>
{
{ "test", "query text" }
};
}
}
}
}

View File

@@ -6,10 +6,11 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Net.Api.LinkMobility;
using AMWD.Net.Api.LinkMobility.Text;
using LinkMobility.Tests.Helpers;
using Moq.Protected;
namespace LinkMobility.Tests.Sms
namespace LinkMobility.Tests.Text
{
[TestClass]
public class SendBinaryMessageTest

View File

@@ -6,10 +6,11 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Net.Api.LinkMobility;
using AMWD.Net.Api.LinkMobility.Text;
using LinkMobility.Tests.Helpers;
using Moq.Protected;
namespace LinkMobility.Tests.Sms
namespace LinkMobility.Tests.Text
{
[TestClass]
public class SendTextMessageTest

View File

@@ -1,9 +1,10 @@
using AMWD.Net.Api.LinkMobility;
using AMWD.Net.Api.LinkMobility.Text;
using AMWD.Net.Api.LinkMobility.Webhook.Text;
namespace LinkMobility.Tests.Models
namespace LinkMobility.Tests.Webhook.Text
{
[TestClass]
public class IncomingMessageNotificationTest
public class TextNotificationTest
{
[TestMethod]
public void ShouldParseAllPropertiesForTextNotification()
@@ -29,13 +30,13 @@ namespace LinkMobility.Tests.Models
}";
// Act
bool successful = IncomingMessageNotification.TryParse(json, out var notification);
bool successful = TextNotification.TryParse(json, out var notification);
// Assert
Assert.IsTrue(successful, "TryParse should return true for valid json");
Assert.IsNotNull(notification);
Assert.AreEqual(IncomingMessageNotification.Type.Text, notification.MessageType);
Assert.AreEqual(TextMessageType.Text, notification.MessageType);
Assert.AreEqual("notif-123", notification.NotificationId);
Assert.AreEqual("trans-456", notification.TransferId);
@@ -80,7 +81,7 @@ namespace LinkMobility.Tests.Models
string invalid = "this is not json";
// Act
bool successful = IncomingMessageNotification.TryParse(invalid, out var notification);
bool successful = TextNotification.TryParse(invalid, out var notification);
// Assert
Assert.IsFalse(successful);