2020-08-06 12:14:45 +01:00
|
|
|
using System.Text;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web.Tests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class Base64UtilTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void Base64UrlDecode_Works()
|
|
|
|
{
|
2020-08-06 19:48:49 +01:00
|
|
|
var encoded = "SGVsbG9Xb3JsZA";
|
2020-08-06 12:14:45 +01:00
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That("HelloWorld", Is.EqualTo(Encoding.UTF8.GetString(Base64Util.UrlDecode(encoded))));
|
2020-08-06 12:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Base64UrlEncode_Works()
|
|
|
|
{
|
|
|
|
var decoded = "HelloWorld";
|
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That("SGVsbG9Xb3JsZA", Is.EqualTo(Base64Util.UrlEncode(Encoding.UTF8.GetBytes(decoded))));
|
2020-08-06 12:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Base64UrlEncode_WorksSpecialChars()
|
|
|
|
{
|
|
|
|
var bytes = new byte[] { 0x04, 0x9f, 0x9c, 0xff, 0x3f, 0x0a };
|
|
|
|
|
|
|
|
// normal base64: BJ+c/z8K
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That("BJ-c_z8K", Is.EqualTo(Base64Util.UrlEncode(bytes)));
|
2020-08-06 12:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Base64UrlDecode_WorksSpecialChars()
|
|
|
|
{
|
|
|
|
var bytes = new byte[] { 0x04, 0x9f, 0x9c, 0xff, 0x3f, 0x0a };
|
|
|
|
|
|
|
|
// normal base64: BJ+c/z8K
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(bytes, Is.EqualTo(Base64Util.UrlDecode("BJ-c_z8K")));
|
2020-08-06 12:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|