1
0

Send Text Message

This commit is contained in:
2025-12-02 22:49:51 +01:00
parent 23ad083d1d
commit 17ff8f7371
27 changed files with 2157 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using System.Net.Http;
using AMWD.Net.Api.LinkMobility;
namespace LinkMobility.Tests.Auth
{
[TestClass]
public class AccessTokenAuthenticationTest
{
[TestMethod]
public void ShouldAddHeader()
{
// Arrange
string token = "test_token";
var auth = new AccessTokenAuthentication(token);
using var httpClient = new HttpClient();
// Act
auth.AddHeader(httpClient);
// Assert
Assert.IsTrue(httpClient.DefaultRequestHeaders.Contains("Authorization"));
Assert.AreEqual("Bearer", httpClient.DefaultRequestHeaders.Authorization.Scheme);
Assert.AreEqual(token, httpClient.DefaultRequestHeaders.Authorization.Parameter);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldThrowArgumentNullExceptionForToken(string token)
{
// Arrange
// Act & Assert
Assert.ThrowsExactly<ArgumentNullException>(() => new AccessTokenAuthentication(token));
}
}
}

View File

@@ -0,0 +1,60 @@
using System.Net.Http;
using System.Text;
using AMWD.Net.Api.LinkMobility;
namespace LinkMobility.Tests.Auth
{
[TestClass]
public class BasicAuthenticationTest
{
[TestMethod]
public void ShouldAddHeader()
{
// Arrange
string username = "user";
string password = "pass";
var auth = new BasicAuthentication(username, password);
using var httpClient = new HttpClient();
// Act
auth.AddHeader(httpClient);
// Assert
Assert.IsTrue(httpClient.DefaultRequestHeaders.Contains("Authorization"));
Assert.AreEqual("Basic", httpClient.DefaultRequestHeaders.Authorization.Scheme);
Assert.AreEqual(Base64(username, password), httpClient.DefaultRequestHeaders.Authorization.Parameter);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldThrowArgumentNullExceptionForUsername(string username)
{
// Arrange
// Act & Assert
Assert.ThrowsExactly<ArgumentNullException>(() => new BasicAuthentication(username, "pass"));
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldThrowArgumentNullExceptionForPassword(string password)
{
// Arrange
// Act & Assert
Assert.ThrowsExactly<ArgumentNullException>(() => new BasicAuthentication("user", password));
}
private static string Base64(string user, string pass)
{
string plainText = $"{user}:{pass}";
return Convert.ToBase64String(Encoding.ASCII.GetBytes(plainText));
}
}
}