diff --git a/test/Pose.Tests/IL/MethodRewriterTests.cs b/test/Pose.Tests/IL/MethodRewriterTests.cs index a687087..6b21268 100644 --- a/test/Pose.Tests/IL/MethodRewriterTests.cs +++ b/test/Pose.Tests/IL/MethodRewriterTests.cs @@ -11,26 +11,31 @@ namespace Pose.Tests { public class MethodRewriterTests { + private class ClassWithStaticMethod + { + public static string Now { get; } = "?"; + } + [Fact] public void Can_rewrite_static_method() { // Arrange - var methodInfo = typeof(DateTime).GetMethod("get_Now"); + var methodInfo = typeof(ClassWithStaticMethod).GetMethod("get_Now"); var methodRewriter = MethodRewriter.CreateRewriter(methodInfo, false); // Act var dynamicMethod = methodRewriter.Rewrite() as DynamicMethod; - var func = dynamicMethod.CreateDelegate(typeof(Func)); + var func = dynamicMethod.CreateDelegate(typeof(Func)); // Assert - func.DynamicInvoke().As().Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(10)); + func.DynamicInvoke().As().Should().BeEquivalentTo("?"); } [Fact] public void Cannot_rewrite_method_in_CoreLib() { // Arrange - var methodInfo = typeof(DateTime).GetMethod("get_Now"); + var methodInfo = typeof(DateTime).GetMethod("get_UtcNow"); var methodRewriter = MethodRewriter.CreateRewriter(methodInfo, false); // Act @@ -38,7 +43,7 @@ public void Cannot_rewrite_method_in_CoreLib() var func = dynamicMethod.CreateDelegate(typeof(Func)); // Assert - func.DynamicInvoke().As().Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(10)); + func.DynamicInvoke().As().Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(10)); } [Fact] diff --git a/test/Pose.Tests/Pose.Tests.csproj b/test/Pose.Tests/Pose.Tests.csproj index 9877c69..971a3e0 100644 --- a/test/Pose.Tests/Pose.Tests.csproj +++ b/test/Pose.Tests/Pose.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/test/Pose.Tests/ShimTests.cs b/test/Pose.Tests/ShimTests.cs index 4ab297c..30d0593 100644 --- a/test/Pose.Tests/ShimTests.cs +++ b/test/Pose.Tests/ShimTests.cs @@ -4,12 +4,14 @@ using System.Threading; using FluentAssertions; using Pose.Exceptions; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Xunit; // ReSharper disable RedundantLambdaParameterType // ReSharper disable PossibleNullReferenceException +// See: https://stackoverflow.com/a/34876963 +[assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace Pose.Tests { public class ShimTests @@ -170,7 +172,7 @@ public void TestReplacePropertySetterAction() setterExecuted.Should().BeTrue(because: "the shim was executed"); } - [TestMethod] + [Fact] public void Can_shim_static_property() { // Arrange @@ -217,7 +219,7 @@ public string GetString() } } - [TestMethod] + [Fact] public void Can_shim_instance_property_getter() { // Arrange @@ -233,7 +235,7 @@ public void Can_shim_instance_property_getter() dt.Should().BeEquivalentTo("Hello", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Can_shim_instance_property_setter() { // Arrange @@ -250,7 +252,7 @@ public void Can_shim_instance_property_setter() wasCalled.Should().BeTrue(because: "the shim has been called"); } - [TestMethod] + [Fact] public void Can_shim_static_property_getter() { // Arrange @@ -265,7 +267,7 @@ public void Can_shim_static_property_getter() dt.Should().BeEquivalentTo("Hello", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Can_shim_static_property_setter() { // Arrange @@ -279,7 +281,7 @@ public void Can_shim_static_property_setter() wasCalled.Should().BeTrue(because: "the shim has been called"); } - [TestMethod] + [Fact] public void Can_shim_instance_method() { // Arrange @@ -299,7 +301,7 @@ public void Can_shim_instance_method() dt.Should().BeEquivalentTo("String", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Can_shim_instance_method_of_value_type() { // Arrange @@ -318,7 +320,7 @@ public void Can_shim_instance_method_of_value_type() dt.Should().BeEquivalentTo("String", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Can_shim_instance_method_of_specific_instance() { // Arrange @@ -337,7 +339,7 @@ public void Can_shim_instance_method_of_specific_instance() dt.Should().BeEquivalentTo("String", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Shims_only_the_method_of_the_specified_instance() { // Arrange @@ -362,7 +364,7 @@ public void Shims_only_the_method_of_the_specified_instance() responseFromNonShimmedInstance.Should().BeEquivalentTo("!", because: "that is what the instance returns by default"); } - [TestMethod] + [Fact] public void Can_shim_static_method() { // Arrange @@ -380,7 +382,7 @@ public void Can_shim_static_method() dt.Should().BeEquivalentTo("String", because: "that is what the shim is configured to return"); } - [TestMethod] + [Fact] public void Can_shim_constructor() { // Arrange