Skip to content

Commit

Permalink
Add net462 support to Tests.csproj
Browse files Browse the repository at this point in the history
That's the only .NET Framework version supported by the MSTest.TestFramework
dependency.
  • Loading branch information
mqudsi committed Apr 28, 2024
1 parent 7cf0b0f commit 824c9d2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 36 additions & 0 deletions Tests/EncodeDecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Text;
using NeoSmart.Utils;
using System;
#if NETCOREAPP
using System.Buffers.Text;
#endif
using System.Buffers;

namespace Tests
Expand All @@ -23,6 +25,29 @@ public void BasicTest()
Assert.IsTrue(decoded.SequenceEqual(foo), "Decoded value mismatch!");
}

[TestMethod]
public void DecodeFromArrayPadded1()
{
var encoding = new UTF8Encoding(false);
var foo = encoding.GetBytes("foo11");
var encoded = UrlBase64.Encode(foo, PaddingPolicy.Preserve);
Assert.AreEqual(Convert.ToBase64String(foo, Base64FormattingOptions.None).Replace('+', '-').Replace('/', '_'), encoded);
var decoded = UrlBase64.Decode(encoded);
CollectionAssert.AreEqual(foo, decoded);
}

[TestMethod]
public void DecodeFromArrayPadded2()
{
var encoding = new UTF8Encoding(false);
var foo = encoding.GetBytes("foo1");
var encoded = UrlBase64.Encode(foo, PaddingPolicy.Preserve);
Assert.AreEqual(Convert.ToBase64String(foo, Base64FormattingOptions.None).Replace('+', '-').Replace('/', '_'), encoded);
var decoded = UrlBase64.Decode(encoded);
CollectionAssert.AreEqual(foo, decoded.ToArray());
}

#if NETCOREAPP
[TestMethod]
public void EncodeToSpan()
{
Expand Down Expand Up @@ -75,6 +100,7 @@ public void DecodeFromSpanPadded1InsteadOf2()
var decoded = UrlBase64.Decode(encoded.AsSpan(0, encoded.Length - 1));
CollectionAssert.AreEqual(foo, decoded.ToArray());
}
#endif

[TestMethod]
public void VariableLengthTest()
Expand Down Expand Up @@ -108,6 +134,7 @@ public void VariableLengthTest()
}
}

#if NETCOREAPP
private static byte[] SystemEncodeUtf8(byte[] input)
{
var systemEncoded = new byte[UrlBase64.GetMaxEncodedLength(input.Length)];
Expand Down Expand Up @@ -152,6 +179,7 @@ public void Utf8VariableLengthTest()
}
}
}
#endif

[TestMethod]
public void PaddingPolicyTest()
Expand Down Expand Up @@ -221,5 +249,13 @@ public static ReadOnlySpan<byte> TrimEnd(this ReadOnlySpan<byte> span, char trim
for (; i >= 0 && span[i] == trim; --i) ;
return span.Slice(0, i + 1);
}

public static byte[] TrimEnd(this byte[] array, char trim)
{
int i = array.Length - 1;
for (; i >= 0 && array[i] == trim; --i) ;
Array.Resize(ref array, i + 1);
return array;
}
}
}
10 changes: 8 additions & 2 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net6</TargetFrameworks>
<TargetFrameworks>net462;netcoreapp3.0;net6</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="*" />
<PackageReference Include="MSTest.TestAdapter" Version="*" />
<PackageReference Include="MSTest.TestFramework" Version="*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UrlBase64\UrlBase64.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 824c9d2

Please sign in to comment.