Reorganized namespaces
All checks were successful
Branch Build / build-test-deploy (push) Successful in 1m13s
All checks were successful
Branch Build / build-test-deploy (push) Successful in 1m13s
This commit is contained in:
@@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Channel implementations (SMS, WhatsApp, ...) are extensions to the `ILinkMobilityClient` interface.
|
- 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
|
## [v0.1.1] - 2026-03-13
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public enum StatusCodes : int
|
public enum StatusCodes : int
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
||||||
/// <param name="requestPath">The path of the API endpoint.</param>
|
/// <param name="requestPath">The path of the API endpoint.</param>
|
||||||
/// <param name="request">The request data.</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>
|
/// <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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,12 +79,12 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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();
|
ThrowIfDisposed();
|
||||||
ValidateRequestPath(requestPath);
|
ValidateRequestPath(requestPath);
|
||||||
|
|
||||||
string requestUrl = BuildRequestUrl(requestPath, queryParams);
|
string requestUrl = BuildRequestUrl(requestPath);
|
||||||
var httpContent = ConvertRequest(request);
|
var httpContent = ConvertRequest(request);
|
||||||
|
|
||||||
var httpRequest = new HttpRequestMessage
|
var httpRequest = new HttpRequestMessage
|
||||||
@@ -99,7 +99,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildRequestUrl(string requestPath, IQueryParameter? queryParams = null)
|
private string BuildRequestUrl(string requestPath)
|
||||||
{
|
{
|
||||||
string path = requestPath.Trim().TrimStart('/');
|
string path = requestPath.Trim().TrimStart('/');
|
||||||
var param = new Dictionary<string, string>();
|
var param = new Dictionary<string, string>();
|
||||||
@@ -110,13 +110,6 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
param[kvp.Key] = kvp.Value;
|
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)
|
if (param.Count == 0)
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the type of sender address.
|
/// Specifies the type of sender address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public enum AddressType
|
public enum AddressType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// National number.
|
/// National number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "national")]
|
[EnumMember(Value = "national")]
|
||||||
National = 1,
|
National = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// International number.
|
/// International number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "international")]
|
[EnumMember(Value = "international")]
|
||||||
International = 2,
|
International = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Alphanumeric sender ID.
|
/// Alphanumeric sender ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "alphanumeric")]
|
[EnumMember(Value = "alphanumeric")]
|
||||||
Alphanumeric = 3,
|
Alphanumeric = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shortcode.
|
/// Shortcode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "shortcode")]
|
[EnumMember(Value = "shortcode")]
|
||||||
Shortcode = 4,
|
Shortcode = 4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the types of delivery methods on a report.
|
/// Defines the types of delivery methods on a report.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public enum DeliveryType
|
public enum DeliveryType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message sent via SMS.
|
/// Message sent via SMS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "sms")]
|
[EnumMember(Value = "sms")]
|
||||||
Sms = 1,
|
Sms = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message sent as Push message.
|
/// Message sent as Push message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "push")]
|
[EnumMember(Value = "push")]
|
||||||
Push = 2,
|
Push = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message sent as failover SMS.
|
/// Message sent as failover SMS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "failover-sms")]
|
[EnumMember(Value = "failover-sms")]
|
||||||
FailoverSms = 3,
|
FailoverSms = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message sent as voice message.
|
/// Message sent as voice message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "voice")]
|
[EnumMember(Value = "voice")]
|
||||||
Voice = 4
|
Voice = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the message type.
|
/// Specifies the message type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public enum MessageType
|
public enum MessageType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The message is sent as defined in the account settings.
|
/// The message is sent as defined in the account settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "default")]
|
[EnumMember(Value = "default")]
|
||||||
Default = 1,
|
Default = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The message is sent as voice call.
|
/// The message is sent as voice call.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "voice")]
|
[EnumMember(Value = "voice")]
|
||||||
Voice = 2,
|
Voice = 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,130 +1,130 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request to send a text message to a list of recipients.
|
/// Request to send a text message to a list of recipients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SendBinaryMessageRequest
|
public class SendBinaryMessageRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SendBinaryMessageRequest"/> class.
|
/// Initializes a new instance of the <see cref="SendBinaryMessageRequest"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="messageContent">A binary message as base64 encoded lines.</param>
|
/// <param name="messageContent">A binary message as base64 encoded lines.</param>
|
||||||
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
||||||
public SendBinaryMessageRequest(IReadOnlyCollection<string> messageContent, IReadOnlyCollection<string> recipientAddressList)
|
public SendBinaryMessageRequest(IReadOnlyCollection<string> messageContent, IReadOnlyCollection<string> recipientAddressList)
|
||||||
{
|
{
|
||||||
MessageContent = messageContent;
|
MessageContent = messageContent;
|
||||||
RecipientAddressList = recipientAddressList;
|
RecipientAddressList = recipientAddressList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// May contain a freely definable message id.
|
/// May contain a freely definable message id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("clientMessageId")]
|
[JsonProperty("clientMessageId")]
|
||||||
public string? ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// The content category that is used to categorize the message (used for blacklisting).
|
/// The content category that is used to categorize the message (used for blacklisting).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The following content categories are supported: <see cref="ContentCategory.Informational"/> or <see cref="ContentCategory.Advertisement"/>.
|
/// The following content categories are supported: <see cref="ContentCategory.Informational"/> or <see cref="ContentCategory.Advertisement"/>.
|
||||||
/// If no content category is provided, the default setting is used (may be changed inside the web interface).
|
/// If no content category is provided, the default setting is used (may be changed inside the web interface).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("contentCategory")]
|
[JsonProperty("contentCategory")]
|
||||||
public ContentCategory? ContentCategory { get; set; }
|
public ContentCategory? ContentCategory { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Array of <c>Base64</c> encoded binary data.
|
/// Array of <c>Base64</c> encoded binary data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Every element of the array corresponds to a message segment.
|
/// Every element of the array corresponds to a message segment.
|
||||||
/// The binary data is transmitted without being changed (using 8 bit alphabet).
|
/// The binary data is transmitted without being changed (using 8 bit alphabet).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("messageContent")]
|
[JsonProperty("messageContent")]
|
||||||
public IReadOnlyCollection<string> MessageContent { get; set; }
|
public IReadOnlyCollection<string> MessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// When setting a <c>NotificationCallbackUrl</c> all delivery reports are forwarded to this URL.
|
/// When setting a <c>NotificationCallbackUrl</c> all delivery reports are forwarded to this URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("notificationCallbackUrl")]
|
[JsonProperty("notificationCallbackUrl")]
|
||||||
public string? NotificationCallbackUrl { get; set; }
|
public string? NotificationCallbackUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Priority of the message.
|
/// Priority of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Must not exceed the value configured for the account used to send the message.
|
/// Must not exceed the value configured for the account used to send the message.
|
||||||
/// For more information please contact our customer service.
|
/// For more information please contact our customer service.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("priority")]
|
[JsonProperty("priority")]
|
||||||
public int? Priority { get; set; }
|
public int? Priority { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of recipients (E.164 formatted <see href="https://en.wikipedia.org/wiki/MSISDN">MSISDN</see>s)
|
/// List of recipients (E.164 formatted <see href="https://en.wikipedia.org/wiki/MSISDN">MSISDN</see>s)
|
||||||
/// to whom the message should be sent.
|
/// to whom the message should be sent.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// The list of recipients may contain a maximum of <em>1000</em> entries.
|
/// The list of recipients may contain a maximum of <em>1000</em> entries.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("recipientAddressList")]
|
[JsonProperty("recipientAddressList")]
|
||||||
public IReadOnlyCollection<string> RecipientAddressList { get; set; }
|
public IReadOnlyCollection<string> RecipientAddressList { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="true"/>: The message is sent as flash SMS (displayed directly on the screen of the mobile phone).
|
/// <see langword="true"/>: The message is sent as flash SMS (displayed directly on the screen of the mobile phone).
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="false"/>: The message is sent as standard text SMS (default).
|
/// <see langword="false"/>: The message is sent as standard text SMS (default).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("sendAsFlashSms")]
|
[JsonProperty("sendAsFlashSms")]
|
||||||
public bool? SendAsFlashSms { get; set; }
|
public bool? SendAsFlashSms { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Address of the sender (assigned to the account) from which the message is sent.
|
/// Address of the sender (assigned to the account) from which the message is sent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddress")]
|
[JsonProperty("senderAddress")]
|
||||||
public string? SenderAddress { get; set; }
|
public string? SenderAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// The sender address type.
|
/// The sender address type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddressType")]
|
[JsonProperty("senderAddressType")]
|
||||||
public AddressType? SenderAddressType { get; set; }
|
public AddressType? SenderAddressType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="true"/>: The transmission is only simulated, no SMS is sent.
|
/// <see langword="true"/>: The transmission is only simulated, no SMS is sent.
|
||||||
/// Depending on the number of recipients the status code <see cref="StatusCodes.Ok"/> or <see cref="StatusCodes.OkQueued"/> is returned.
|
/// Depending on the number of recipients the status code <see cref="StatusCodes.Ok"/> or <see cref="StatusCodes.OkQueued"/> is returned.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="false"/>: No simulation is done. The SMS is sent via the SMS Gateway. (default)
|
/// <see langword="false"/>: No simulation is done. The SMS is sent via the SMS Gateway. (default)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("test")]
|
[JsonProperty("test")]
|
||||||
public bool? Test { get; set; }
|
public bool? Test { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="true"/>: Indicates the presence of a user data header in the <see cref="MessageContent"/> property.
|
/// <see langword="true"/>: Indicates the presence of a user data header in the <see cref="MessageContent"/> property.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="false"/>: Indicates the absence of a user data header in the <see cref="MessageContent"/> property. (default)
|
/// <see langword="false"/>: Indicates the absence of a user data header in the <see cref="MessageContent"/> property. (default)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("userDataHeaderPresent")]
|
[JsonProperty("userDataHeaderPresent")]
|
||||||
public bool? UserDataHeaderPresent { get; set; }
|
public bool? UserDataHeaderPresent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Specifies the validity periode (in seconds) in which the message is tried to be delivered to the recipient.
|
/// Specifies the validity periode (in seconds) in which the message is tried to be delivered to the recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// A minimum of 1 minute (<c>60</c> seconds) and a maximum of 3 days (<c>259200</c> seconds) are allowed.
|
/// A minimum of 1 minute (<c>60</c> seconds) and a maximum of 3 days (<c>259200</c> seconds) are allowed.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("validityPeriode")]
|
[JsonProperty("validityPeriode")]
|
||||||
public int? ValidityPeriode { get; set; }
|
public int? ValidityPeriode { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,139 +1,139 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request to send a text message to a list of recipients.
|
/// Request to send a text message to a list of recipients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SendTextMessageRequest
|
public class SendTextMessageRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SendTextMessageRequest"/> class.
|
/// Initializes a new instance of the <see cref="SendTextMessageRequest"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="messageContent">A text message.</param>
|
/// <param name="messageContent">A text message.</param>
|
||||||
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
||||||
public SendTextMessageRequest(string messageContent, IReadOnlyCollection<string> recipientAddressList)
|
public SendTextMessageRequest(string messageContent, IReadOnlyCollection<string> recipientAddressList)
|
||||||
{
|
{
|
||||||
MessageContent = messageContent;
|
MessageContent = messageContent;
|
||||||
RecipientAddressList = recipientAddressList;
|
RecipientAddressList = recipientAddressList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// May contain a freely definable message id.
|
/// May contain a freely definable message id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("clientMessageId")]
|
[JsonProperty("clientMessageId")]
|
||||||
public string? ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// The content category that is used to categorize the message (used for blacklisting).
|
/// The content category that is used to categorize the message (used for blacklisting).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The following content categories are supported: <see cref="ContentCategory.Informational"/> or <see cref="ContentCategory.Advertisement"/>.
|
/// The following content categories are supported: <see cref="ContentCategory.Informational"/> or <see cref="ContentCategory.Advertisement"/>.
|
||||||
/// If no content category is provided, the default setting is used (may be changed inside the web interface).
|
/// If no content category is provided, the default setting is used (may be changed inside the web interface).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("contentCategory")]
|
[JsonProperty("contentCategory")]
|
||||||
public ContentCategory? ContentCategory { get; set; }
|
public ContentCategory? ContentCategory { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Specifies the maximum number of SMS to be generated.
|
/// Specifies the maximum number of SMS to be generated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the system generates more than this number of SMS, the status code <see cref="StatusCodes.MaxSmsPerMessageExceeded"/> is returned.
|
/// If the system generates more than this number of SMS, the status code <see cref="StatusCodes.MaxSmsPerMessageExceeded"/> is returned.
|
||||||
/// The default value of this parameter is <c>0</c>.
|
/// The default value of this parameter is <c>0</c>.
|
||||||
/// If set to <c>0</c>, no limitation is applied.
|
/// If set to <c>0</c>, no limitation is applied.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("maxSmsPerMessage")]
|
[JsonProperty("maxSmsPerMessage")]
|
||||||
public int? MaxSmsPerMessage { get; set; }
|
public int? MaxSmsPerMessage { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>UTF-8</em> encoded message content.
|
/// <em>UTF-8</em> encoded message content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("messageContent")]
|
[JsonProperty("messageContent")]
|
||||||
public string MessageContent { get; set; }
|
public string MessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Specifies the message type.
|
/// Specifies the message type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Allowed values are <see cref="MessageType.Default"/> and <see cref="MessageType.Voice"/>.
|
/// Allowed values are <see cref="MessageType.Default"/> and <see cref="MessageType.Voice"/>.
|
||||||
/// When using the message type <see cref="MessageType.Default"/>, the outgoing message type is determined based on account settings.
|
/// When using the message type <see cref="MessageType.Default"/>, the outgoing message type is determined based on account settings.
|
||||||
/// Using the message type <see cref="MessageType.Voice"/> triggers a voice call.
|
/// Using the message type <see cref="MessageType.Voice"/> triggers a voice call.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("messageType")]
|
[JsonProperty("messageType")]
|
||||||
public MessageType? MessageType { get; set; }
|
public MessageType? MessageType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// When setting a <c>NotificationCallbackUrl</c> all delivery reports are forwarded to this URL.
|
/// When setting a <c>NotificationCallbackUrl</c> all delivery reports are forwarded to this URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("notificationCallbackUrl")]
|
[JsonProperty("notificationCallbackUrl")]
|
||||||
public string? NotificationCallbackUrl { get; set; }
|
public string? NotificationCallbackUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Priority of the message.
|
/// Priority of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Must not exceed the value configured for the account used to send the message.
|
/// Must not exceed the value configured for the account used to send the message.
|
||||||
/// For more information please contact our customer service.
|
/// For more information please contact our customer service.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("priority")]
|
[JsonProperty("priority")]
|
||||||
public int? Priority { get; set; }
|
public int? Priority { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of recipients (E.164 formatted <see href="https://en.wikipedia.org/wiki/MSISDN">MSISDN</see>s)
|
/// List of recipients (E.164 formatted <see href="https://en.wikipedia.org/wiki/MSISDN">MSISDN</see>s)
|
||||||
/// to whom the message should be sent.
|
/// to whom the message should be sent.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// The list of recipients may contain a maximum of <em>1000</em> entries.
|
/// The list of recipients may contain a maximum of <em>1000</em> entries.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("recipientAddressList")]
|
[JsonProperty("recipientAddressList")]
|
||||||
public IReadOnlyCollection<string> RecipientAddressList { get; set; }
|
public IReadOnlyCollection<string> RecipientAddressList { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="true"/>: The message is sent as flash SMS (displayed directly on the screen of the mobile phone).
|
/// <see langword="true"/>: The message is sent as flash SMS (displayed directly on the screen of the mobile phone).
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="false"/>: The message is sent as standard text SMS (default).
|
/// <see langword="false"/>: The message is sent as standard text SMS (default).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("sendAsFlashSms")]
|
[JsonProperty("sendAsFlashSms")]
|
||||||
public bool? SendAsFlashSms { get; set; }
|
public bool? SendAsFlashSms { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Address of the sender (assigned to the account) from which the message is sent.
|
/// Address of the sender (assigned to the account) from which the message is sent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddress")]
|
[JsonProperty("senderAddress")]
|
||||||
public string? SenderAddress { get; set; }
|
public string? SenderAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// The sender address type.
|
/// The sender address type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddressType")]
|
[JsonProperty("senderAddressType")]
|
||||||
public AddressType? SenderAddressType { get; set; }
|
public AddressType? SenderAddressType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="true"/>: The transmission is only simulated, no SMS is sent.
|
/// <see langword="true"/>: The transmission is only simulated, no SMS is sent.
|
||||||
/// Depending on the number of recipients the status code <see cref="StatusCodes.Ok"/> or <see cref="StatusCodes.OkQueued"/> is returned.
|
/// Depending on the number of recipients the status code <see cref="StatusCodes.Ok"/> or <see cref="StatusCodes.OkQueued"/> is returned.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see langword="false"/>: No simulation is done. The SMS is sent via the SMS Gateway. (default)
|
/// <see langword="false"/>: No simulation is done. The SMS is sent via the SMS Gateway. (default)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("test")]
|
[JsonProperty("test")]
|
||||||
public bool? Test { get; set; }
|
public bool? Test { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
/// Specifies the validity periode (in seconds) in which the message is tried to be delivered to the recipient.
|
/// Specifies the validity periode (in seconds) in which the message is tried to be delivered to the recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// A minimum of 1 minute (<c>60</c> seconds) and a maximum of 3 days (<c>259200</c> seconds) are allowed.
|
/// A minimum of 1 minute (<c>60</c> seconds) and a maximum of 3 days (<c>259200</c> seconds) are allowed.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("validityPeriode")]
|
[JsonProperty("validityPeriode")]
|
||||||
public int? ValidityPeriode { get; set; }
|
public int? ValidityPeriode { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Net.Api.LinkMobility.Utils;
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of text messaging (SMS). <see href="https://developer.linkmobility.eu/sms-api/rest-api">API</see>
|
/// Implementation of text messaging (SMS). <see href="https://developer.linkmobility.eu/sms-api/rest-api">API</see>
|
||||||
@@ -1,27 +1,31 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Webhook
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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.
|
||||||
/// </summary>
|
/// (See <see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
||||||
public class IncomingMessageNotificationResponse
|
/// </summary>
|
||||||
{
|
/// <remarks>
|
||||||
/// <summary>
|
/// This notification acknowlegement is the same for all webhooks of LINK Mobility.
|
||||||
/// Gets or sets the status code of the response.
|
/// </remarks>
|
||||||
/// </summary>
|
public class NotificationResponse
|
||||||
[JsonProperty("statusCode")]
|
{
|
||||||
public StatusCodes StatusCode { get; set; } = StatusCodes.Ok;
|
/// <summary>
|
||||||
|
/// Gets or sets the status code of the response.
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// Gets or sets the status message of the response.
|
[JsonProperty("statusCode")]
|
||||||
/// </summary>
|
public StatusCodes StatusCode { get; set; } = StatusCodes.Ok;
|
||||||
[JsonProperty("statusMessage")]
|
|
||||||
public string StatusMessage { get; set; } = "OK";
|
/// <summary>
|
||||||
|
/// Gets or sets the status message of the response.
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// Returns a string representation of the current object in serialized format.
|
[JsonProperty("statusMessage")]
|
||||||
/// </summary>
|
public string StatusMessage { get; set; } = "OK";
|
||||||
/// <returns>A string containing the serialized form of the object (json).</returns>
|
|
||||||
public override string ToString()
|
/// <summary>
|
||||||
=> this.SerializeObject();
|
/// Returns a string representation of the current object in serialized format.
|
||||||
}
|
/// </summary>
|
||||||
}
|
/// <returns>A string containing the serialized form of the object (json).</returns>
|
||||||
|
public override string ToString()
|
||||||
|
=> this.SerializeObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,48 +1,48 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the delivery status of a message on a report.
|
/// Defines the delivery status of a message on a report.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public enum DeliveryStatus
|
public enum DeliveryStatus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message has been delivered to the recipient.
|
/// Message has been delivered to the recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "delivered")]
|
[EnumMember(Value = "delivered")]
|
||||||
Delivered = 1,
|
Delivered = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message not delivered and will be re-tried.
|
/// Message not delivered and will be re-tried.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "undelivered")]
|
[EnumMember(Value = "undelivered")]
|
||||||
Undelivered = 2,
|
Undelivered = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message has expired and will no longer re-tried.
|
/// Message has expired and will no longer re-tried.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "expired")]
|
[EnumMember(Value = "expired")]
|
||||||
Expired = 3,
|
Expired = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message has been deleted.
|
/// Message has been deleted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "deleted")]
|
[EnumMember(Value = "deleted")]
|
||||||
Deleted = 4,
|
Deleted = 4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message has been accepted by the carrier.
|
/// Message has been accepted by the carrier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "accepted")]
|
[EnumMember(Value = "accepted")]
|
||||||
Accepted = 5,
|
Accepted = 5,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message has been rejected by the carrier.
|
/// Message has been rejected by the carrier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumMember(Value = "rejected")]
|
[EnumMember(Value = "rejected")]
|
||||||
Rejected = 6
|
Rejected = 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
30
src/LinkMobility/Webhook/Text/TextMessageType.cs
Normal file
30
src/LinkMobility/Webhook/Text/TextMessageType.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,194 +1,169 @@
|
|||||||
using System.Runtime.Serialization;
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
|
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
{
|
||||||
{
|
/// <summary>
|
||||||
/// <summary>
|
/// Represents a notification for an incoming text message or delivery report.
|
||||||
/// Represents a notification for an incoming message or delivery report. (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
/// (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IncomingMessageNotification
|
public class TextNotification
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="IncomingMessageNotification"/> class.
|
/// Initializes a new instance of the <see cref="TextNotification"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="notificationId">The notification id.</param>
|
/// <param name="notificationId">The notification id.</param>
|
||||||
/// <param name="transferId">The transfer id.</param>
|
/// <param name="transferId">The transfer id.</param>
|
||||||
public IncomingMessageNotification(string notificationId, string transferId)
|
public TextNotification(string notificationId, string transferId)
|
||||||
{
|
{
|
||||||
NotificationId = notificationId;
|
NotificationId = notificationId;
|
||||||
TransferId = transferId;
|
TransferId = transferId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the content type of your notification.
|
/// Defines the content type of your notification.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("messageType")]
|
[JsonProperty("messageType")]
|
||||||
public Type MessageType { get; set; }
|
public TextMessageType MessageType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 20 digit long identification of your notification.
|
/// 20 digit long identification of your notification.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("notificationId")]
|
[JsonProperty("notificationId")]
|
||||||
public string NotificationId { get; set; }
|
public string NotificationId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Unique transfer-id to connect the deliveryReport to the initial message.
|
/// Unique transfer-id to connect the deliveryReport to the initial message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("transferId")]
|
[JsonProperty("transferId")]
|
||||||
public string TransferId { get; set; }
|
public string TransferId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Indicates whether you received message is a SMS or a flash-SMS.
|
/// Indicates whether you received message is a SMS or a flash-SMS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("messageFlashSms")]
|
[JsonProperty("messageFlashSms")]
|
||||||
public bool? MessageFlashSms { get; set; }
|
public bool? MessageFlashSms { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Originator of the sender.
|
/// Originator of the sender.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddress")]
|
[JsonProperty("senderAddress")]
|
||||||
public string? SenderAddress { get; set; }
|
public string? SenderAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see cref="AddressType.International"/> - defines the number format of the mobile originated <see cref="SenderAddress"/>.
|
/// <see cref="AddressType.International"/> - defines the number format of the mobile originated <see cref="SenderAddress"/>.
|
||||||
/// International numbers always includes the country prefix.
|
/// International numbers always includes the country prefix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddressType")]
|
[JsonProperty("senderAddressType")]
|
||||||
public AddressType? SenderAddressType { get; set; }
|
public AddressType? SenderAddressType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Senders address, can either be
|
/// Senders address, can either be
|
||||||
/// <see cref="AddressType.International"/> (4366012345678),
|
/// <see cref="AddressType.International"/> (4366012345678),
|
||||||
/// <see cref="AddressType.National"/> (066012345678) or a
|
/// <see cref="AddressType.National"/> (066012345678) or a
|
||||||
/// <see cref="AddressType.Shortcode"/> (1234).
|
/// <see cref="AddressType.Shortcode"/> (1234).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("recipientAddress")]
|
[JsonProperty("recipientAddress")]
|
||||||
public string? RecipientAddress { get; set; }
|
public string? RecipientAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Defines the number format of the mobile originated message.
|
/// Defines the number format of the mobile originated message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("recipientAddressType")]
|
[JsonProperty("recipientAddressType")]
|
||||||
public AddressType? RecipientAddressType { get; set; }
|
public AddressType? RecipientAddressType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>:
|
/// <see cref="Text.TextMessageType.Text"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Text body of the message encoded in <c>UTF-8</c>.
|
/// 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.
|
/// In the case of concatenated SMS it will contain the complete content of all segments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("textMessageContent")]
|
[JsonProperty("textMessageContent")]
|
||||||
public string? TextMessageContent { get; set; }
|
public string? TextMessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Indicates whether a user-data-header is included within a <c>Base64</c> encoded byte segment.
|
/// Indicates whether a user-data-header is included within a <c>Base64</c> encoded byte segment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("userDataHeaderPresent")]
|
[JsonProperty("userDataHeaderPresent")]
|
||||||
public bool? UserDataHeaderPresent { get; set; }
|
public bool? UserDataHeaderPresent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Content of a binary SMS in an array of <c>Base64</c> strings (URL safe).
|
/// Content of a binary SMS in an array of <c>Base64</c> strings (URL safe).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("binaryMessageContent")]
|
[JsonProperty("binaryMessageContent")]
|
||||||
public IReadOnlyCollection<string>? BinaryMessageContent { get; set; }
|
public IReadOnlyCollection<string>? BinaryMessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Status of the message.
|
/// Status of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("deliveryReportMessageStatus")]
|
[JsonProperty("deliveryReportMessageStatus")]
|
||||||
public DeliveryStatus? DeliveryReportMessageStatus { get; set; }
|
public DeliveryStatus? DeliveryReportMessageStatus { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// ISO 8601 timestamp. Point of time sending the message to recipients address.
|
/// ISO 8601 timestamp. Point of time sending the message to recipients address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("sentOn")]
|
[JsonProperty("sentOn")]
|
||||||
public DateTime? SentOn { get; set; }
|
public DateTime? SentOn { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// ISO 8601 timestamp. Point of time of submitting the message to the mobile operators network.
|
/// ISO 8601 timestamp. Point of time of submitting the message to the mobile operators network.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("deliveredOn")]
|
[JsonProperty("deliveredOn")]
|
||||||
public DateTime? DeliveredOn { get; set; }
|
public DateTime? DeliveredOn { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Type of delivery used to send the message.
|
/// Type of delivery used to send the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("deliveredAs")]
|
[JsonProperty("deliveredAs")]
|
||||||
public DeliveryType? DeliveredAs { get; set; }
|
public DeliveryType? DeliveredAs { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// In the case of a delivery report, the <see cref="ClientMessageId"/> contains the optional submitted message id.
|
/// In the case of a delivery report, the <see cref="ClientMessageId"/> contains the optional submitted message id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("clientMessageId")]
|
[JsonProperty("clientMessageId")]
|
||||||
public string? ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the type of notification.
|
/// Tries to parse the given content as <see cref="TextNotification"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
/// <param name="json">The given content (should be the notification json).</param>
|
||||||
public enum Type
|
/// <param name="notification">The deserialized notification.</param>
|
||||||
{
|
/// <returns>
|
||||||
/// <summary>
|
/// <see langword="true"/> if the content could be parsed; otherwise, <see langword="false"/>.
|
||||||
/// Notification of an incoming text message.
|
/// </returns>
|
||||||
/// </summary>
|
public static bool TryParse(string json, out TextNotification? notification)
|
||||||
[EnumMember(Value = "text")]
|
{
|
||||||
Text = 1,
|
try
|
||||||
|
{
|
||||||
/// <summary>
|
notification = json.DeserializeObject<TextNotification>();
|
||||||
/// Notification of an incoming binary message.
|
return notification != null;
|
||||||
/// </summary>
|
}
|
||||||
[EnumMember(Value = "binary")]
|
catch
|
||||||
Binary = 2,
|
{
|
||||||
|
notification = null;
|
||||||
/// <summary>
|
return false;
|
||||||
/// Notification of a delivery report.
|
}
|
||||||
/// </summary>
|
}
|
||||||
[EnumMember(Value = "deliveryReport")]
|
}
|
||||||
DeliveryReport = 3
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to parse the given content as <see cref="IncomingMessageNotification"/>.
|
|
||||||
/// </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)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
notification = json.DeserializeObject<IncomingMessageNotification>();
|
|
||||||
return notification != null;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
notification = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -145,7 +145,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// 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
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -166,57 +166,12 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Exactly(2));
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Exactly(2));
|
||||||
VerifyNoOtherCalls();
|
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]
|
[TestMethod]
|
||||||
public void ShouldDisposeHttpClient()
|
public void ShouldDisposeHttpClient()
|
||||||
{
|
{
|
||||||
@@ -227,9 +182,7 @@ namespace LinkMobility.Tests
|
|||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
||||||
.Protected()
|
|
||||||
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -245,9 +198,7 @@ namespace LinkMobility.Tests
|
|||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
||||||
.Protected()
|
|
||||||
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -320,7 +271,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
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
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
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
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
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();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// 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
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -389,9 +340,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -411,7 +360,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// 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
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -434,9 +383,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -455,7 +402,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// 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
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -479,9 +426,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -501,7 +446,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
|
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.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"HTTP auth missing: {statusCode}", ex.Message);
|
Assert.AreEqual($"HTTP auth missing: {statusCode}", ex.Message);
|
||||||
@@ -524,7 +469,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = await Assert.ThrowsExactlyAsync<ApplicationException>(async () =>
|
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.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"Unknown HTTP response: {statusCode}", ex.Message);
|
Assert.AreEqual($"Unknown HTTP response: {statusCode}", ex.Message);
|
||||||
@@ -545,7 +490,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
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();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// 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
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -586,9 +531,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -638,16 +581,5 @@ namespace LinkMobility.Tests
|
|||||||
[JsonProperty("integer")]
|
[JsonProperty("integer")]
|
||||||
public int Int { get; set; }
|
public int Int { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestParams : IQueryParameter
|
|
||||||
{
|
|
||||||
public IReadOnlyDictionary<string, string> GetQueryParameters()
|
|
||||||
{
|
|
||||||
return new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "test", "query text" }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,302 +1,303 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Net.Api.LinkMobility;
|
using AMWD.Net.Api.LinkMobility;
|
||||||
using LinkMobility.Tests.Helpers;
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using Moq.Protected;
|
using LinkMobility.Tests.Helpers;
|
||||||
|
using Moq.Protected;
|
||||||
namespace LinkMobility.Tests.Sms
|
|
||||||
{
|
namespace LinkMobility.Tests.Text
|
||||||
[TestClass]
|
{
|
||||||
public class SendBinaryMessageTest
|
[TestClass]
|
||||||
{
|
public class SendBinaryMessageTest
|
||||||
public TestContext TestContext { get; set; }
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
private const string BASE_URL = "https://localhost/rest/";
|
|
||||||
|
private const string BASE_URL = "https://localhost/rest/";
|
||||||
private Mock<IAuthentication> _authenticationMock;
|
|
||||||
private Mock<ClientOptions> _clientOptionsMock;
|
private Mock<IAuthentication> _authenticationMock;
|
||||||
private HttpMessageHandlerMock _httpMessageHandlerMock;
|
private Mock<ClientOptions> _clientOptionsMock;
|
||||||
|
private HttpMessageHandlerMock _httpMessageHandlerMock;
|
||||||
private SendBinaryMessageRequest _request;
|
|
||||||
|
private SendBinaryMessageRequest _request;
|
||||||
[TestInitialize]
|
|
||||||
public void Initialize()
|
[TestInitialize]
|
||||||
{
|
public void Initialize()
|
||||||
_authenticationMock = new Mock<IAuthentication>();
|
{
|
||||||
_clientOptionsMock = new Mock<ClientOptions>();
|
_authenticationMock = new Mock<IAuthentication>();
|
||||||
_httpMessageHandlerMock = new HttpMessageHandlerMock();
|
_clientOptionsMock = new Mock<ClientOptions>();
|
||||||
|
_httpMessageHandlerMock = new HttpMessageHandlerMock();
|
||||||
_authenticationMock
|
|
||||||
.Setup(a => a.AddHeader(It.IsAny<HttpClient>()))
|
_authenticationMock
|
||||||
.Callback<HttpClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Scheme", "Parameter"));
|
.Setup(a => a.AddHeader(It.IsAny<HttpClient>()))
|
||||||
|
.Callback<HttpClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Scheme", "Parameter"));
|
||||||
_clientOptionsMock.Setup(c => c.BaseUrl).Returns(BASE_URL);
|
|
||||||
_clientOptionsMock.Setup(c => c.Timeout).Returns(TimeSpan.FromSeconds(30));
|
_clientOptionsMock.Setup(c => c.BaseUrl).Returns(BASE_URL);
|
||||||
_clientOptionsMock.Setup(c => c.DefaultHeaders).Returns(new Dictionary<string, string>());
|
_clientOptionsMock.Setup(c => c.Timeout).Returns(TimeSpan.FromSeconds(30));
|
||||||
_clientOptionsMock.Setup(c => c.DefaultQueryParams).Returns(new Dictionary<string, string>());
|
_clientOptionsMock.Setup(c => c.DefaultHeaders).Returns(new Dictionary<string, string>());
|
||||||
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
_clientOptionsMock.Setup(c => c.DefaultQueryParams).Returns(new Dictionary<string, string>());
|
||||||
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
||||||
|
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
||||||
_request = new SendBinaryMessageRequest(["SGVsbG8gV29ybGQ="], ["436991234567"]); // "Hello World" in Base64
|
|
||||||
}
|
_request = new SendBinaryMessageRequest(["SGVsbG8gV29ybGQ="], ["436991234567"]); // "Hello World" in Base64
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public async Task ShouldSendBinaryMessage()
|
[TestMethod]
|
||||||
{
|
public async Task ShouldSendBinaryMessage()
|
||||||
// Arrange
|
{
|
||||||
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
// Arrange
|
||||||
{
|
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
||||||
StatusCode = HttpStatusCode.OK,
|
{
|
||||||
Content = new StringContent(@"{ ""clientMessageId"": ""binId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""abc123"" }", Encoding.UTF8, "application/json"),
|
StatusCode = HttpStatusCode.OK,
|
||||||
});
|
Content = new StringContent(@"{ ""clientMessageId"": ""binId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""abc123"" }", Encoding.UTF8, "application/json"),
|
||||||
|
});
|
||||||
var client = GetClient();
|
|
||||||
|
var client = GetClient();
|
||||||
// Act
|
|
||||||
var response = await client.SendBinaryMessage(_request, TestContext.CancellationToken);
|
// Act
|
||||||
|
var response = await client.SendBinaryMessage(_request, TestContext.CancellationToken);
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(response);
|
// Assert
|
||||||
Assert.AreEqual("binId", response.ClientMessageId);
|
Assert.IsNotNull(response);
|
||||||
Assert.AreEqual(1, response.SmsCount);
|
Assert.AreEqual("binId", response.ClientMessageId);
|
||||||
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
Assert.AreEqual(1, response.SmsCount);
|
||||||
Assert.AreEqual("OK", response.StatusMessage);
|
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
||||||
Assert.AreEqual("abc123", response.TransferId);
|
Assert.AreEqual("OK", response.StatusMessage);
|
||||||
|
Assert.AreEqual("abc123", response.TransferId);
|
||||||
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
|
||||||
|
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
||||||
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
||||||
Assert.AreEqual("https://localhost/rest/smsmessaging/binary", callback.Url);
|
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
||||||
Assert.AreEqual(@"{""messageContent"":[""SGVsbG8gV29ybGQ=""],""recipientAddressList"":[""436991234567""]}", callback.Content);
|
Assert.AreEqual("https://localhost/rest/smsmessaging/binary", callback.Url);
|
||||||
|
Assert.AreEqual(@"{""messageContent"":[""SGVsbG8gV29ybGQ=""],""recipientAddressList"":[""436991234567""]}", callback.Content);
|
||||||
Assert.HasCount(3, callback.Headers);
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
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("application/json", callback.Headers["Accept"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
_httpMessageHandlerMock.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();
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnInvalidContentCategoryForBinary()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnInvalidContentCategoryForBinary()
|
||||||
// Arrange
|
{
|
||||||
_request.ContentCategory = 0;
|
// Arrange
|
||||||
var client = GetClient();
|
_request.ContentCategory = 0;
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
Assert.AreEqual("contentCategory", ex.ParamName);
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
Assert.AreEqual("contentCategory", ex.ParamName);
|
||||||
|
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public async Task ShouldSendBinaryMessageFullDetails()
|
[TestMethod]
|
||||||
{
|
public async Task ShouldSendBinaryMessageFullDetails()
|
||||||
// Arrange
|
{
|
||||||
_request.ClientMessageId = "myCustomId";
|
// Arrange
|
||||||
_request.ContentCategory = ContentCategory.Advertisement;
|
_request.ClientMessageId = "myCustomId";
|
||||||
_request.NotificationCallbackUrl = "https://user:pass@example.com/callback/";
|
_request.ContentCategory = ContentCategory.Advertisement;
|
||||||
_request.Priority = 5;
|
_request.NotificationCallbackUrl = "https://user:pass@example.com/callback/";
|
||||||
_request.SendAsFlashSms = false;
|
_request.Priority = 5;
|
||||||
_request.SenderAddress = "4369912345678";
|
_request.SendAsFlashSms = false;
|
||||||
_request.SenderAddressType = AddressType.International;
|
_request.SenderAddress = "4369912345678";
|
||||||
_request.Test = false;
|
_request.SenderAddressType = AddressType.International;
|
||||||
_request.UserDataHeaderPresent = true;
|
_request.Test = false;
|
||||||
_request.ValidityPeriode = 300;
|
_request.UserDataHeaderPresent = true;
|
||||||
|
_request.ValidityPeriode = 300;
|
||||||
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
|
||||||
{
|
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
||||||
StatusCode = HttpStatusCode.OK,
|
{
|
||||||
Content = new StringContent(@"{ ""clientMessageId"": ""myCustomId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""abc123"" }", Encoding.UTF8, "application/json"),
|
StatusCode = HttpStatusCode.OK,
|
||||||
});
|
Content = new StringContent(@"{ ""clientMessageId"": ""myCustomId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""abc123"" }", Encoding.UTF8, "application/json"),
|
||||||
|
});
|
||||||
var client = GetClient();
|
|
||||||
|
var client = GetClient();
|
||||||
// Act
|
|
||||||
var response = await client.SendBinaryMessage(_request, TestContext.CancellationToken);
|
// Act
|
||||||
|
var response = await client.SendBinaryMessage(_request, TestContext.CancellationToken);
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(response);
|
// Assert
|
||||||
Assert.AreEqual("myCustomId", response.ClientMessageId);
|
Assert.IsNotNull(response);
|
||||||
Assert.AreEqual(1, response.SmsCount);
|
Assert.AreEqual("myCustomId", response.ClientMessageId);
|
||||||
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
Assert.AreEqual(1, response.SmsCount);
|
||||||
Assert.AreEqual("OK", response.StatusMessage);
|
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
||||||
Assert.AreEqual("abc123", response.TransferId);
|
Assert.AreEqual("OK", response.StatusMessage);
|
||||||
|
Assert.AreEqual("abc123", response.TransferId);
|
||||||
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
|
||||||
|
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
||||||
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
||||||
Assert.AreEqual("https://localhost/rest/smsmessaging/binary", callback.Url);
|
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
||||||
Assert.AreEqual(@"{""clientMessageId"":""myCustomId"",""contentCategory"":""advertisement"",""messageContent"":[""SGVsbG8gV29ybGQ=""],""notificationCallbackUrl"":""https://user:pass@example.com/callback/"",""priority"":5,""recipientAddressList"":[""436991234567""],""sendAsFlashSms"":false,""senderAddress"":""4369912345678"",""senderAddressType"":""international"",""test"":false,""userDataHeaderPresent"":true,""validityPeriode"":300}", callback.Content);
|
Assert.AreEqual("https://localhost/rest/smsmessaging/binary", callback.Url);
|
||||||
|
Assert.AreEqual(@"{""clientMessageId"":""myCustomId"",""contentCategory"":""advertisement"",""messageContent"":[""SGVsbG8gV29ybGQ=""],""notificationCallbackUrl"":""https://user:pass@example.com/callback/"",""priority"":5,""recipientAddressList"":[""436991234567""],""sendAsFlashSms"":false,""senderAddress"":""4369912345678"",""senderAddressType"":""international"",""test"":false,""userDataHeaderPresent"":true,""validityPeriode"":300}", callback.Content);
|
||||||
Assert.HasCount(3, callback.Headers);
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
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("application/json", callback.Headers["Accept"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
_httpMessageHandlerMock.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();
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnNullRequest()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnNullRequest()
|
||||||
// Arrange
|
{
|
||||||
var client = GetClient();
|
// Arrange
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendBinaryMessage(null, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendBinaryMessage(null, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("request", ex.ParamName);
|
|
||||||
|
Assert.AreEqual("request", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnNullMessageContentList()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnNullMessageContentList()
|
||||||
// Arrange
|
{
|
||||||
_request.MessageContent = null;
|
// Arrange
|
||||||
var client = GetClient();
|
_request.MessageContent = null;
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("MessageContent", ex.ParamName);
|
|
||||||
|
Assert.AreEqual("MessageContent", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnEmptyMessageContentList()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnEmptyMessageContentList()
|
||||||
// Arrange
|
{
|
||||||
_request.MessageContent = [];
|
// Arrange
|
||||||
var client = GetClient();
|
_request.MessageContent = [];
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("MessageContent", ex.ParamName);
|
|
||||||
|
Assert.AreEqual("MessageContent", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnInvalidMessageEncoding()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnInvalidMessageEncoding()
|
||||||
// Arrange
|
{
|
||||||
_request.MessageContent = ["InvalidBase64!!"];
|
// Arrange
|
||||||
var client = GetClient();
|
_request.MessageContent = ["InvalidBase64!!"];
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
Assert.ThrowsExactly<FormatException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
Assert.ThrowsExactly<FormatException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnNullMessageContent()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnNullMessageContent()
|
||||||
// Arrange
|
{
|
||||||
_request.MessageContent = [null];
|
// Arrange
|
||||||
var client = GetClient();
|
_request.MessageContent = [null];
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
[DataRow(null)]
|
[TestMethod]
|
||||||
[DataRow("")]
|
[DataRow(null)]
|
||||||
public void ShouldThrowOnNoRecipients(string recipients)
|
[DataRow("")]
|
||||||
{
|
public void ShouldThrowOnNoRecipients(string recipients)
|
||||||
// Arrange
|
{
|
||||||
_request.RecipientAddressList = recipients?.Split(',');
|
// Arrange
|
||||||
var client = GetClient();
|
_request.RecipientAddressList = recipients?.Split(',');
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
|
||||||
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
[DataRow(null)]
|
[TestMethod]
|
||||||
[DataRow("")]
|
[DataRow(null)]
|
||||||
[DataRow(" ")]
|
[DataRow("")]
|
||||||
[DataRow("invalid-recipient")]
|
[DataRow(" ")]
|
||||||
public void ShouldThrowOnInvalidRecipient(string recipient)
|
[DataRow("invalid-recipient")]
|
||||||
{
|
public void ShouldThrowOnInvalidRecipient(string recipient)
|
||||||
// Arrange
|
{
|
||||||
_request.RecipientAddressList = ["436991234567", recipient];
|
// Arrange
|
||||||
var client = GetClient();
|
_request.RecipientAddressList = ["436991234567", recipient];
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
|
||||||
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
|
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
private void VerifyNoOtherCalls()
|
|
||||||
{
|
private void VerifyNoOtherCalls()
|
||||||
_authenticationMock.VerifyNoOtherCalls();
|
{
|
||||||
_clientOptionsMock.VerifyNoOtherCalls();
|
_authenticationMock.VerifyNoOtherCalls();
|
||||||
_httpMessageHandlerMock.Mock.VerifyNoOtherCalls();
|
_clientOptionsMock.VerifyNoOtherCalls();
|
||||||
}
|
_httpMessageHandlerMock.Mock.VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
private ILinkMobilityClient GetClient()
|
|
||||||
{
|
private ILinkMobilityClient GetClient()
|
||||||
var client = new LinkMobilityClient(_authenticationMock.Object, _clientOptionsMock.Object);
|
{
|
||||||
|
var client = new LinkMobilityClient(_authenticationMock.Object, _clientOptionsMock.Object);
|
||||||
var httpClient = new HttpClient(_httpMessageHandlerMock.Mock.Object)
|
|
||||||
{
|
var httpClient = new HttpClient(_httpMessageHandlerMock.Mock.Object)
|
||||||
Timeout = _clientOptionsMock.Object.Timeout,
|
{
|
||||||
BaseAddress = new Uri(_clientOptionsMock.Object.BaseUrl)
|
Timeout = _clientOptionsMock.Object.Timeout,
|
||||||
};
|
BaseAddress = new Uri(_clientOptionsMock.Object.BaseUrl)
|
||||||
|
};
|
||||||
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LinkMobilityClient", "1.0.0"));
|
|
||||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LinkMobilityClient", "1.0.0"));
|
||||||
|
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
_authenticationMock.Object.AddHeader(httpClient);
|
|
||||||
|
_authenticationMock.Object.AddHeader(httpClient);
|
||||||
_authenticationMock.Invocations.Clear();
|
|
||||||
_clientOptionsMock.Invocations.Clear();
|
_authenticationMock.Invocations.Clear();
|
||||||
|
_clientOptionsMock.Invocations.Clear();
|
||||||
ReflectionHelper.GetPrivateField<HttpClient>(client, "_httpClient")?.Dispose();
|
|
||||||
ReflectionHelper.SetPrivateField(client, "_httpClient", httpClient);
|
ReflectionHelper.GetPrivateField<HttpClient>(client, "_httpClient")?.Dispose();
|
||||||
|
ReflectionHelper.SetPrivateField(client, "_httpClient", httpClient);
|
||||||
return client;
|
|
||||||
}
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,262 +1,263 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Net.Api.LinkMobility;
|
using AMWD.Net.Api.LinkMobility;
|
||||||
using LinkMobility.Tests.Helpers;
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using Moq.Protected;
|
using LinkMobility.Tests.Helpers;
|
||||||
|
using Moq.Protected;
|
||||||
namespace LinkMobility.Tests.Sms
|
|
||||||
{
|
namespace LinkMobility.Tests.Text
|
||||||
[TestClass]
|
{
|
||||||
public class SendTextMessageTest
|
[TestClass]
|
||||||
{
|
public class SendTextMessageTest
|
||||||
public TestContext TestContext { get; set; }
|
{
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
private const string BASE_URL = "https://localhost/rest/";
|
|
||||||
|
private const string BASE_URL = "https://localhost/rest/";
|
||||||
private Mock<IAuthentication> _authenticationMock;
|
|
||||||
private Mock<ClientOptions> _clientOptionsMock;
|
private Mock<IAuthentication> _authenticationMock;
|
||||||
private HttpMessageHandlerMock _httpMessageHandlerMock;
|
private Mock<ClientOptions> _clientOptionsMock;
|
||||||
|
private HttpMessageHandlerMock _httpMessageHandlerMock;
|
||||||
private SendTextMessageRequest _request;
|
|
||||||
|
private SendTextMessageRequest _request;
|
||||||
[TestInitialize]
|
|
||||||
public void Initialize()
|
[TestInitialize]
|
||||||
{
|
public void Initialize()
|
||||||
_authenticationMock = new Mock<IAuthentication>();
|
{
|
||||||
_clientOptionsMock = new Mock<ClientOptions>();
|
_authenticationMock = new Mock<IAuthentication>();
|
||||||
_httpMessageHandlerMock = new HttpMessageHandlerMock();
|
_clientOptionsMock = new Mock<ClientOptions>();
|
||||||
|
_httpMessageHandlerMock = new HttpMessageHandlerMock();
|
||||||
_authenticationMock
|
|
||||||
.Setup(a => a.AddHeader(It.IsAny<HttpClient>()))
|
_authenticationMock
|
||||||
.Callback<HttpClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Scheme", "Parameter"));
|
.Setup(a => a.AddHeader(It.IsAny<HttpClient>()))
|
||||||
|
.Callback<HttpClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Scheme", "Parameter"));
|
||||||
_clientOptionsMock.Setup(c => c.BaseUrl).Returns(BASE_URL);
|
|
||||||
_clientOptionsMock.Setup(c => c.Timeout).Returns(TimeSpan.FromSeconds(30));
|
_clientOptionsMock.Setup(c => c.BaseUrl).Returns(BASE_URL);
|
||||||
_clientOptionsMock.Setup(c => c.DefaultHeaders).Returns(new Dictionary<string, string>());
|
_clientOptionsMock.Setup(c => c.Timeout).Returns(TimeSpan.FromSeconds(30));
|
||||||
_clientOptionsMock.Setup(c => c.DefaultQueryParams).Returns(new Dictionary<string, string>());
|
_clientOptionsMock.Setup(c => c.DefaultHeaders).Returns(new Dictionary<string, string>());
|
||||||
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
_clientOptionsMock.Setup(c => c.DefaultQueryParams).Returns(new Dictionary<string, string>());
|
||||||
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
||||||
|
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
||||||
_request = new SendTextMessageRequest("example message content", ["436991234567"]);
|
|
||||||
}
|
_request = new SendTextMessageRequest("example message content", ["436991234567"]);
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public async Task ShouldSendTextMessage()
|
[TestMethod]
|
||||||
{
|
public async Task ShouldSendTextMessage()
|
||||||
// Arrange
|
{
|
||||||
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
// Arrange
|
||||||
{
|
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
||||||
StatusCode = HttpStatusCode.OK,
|
{
|
||||||
Content = new StringContent(@"{ ""clientMessageId"": ""myUniqueId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""0059d0b20100a0a8b803"" }", Encoding.UTF8, "application/json"),
|
StatusCode = HttpStatusCode.OK,
|
||||||
});
|
Content = new StringContent(@"{ ""clientMessageId"": ""myUniqueId"", ""smsCount"": 1, ""statusCode"": 2000, ""statusMessage"": ""OK"", ""transferId"": ""0059d0b20100a0a8b803"" }", Encoding.UTF8, "application/json"),
|
||||||
|
});
|
||||||
var client = GetClient();
|
|
||||||
|
var client = GetClient();
|
||||||
// Act
|
|
||||||
var response = await client.SendTextMessage(_request, TestContext.CancellationToken);
|
// Act
|
||||||
|
var response = await client.SendTextMessage(_request, TestContext.CancellationToken);
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(response);
|
// Assert
|
||||||
|
Assert.IsNotNull(response);
|
||||||
Assert.AreEqual("myUniqueId", response.ClientMessageId);
|
|
||||||
Assert.AreEqual(1, response.SmsCount);
|
Assert.AreEqual("myUniqueId", response.ClientMessageId);
|
||||||
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
Assert.AreEqual(1, response.SmsCount);
|
||||||
Assert.AreEqual("OK", response.StatusMessage);
|
Assert.AreEqual(StatusCodes.Ok, response.StatusCode);
|
||||||
Assert.AreEqual("0059d0b20100a0a8b803", response.TransferId);
|
Assert.AreEqual("OK", response.StatusMessage);
|
||||||
|
Assert.AreEqual("0059d0b20100a0a8b803", response.TransferId);
|
||||||
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
|
||||||
|
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
||||||
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
||||||
Assert.AreEqual("https://localhost/rest/smsmessaging/text", callback.Url);
|
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
||||||
Assert.AreEqual(@"{""messageContent"":""example message content"",""recipientAddressList"":[""436991234567""]}", callback.Content);
|
Assert.AreEqual("https://localhost/rest/smsmessaging/text", callback.Url);
|
||||||
|
Assert.AreEqual(@"{""messageContent"":""example message content"",""recipientAddressList"":[""436991234567""]}", callback.Content);
|
||||||
Assert.HasCount(3, callback.Headers);
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
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("application/json", callback.Headers["Accept"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
_httpMessageHandlerMock.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();
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnInvalidContentCategory()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnInvalidContentCategory()
|
||||||
// Arrange
|
{
|
||||||
_request.ContentCategory = 0;
|
// Arrange
|
||||||
var client = GetClient();
|
_request.ContentCategory = 0;
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(_request, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
Assert.AreEqual("contentCategory", ex.ParamName);
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(_request, TestContext.CancellationToken));
|
||||||
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
Assert.AreEqual("contentCategory", ex.ParamName);
|
||||||
|
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public async Task ShouldSendTextMessageFullDetails()
|
[TestMethod]
|
||||||
{
|
public async Task ShouldSendTextMessageFullDetails()
|
||||||
// Arrange
|
{
|
||||||
_request.ClientMessageId = "myCustomId";
|
// Arrange
|
||||||
_request.ContentCategory = ContentCategory.Informational;
|
_request.ClientMessageId = "myCustomId";
|
||||||
_request.MaxSmsPerMessage = 1;
|
_request.ContentCategory = ContentCategory.Informational;
|
||||||
_request.MessageType = MessageType.Voice;
|
_request.MaxSmsPerMessage = 1;
|
||||||
_request.NotificationCallbackUrl = "https://user:pass@example.com/callback/";
|
_request.MessageType = MessageType.Voice;
|
||||||
_request.Priority = 5;
|
_request.NotificationCallbackUrl = "https://user:pass@example.com/callback/";
|
||||||
_request.SendAsFlashSms = false;
|
_request.Priority = 5;
|
||||||
_request.SenderAddress = "4369912345678";
|
_request.SendAsFlashSms = false;
|
||||||
_request.SenderAddressType = AddressType.International;
|
_request.SenderAddress = "4369912345678";
|
||||||
_request.Test = false;
|
_request.SenderAddressType = AddressType.International;
|
||||||
_request.ValidityPeriode = 300;
|
_request.Test = false;
|
||||||
|
_request.ValidityPeriode = 300;
|
||||||
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
|
||||||
{
|
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
||||||
StatusCode = HttpStatusCode.OK,
|
{
|
||||||
Content = new StringContent(@"{ ""clientMessageId"": ""myCustomId"", ""smsCount"": 1, ""statusCode"": 4035, ""statusMessage"": ""SMS_DISABLED"", ""transferId"": ""0059d0b20100a0a8b803"" }", Encoding.UTF8, "application/json"),
|
StatusCode = HttpStatusCode.OK,
|
||||||
});
|
Content = new StringContent(@"{ ""clientMessageId"": ""myCustomId"", ""smsCount"": 1, ""statusCode"": 4035, ""statusMessage"": ""SMS_DISABLED"", ""transferId"": ""0059d0b20100a0a8b803"" }", Encoding.UTF8, "application/json"),
|
||||||
|
});
|
||||||
var client = GetClient();
|
|
||||||
|
var client = GetClient();
|
||||||
// Act
|
|
||||||
var response = await client.SendTextMessage(_request, TestContext.CancellationToken);
|
// Act
|
||||||
|
var response = await client.SendTextMessage(_request, TestContext.CancellationToken);
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(response);
|
// Assert
|
||||||
|
Assert.IsNotNull(response);
|
||||||
Assert.AreEqual("myCustomId", response.ClientMessageId);
|
|
||||||
Assert.AreEqual(1, response.SmsCount);
|
Assert.AreEqual("myCustomId", response.ClientMessageId);
|
||||||
Assert.AreEqual(StatusCodes.SmsDisabled, response.StatusCode);
|
Assert.AreEqual(1, response.SmsCount);
|
||||||
Assert.AreEqual("SMS_DISABLED", response.StatusMessage);
|
Assert.AreEqual(StatusCodes.SmsDisabled, response.StatusCode);
|
||||||
Assert.AreEqual("0059d0b20100a0a8b803", response.TransferId);
|
Assert.AreEqual("SMS_DISABLED", response.StatusMessage);
|
||||||
|
Assert.AreEqual("0059d0b20100a0a8b803", response.TransferId);
|
||||||
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
|
||||||
|
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
||||||
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
||||||
Assert.AreEqual("https://localhost/rest/smsmessaging/text", callback.Url);
|
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
||||||
Assert.AreEqual(@"{""clientMessageId"":""myCustomId"",""contentCategory"":""informational"",""maxSmsPerMessage"":1,""messageContent"":""example message content"",""messageType"":""voice"",""notificationCallbackUrl"":""https://user:pass@example.com/callback/"",""priority"":5,""recipientAddressList"":[""436991234567""],""sendAsFlashSms"":false,""senderAddress"":""4369912345678"",""senderAddressType"":""international"",""test"":false,""validityPeriode"":300}", callback.Content);
|
Assert.AreEqual("https://localhost/rest/smsmessaging/text", callback.Url);
|
||||||
|
Assert.AreEqual(@"{""clientMessageId"":""myCustomId"",""contentCategory"":""informational"",""maxSmsPerMessage"":1,""messageContent"":""example message content"",""messageType"":""voice"",""notificationCallbackUrl"":""https://user:pass@example.com/callback/"",""priority"":5,""recipientAddressList"":[""436991234567""],""sendAsFlashSms"":false,""senderAddress"":""4369912345678"",""senderAddressType"":""international"",""test"":false,""validityPeriode"":300}", callback.Content);
|
||||||
Assert.HasCount(3, callback.Headers);
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
Assert.HasCount(3, callback.Headers);
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
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("application/json", callback.Headers["Accept"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
_httpMessageHandlerMock.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();
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnNullRequest()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnNullRequest()
|
||||||
// Arrange
|
{
|
||||||
var client = GetClient();
|
// Arrange
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendTextMessage(null, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
Assert.AreEqual("request", ex.ParamName);
|
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => client.SendTextMessage(null, TestContext.CancellationToken));
|
||||||
|
Assert.AreEqual("request", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
[DataRow(null)]
|
[TestMethod]
|
||||||
[DataRow("")]
|
[DataRow(null)]
|
||||||
[DataRow(" ")]
|
[DataRow("")]
|
||||||
public void ShouldThrowOnMissingMessage(string message)
|
[DataRow(" ")]
|
||||||
{
|
public void ShouldThrowOnMissingMessage(string message)
|
||||||
// Arrange
|
{
|
||||||
var req = new SendTextMessageRequest(message, ["4791234567"]);
|
// Arrange
|
||||||
var client = GetClient();
|
var req = new SendTextMessageRequest(message, ["4791234567"]);
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
Assert.AreEqual("MessageContent", ex.ParamName);
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
||||||
|
Assert.AreEqual("MessageContent", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void ShouldThrowOnNoRecipients()
|
[TestMethod]
|
||||||
{
|
public void ShouldThrowOnNoRecipients()
|
||||||
// Arrange
|
{
|
||||||
var req = new SendTextMessageRequest("Hello", []);
|
// Arrange
|
||||||
var client = GetClient();
|
var req = new SendTextMessageRequest("Hello", []);
|
||||||
|
var client = GetClient();
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
||||||
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
[DataRow(null)]
|
[TestMethod]
|
||||||
[DataRow("")]
|
[DataRow(null)]
|
||||||
[DataRow(" ")]
|
[DataRow("")]
|
||||||
[DataRow("invalid-recipient")]
|
[DataRow(" ")]
|
||||||
public void ShouldThrowOnInvalidRecipient(string recipient)
|
[DataRow("invalid-recipient")]
|
||||||
{
|
public void ShouldThrowOnInvalidRecipient(string recipient)
|
||||||
// Arrange
|
{
|
||||||
var client = GetClient();
|
// Arrange
|
||||||
var req = new SendTextMessageRequest("Hello", ["4791234567", recipient]);
|
var client = GetClient();
|
||||||
|
var req = new SendTextMessageRequest("Hello", ["4791234567", recipient]);
|
||||||
// Act & Assert
|
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
|
||||||
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
|
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
private void VerifyNoOtherCalls()
|
|
||||||
{
|
private void VerifyNoOtherCalls()
|
||||||
_authenticationMock.VerifyNoOtherCalls();
|
{
|
||||||
_clientOptionsMock.VerifyNoOtherCalls();
|
_authenticationMock.VerifyNoOtherCalls();
|
||||||
_httpMessageHandlerMock.Mock.VerifyNoOtherCalls();
|
_clientOptionsMock.VerifyNoOtherCalls();
|
||||||
}
|
_httpMessageHandlerMock.Mock.VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
private ILinkMobilityClient GetClient()
|
|
||||||
{
|
private ILinkMobilityClient GetClient()
|
||||||
var client = new LinkMobilityClient(_authenticationMock.Object, _clientOptionsMock.Object);
|
{
|
||||||
|
var client = new LinkMobilityClient(_authenticationMock.Object, _clientOptionsMock.Object);
|
||||||
var httpClient = new HttpClient(_httpMessageHandlerMock.Mock.Object)
|
|
||||||
{
|
var httpClient = new HttpClient(_httpMessageHandlerMock.Mock.Object)
|
||||||
Timeout = _clientOptionsMock.Object.Timeout,
|
{
|
||||||
BaseAddress = new Uri(_clientOptionsMock.Object.BaseUrl)
|
Timeout = _clientOptionsMock.Object.Timeout,
|
||||||
};
|
BaseAddress = new Uri(_clientOptionsMock.Object.BaseUrl)
|
||||||
|
};
|
||||||
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LinkMobilityClient", "1.0.0"));
|
|
||||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LinkMobilityClient", "1.0.0"));
|
||||||
|
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
_authenticationMock.Object.AddHeader(httpClient);
|
|
||||||
|
_authenticationMock.Object.AddHeader(httpClient);
|
||||||
_authenticationMock.Invocations.Clear();
|
|
||||||
_clientOptionsMock.Invocations.Clear();
|
_authenticationMock.Invocations.Clear();
|
||||||
|
_clientOptionsMock.Invocations.Clear();
|
||||||
ReflectionHelper.GetPrivateField<HttpClient>(client, "_httpClient")?.Dispose();
|
|
||||||
ReflectionHelper.SetPrivateField(client, "_httpClient", httpClient);
|
ReflectionHelper.GetPrivateField<HttpClient>(client, "_httpClient")?.Dispose();
|
||||||
|
ReflectionHelper.SetPrivateField(client, "_httpClient", httpClient);
|
||||||
return client;
|
|
||||||
}
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,90 +1,91 @@
|
|||||||
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
|
[TestClass]
|
||||||
{
|
public class TextNotificationTest
|
||||||
[TestMethod]
|
{
|
||||||
public void ShouldParseAllPropertiesForTextNotification()
|
[TestMethod]
|
||||||
{
|
public void ShouldParseAllPropertiesForTextNotification()
|
||||||
// Arrange
|
{
|
||||||
string json = @"{
|
// Arrange
|
||||||
""messageType"": ""text"",
|
string json = @"{
|
||||||
""notificationId"": ""notif-123"",
|
""messageType"": ""text"",
|
||||||
""transferId"": ""trans-456"",
|
""notificationId"": ""notif-123"",
|
||||||
""messageFlashSms"": true,
|
""transferId"": ""trans-456"",
|
||||||
""senderAddress"": ""436991234567"",
|
""messageFlashSms"": true,
|
||||||
""senderAddressType"": ""international"",
|
""senderAddress"": ""436991234567"",
|
||||||
""recipientAddress"": ""066012345678"",
|
""senderAddressType"": ""international"",
|
||||||
""recipientAddressType"": ""national"",
|
""recipientAddress"": ""066012345678"",
|
||||||
""textMessageContent"": ""Hello from user"",
|
""recipientAddressType"": ""national"",
|
||||||
""userDataHeaderPresent"": false,
|
""textMessageContent"": ""Hello from user"",
|
||||||
""binaryMessageContent"": [""SGVsbG8=""],
|
""userDataHeaderPresent"": false,
|
||||||
""deliveryReportMessageStatus"": 2,
|
""binaryMessageContent"": [""SGVsbG8=""],
|
||||||
""sentOn"": ""2025-12-03T12:34:56Z"",
|
""deliveryReportMessageStatus"": 2,
|
||||||
""deliveredOn"": ""2025-12-03T12:35:30Z"",
|
""sentOn"": ""2025-12-03T12:34:56Z"",
|
||||||
""deliveredAs"": 1,
|
""deliveredOn"": ""2025-12-03T12:35:30Z"",
|
||||||
""clientMessageId"": ""client-789""
|
""deliveredAs"": 1,
|
||||||
}";
|
""clientMessageId"": ""client-789""
|
||||||
|
}";
|
||||||
// Act
|
|
||||||
bool successful = IncomingMessageNotification.TryParse(json, out var notification);
|
// Act
|
||||||
|
bool successful = TextNotification.TryParse(json, out var notification);
|
||||||
// Assert
|
|
||||||
Assert.IsTrue(successful, "TryParse should return true for valid json");
|
// Assert
|
||||||
Assert.IsNotNull(notification);
|
Assert.IsTrue(successful, "TryParse should return true for valid json");
|
||||||
|
Assert.IsNotNull(notification);
|
||||||
Assert.AreEqual(IncomingMessageNotification.Type.Text, notification.MessageType);
|
|
||||||
Assert.AreEqual("notif-123", notification.NotificationId);
|
Assert.AreEqual(TextMessageType.Text, notification.MessageType);
|
||||||
Assert.AreEqual("trans-456", notification.TransferId);
|
Assert.AreEqual("notif-123", notification.NotificationId);
|
||||||
|
Assert.AreEqual("trans-456", notification.TransferId);
|
||||||
Assert.IsTrue(notification.MessageFlashSms.HasValue && notification.MessageFlashSms.Value);
|
|
||||||
Assert.AreEqual("436991234567", notification.SenderAddress);
|
Assert.IsTrue(notification.MessageFlashSms.HasValue && notification.MessageFlashSms.Value);
|
||||||
Assert.IsTrue(notification.SenderAddressType.HasValue);
|
Assert.AreEqual("436991234567", notification.SenderAddress);
|
||||||
Assert.AreEqual(AddressType.International, notification.SenderAddressType.Value);
|
Assert.IsTrue(notification.SenderAddressType.HasValue);
|
||||||
|
Assert.AreEqual(AddressType.International, notification.SenderAddressType.Value);
|
||||||
Assert.AreEqual("066012345678", notification.RecipientAddress);
|
|
||||||
Assert.IsTrue(notification.RecipientAddressType.HasValue);
|
Assert.AreEqual("066012345678", notification.RecipientAddress);
|
||||||
Assert.AreEqual(AddressType.National, notification.RecipientAddressType.Value);
|
Assert.IsTrue(notification.RecipientAddressType.HasValue);
|
||||||
|
Assert.AreEqual(AddressType.National, notification.RecipientAddressType.Value);
|
||||||
Assert.AreEqual("Hello from user", notification.TextMessageContent);
|
|
||||||
Assert.IsTrue(notification.UserDataHeaderPresent.HasValue && !notification.UserDataHeaderPresent.Value);
|
Assert.AreEqual("Hello from user", notification.TextMessageContent);
|
||||||
|
Assert.IsTrue(notification.UserDataHeaderPresent.HasValue && !notification.UserDataHeaderPresent.Value);
|
||||||
Assert.IsNotNull(notification.BinaryMessageContent);
|
|
||||||
CollectionAssert.AreEqual(new List<string> { "SGVsbG8=" }, new List<string>(notification.BinaryMessageContent));
|
Assert.IsNotNull(notification.BinaryMessageContent);
|
||||||
|
CollectionAssert.AreEqual(new List<string> { "SGVsbG8=" }, new List<string>(notification.BinaryMessageContent));
|
||||||
// delivery status and deliveredAs are numeric in the test json: assert underlying integral values
|
|
||||||
Assert.IsTrue(notification.DeliveryReportMessageStatus.HasValue);
|
// delivery status and deliveredAs are numeric in the test json: assert underlying integral values
|
||||||
Assert.AreEqual(2, (int)notification.DeliveryReportMessageStatus.Value);
|
Assert.IsTrue(notification.DeliveryReportMessageStatus.HasValue);
|
||||||
|
Assert.AreEqual(2, (int)notification.DeliveryReportMessageStatus.Value);
|
||||||
Assert.IsTrue(notification.SentOn.HasValue);
|
|
||||||
Assert.IsTrue(notification.DeliveredOn.HasValue);
|
Assert.IsTrue(notification.SentOn.HasValue);
|
||||||
|
Assert.IsTrue(notification.DeliveredOn.HasValue);
|
||||||
// Compare instants in UTC
|
|
||||||
var expectedSent = DateTime.Parse("2025-12-03T12:34:56Z").ToUniversalTime();
|
// Compare instants in UTC
|
||||||
var expectedDelivered = DateTime.Parse("2025-12-03T12:35:30Z").ToUniversalTime();
|
var expectedSent = DateTime.Parse("2025-12-03T12:34:56Z").ToUniversalTime();
|
||||||
Assert.AreEqual(expectedSent, notification.SentOn.Value.ToUniversalTime());
|
var expectedDelivered = DateTime.Parse("2025-12-03T12:35:30Z").ToUniversalTime();
|
||||||
Assert.AreEqual(expectedDelivered, notification.DeliveredOn.Value.ToUniversalTime());
|
Assert.AreEqual(expectedSent, notification.SentOn.Value.ToUniversalTime());
|
||||||
|
Assert.AreEqual(expectedDelivered, notification.DeliveredOn.Value.ToUniversalTime());
|
||||||
Assert.IsTrue(notification.DeliveredAs.HasValue);
|
|
||||||
Assert.AreEqual(1, (int)notification.DeliveredAs.Value);
|
Assert.IsTrue(notification.DeliveredAs.HasValue);
|
||||||
|
Assert.AreEqual(1, (int)notification.DeliveredAs.Value);
|
||||||
Assert.AreEqual("client-789", notification.ClientMessageId);
|
|
||||||
}
|
Assert.AreEqual("client-789", notification.ClientMessageId);
|
||||||
|
}
|
||||||
[TestMethod]
|
|
||||||
public void TryParseShouldReturnFalseOnInvalidJson()
|
[TestMethod]
|
||||||
{
|
public void TryParseShouldReturnFalseOnInvalidJson()
|
||||||
// Arrange
|
{
|
||||||
string invalid = "this is not json";
|
// Arrange
|
||||||
|
string invalid = "this is not json";
|
||||||
// Act
|
|
||||||
bool successful = IncomingMessageNotification.TryParse(invalid, out var notification);
|
// Act
|
||||||
|
bool successful = TextNotification.TryParse(invalid, out var notification);
|
||||||
// Assert
|
|
||||||
Assert.IsFalse(successful);
|
// Assert
|
||||||
Assert.IsNull(notification);
|
Assert.IsFalse(successful);
|
||||||
}
|
Assert.IsNull(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user