Enable .NET Standard 2.0 tests through .NET Framework 4.7.2

This commit is contained in:
Sergio Pedri
2021-11-02 02:36:50 +01:00
parent e2b336184f
commit a5ef60ea4d
20 changed files with 45 additions and 51 deletions
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -217,7 +217,7 @@ public partial class Test_Guard
public void Test_Guard_IsBitwiseEqualTo_Ok()
{
Guard.IsBitwiseEqualTo(byte.MaxValue, byte.MaxValue, nameof(Test_Guard_IsBitwiseEqualTo_Ok));
Guard.IsBitwiseEqualTo(MathF.PI, MathF.PI, nameof(Test_Guard_IsBitwiseEqualTo_Ok));
Guard.IsBitwiseEqualTo((float)Math.PI, (float)Math.PI, nameof(Test_Guard_IsBitwiseEqualTo_Ok));
Guard.IsBitwiseEqualTo(double.Epsilon, double.Epsilon, nameof(Test_Guard_IsBitwiseEqualTo_Ok));
Guid guid = Guid.NewGuid();
@@ -413,8 +413,8 @@ public partial class Test_Guard
{
Guard.IsLessThanOrEqualTo(1, 2, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(1, 1, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(0.1f, MathF.PI, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(MathF.PI, MathF.PI, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(0.1f, (float)Math.PI, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo((float)Math.PI, (float)Math.PI, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(DateTime.Today, DateTime.MaxValue, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
Guard.IsLessThanOrEqualTo(DateTime.MaxValue, DateTime.MaxValue, nameof(Test_Guard_IsLessThanOrEqualTo_Ok));
}
@@ -458,8 +458,8 @@ public partial class Test_Guard
{
Guard.IsGreaterThanOrEqualTo(2, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(1, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(MathF.PI, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(MathF.PI, MathF.PI, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo((float)Math.PI, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo((float)Math.PI, (float)Math.PI, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(DateTime.MaxValue, DateTime.Today, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(DateTime.MaxValue, DateTime.MaxValue, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
}
@@ -227,9 +227,14 @@ public class Test_StringPool
Assert.AreEqual(nameof(helloworld), helloworld);
Assert.AreEqual(nameof(dotnetCommunityToolkit), dotnetCommunityToolkit);
#if NETCOREAPP
// .NET Framework reuses strings in a way that makes these tests fail.
// The actual underlying APIs are still working as expected though.
Assert.AreNotSame(hello, pool.GetOrAdd(hello.AsSpan()));
Assert.AreNotSame(helloworld, pool.GetOrAdd(helloworld.AsSpan()));
Assert.AreNotSame(dotnetCommunityToolkit, pool.GetOrAdd(dotnetCommunityToolkit.AsSpan()));
#endif
}
[TestCategory("StringPool")]
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if !WINDOWS_UWP
#if NETCOREAPP
using System;
using System.Runtime.CompilerServices;
@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if !WINDOWS_UWP
#if NETCOREAPP
using System;
using System.Runtime.CompilerServices;
@@ -3,12 +3,11 @@
// See the LICENSE file in the project root for more information.
using System;
#if !WINDOWS_UWP
#if NETCOREAPP
using System.Buffers;
#endif
using System.IO;
using System.Runtime.CompilerServices;
using CommunityToolkit.HighPerformance;
using CommunityToolkit.HighPerformance.Buffers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -42,7 +42,7 @@ public partial class Test_ReadOnlySpanExtensions
{
TestForType((int)37438941, CreateRandomData);
TestForType((uint)37438941, CreateRandomData);
TestForType(MathF.PI, CreateRandomData);
TestForType((float)Math.PI, CreateRandomData);
}
[TestCategory("ReadOnlySpanExtensions")]
@@ -46,7 +46,7 @@ public class Test_SpinLockExtensions
{
for (int j = 0; j < 10; j++)
{
#if WINDOWS_UWP
#if NETFRAMEWORK
using (SpinLockExtensions.Enter(spinLockOwner, ref spinLockOwner.Lock))
#else
using (spinLockOwner.Lock.Enter())
@@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
#if !WINDOWS_UWP
using System.Runtime.CompilerServices;
#endif
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommunityToolkit.HighPerformance.UnitTests;
@@ -202,7 +200,7 @@ public class Test_Memory2DT
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() => new Memory2D<int>(array, 0, 0, 0, 3, 3));
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("Memory2DT")]
[TestMethod]
public void Test_Memory2DT_MemoryConstructor()
@@ -338,7 +336,7 @@ public class Test_Memory2DT
// Memory<T> (or a Span<T> too, for that matter) from a 2D array.
bool success = memory2d.TryGetMemory(out Memory<int> memory);
#if WINDOWS_UWP
#if NETFRAMEWORK
Assert.IsFalse(success);
Assert.IsTrue(memory.IsEmpty);
#else
@@ -365,7 +363,7 @@ public class Test_Memory2DT
Assert.AreEqual(memory.Span[2], 3);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("Memory2DT")]
[TestMethod]
public void Test_Memory2DT_TryGetMemory_3()
@@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
#if !WINDOWS_UWP
using System.Runtime.CompilerServices;
#endif
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommunityToolkit.HighPerformance.UnitTests;
@@ -182,7 +180,7 @@ public class Test_ReadOnlyMemory2DT
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlyMemory2D<int>(array, 0, 0, 0, 3, 3));
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("ReadOnlyMemory2DT")]
[TestMethod]
public void Test_ReadOnlyMemory2DT_ReadOnlyMemoryConstructor()
@@ -304,7 +302,7 @@ public class Test_ReadOnlyMemory2DT
bool success = memory2d.TryGetMemory(out ReadOnlyMemory<int> memory);
#if WINDOWS_UWP
#if NETFRAMEWORK
Assert.IsFalse(success);
Assert.IsTrue(memory.IsEmpty);
#else
@@ -329,7 +327,7 @@ public class Test_ReadOnlyMemory2DT
Assert.AreEqual(memory.Span[2], 3);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("ReadOnlyMemory2DT")]
[TestMethod]
public void Test_ReadOnlyMemory2DT_TryGetReadOnlyMemory_3()
@@ -36,7 +36,7 @@ public class Test_ReadOnlySpan2DT
Assert.AreEqual(empty2.Height, 0);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("ReadOnlySpan2DT")]
[TestMethod]
public unsafe void Test_ReadOnlySpan2DT_RefConstructor()
@@ -559,7 +559,7 @@ public class Test_ReadOnlySpan2DT
Assert.AreEqual(slice3[0, 0], 5);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("ReadOnlySpan2DT")]
[TestMethod]
public void Test_ReadOnlySpan2DT_GetRowReadOnlySpan()
@@ -644,8 +644,8 @@ public class Test_ReadOnlySpan2DT
bool success = span2d.TryGetSpan(out ReadOnlySpan<int> span);
#if WINDOWS_UWP
// Can't get a ReadOnlySpan<T> over a T[,] array on UWP
#if NETFRAMEWORK
// Can't get a ReadOnlySpan<T> over a T[,] array on .NET Standard 2.0
Assert.IsFalse(success);
Assert.AreEqual(span.Length, 0);
#else
@@ -47,7 +47,7 @@ public class Test_Span2DT
Assert.AreEqual(empty4.Height, 0);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("Span2DT")]
[TestMethod]
public unsafe void Test_Span2DT_RefConstructor()
@@ -728,7 +728,7 @@ public class Test_Span2DT
Assert.AreEqual(slice3[0, 0], 5);
}
#if !WINDOWS_UWP
#if NETCOREAPP
[TestCategory("Span2DT")]
[TestMethod]
public void Test_Span2DT_GetRowSpan()
@@ -835,12 +835,12 @@ public class Test_Span2DT
// This API tries to get a Span<T> for the entire contents of Span2D<T>.
// This only works on runtimes if the underlying data is contiguous
// and of a size that can fit into a single Span<T>. In this specific test,
// this is not expected to work on UWP because it can't create a Span<T>
// from a 2D array (reasons explained in the comments for the test above).
// this is not expected to work on .NET Standard 2.0 because it can't create a
// Span<T> from a 2D array (reasons explained in the comments for the test above).
bool success = span2d.TryGetSpan(out Span<int> span);
#if WINDOWS_UWP
// Can't get a Span<T> over a T[,] array on UWP
#if NETFRAMEWORK
// Can't get a Span<T> over a T[,] array on .NET Standard 2.0
Assert.IsFalse(success);
Assert.AreEqual(span.Length, 0);
#else
@@ -130,9 +130,8 @@ public class Test_IBufferWriterStream
Memory<byte> data = Test_MemoryStream.CreateRandomData(64);
// This will use the extension when on .NET Standard 2.0,
// as the Stream class doesn't have Spam<T> or Memory<T>
// public APIs there. This is the case eg. on UWP as well.
// This will use the extension when on .NET Standard 2.0, as the
// Stream class doesn't have Spam<T> or Memory<T> public APIs there.
stream.Write(data.Span);
Assert.AreEqual(writer.WrittenCount, data.Length);
@@ -222,9 +222,8 @@ public partial class Test_MemoryStream
Memory<byte> data = CreateRandomData(64);
// This will use the extension when on .NET Standard 2.0,
// as the Stream class doesn't have Spam<T> or Memory<T>
// public APIs there. This is the case eg. on UWP as well.
// This will use the extension when on .NET Standard 2.0, as the
// Stream class doesn't have Spam<T> or Memory<T> public APIs there.
stream.Write(data.Span);
Assert.AreEqual(stream.Position, data.Length);
@@ -12,11 +12,11 @@ public class Test_ReadOnlyRefOfT
{
[TestCategory("ReadOnlyRefOfT")]
[TestMethod]
#if WINDOWS_UWP
#if NETFRAMEWORK
public void Test_RefOfT_CreateRefOfT()
{
var model = new ReadOnlyFieldOwner();
var reference = new ReadOnlyRef<int>(model, model.Value);
ReadOnlyFieldOwner model = new();
ReadOnlyRef<int> reference = new(model, model.Value);
Assert.IsTrue(Unsafe.AreSame(ref Unsafe.AsRef(model.Value), ref Unsafe.AsRef(reference.Value)));
}
@@ -26,7 +26,6 @@ public class Test_ReadOnlyRefOfT
/// </summary>
private sealed class ReadOnlyFieldOwner
{
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401", Justification = "Ref readonly access for tests")]
public readonly int Value = 1;
}
#else
@@ -12,11 +12,11 @@ public class Test_RefOfT
{
[TestCategory("RefOfT")]
[TestMethod]
#if WINDOWS_UWP
#if NETFRAMEWORK
public void Test_RefOfT_CreateRefOfT()
{
var model = new FieldOwner { Value = 1 };
var reference = new Ref<int>(model, ref model.Value);
FieldOwner model = new() { Value = 1 };
Ref<int> reference = new(model, ref model.Value);
Assert.IsTrue(Unsafe.AreSame(ref model.Value, ref reference.Value));
@@ -30,7 +30,6 @@ public class Test_RefOfT
/// </summary>
private sealed class FieldOwner
{
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401", Justification = "Quick ref access for tests")]
public int Value;
}
#else
@@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>