Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Moving to .Net Standard 1.4 and 2.0
Browse files Browse the repository at this point in the history
references #10
  • Loading branch information
pvandervelde committed Jun 10, 2019
1 parent 15ddc74 commit f8974c6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 120 deletions.
40 changes: 0 additions & 40 deletions src/nuclei.nunit.extensions/AssertExtensions.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/nuclei.nunit.extensions/EqualityContractVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static MethodInfo EqualityOperator(Type type)
while ((method == null) && (localType != null))
{
method = localType.GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public);
localType = localType.BaseType;
localType = localType.GetTypeInfo().BaseType;
}

return method;
Expand All @@ -39,7 +39,7 @@ private static MethodInfo InequalityOperator(Type type)
while ((method == null) && (localType != null))
{
method = localType.GetMethod("op_Inequality", BindingFlags.Static | BindingFlags.Public);
localType = localType.BaseType;
localType = localType.GetTypeInfo().BaseType;
}

return method;
Expand Down
80 changes: 3 additions & 77 deletions src/nuclei.nunit.extensions/ExceptionContractVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.Serialization;
using NUnit.Framework;

namespace Nuclei.Nunit.Extensions
Expand All @@ -25,26 +24,13 @@ namespace Nuclei.Nunit.Extensions
public abstract class ExceptionContractVerifier<TException>
where TException : Exception
{
/// <summary>
/// Verifies that the exception is marked with the <c>SerializableAttribute</c>.
/// </summary>
[Test]
public void HasSerializationAttribute()
{
Assert.True(typeof(TException).IsDefined(typeof(SerializableAttribute), false));
}

/// <summary>
/// Verifies that the exception has a parameterless constructor.
/// </summary>
[Test]
public void HasDefaultConstructor()
{
var constructor = typeof(TException).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
Array.Empty<Type>(),
null);
var constructor = typeof(TException).GetConstructor(Array.Empty<Type>());
Assert.NotNull(constructor);
}

Expand All @@ -55,13 +41,10 @@ public void HasDefaultConstructor()
public void HasMessageConstructor()
{
var constructor = typeof(TException).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[]
{
typeof(string),
},
null);
});
Assert.NotNull(constructor);

var text = "a";
Expand All @@ -80,14 +63,11 @@ public void HasMessageConstructor()
public void HasMessageAndExceptionConstructor()
{
var constructor = typeof(TException).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[]
{
typeof(string),
typeof(Exception),
},
null);
});
Assert.NotNull(constructor);

var text = "a";
Expand All @@ -101,59 +81,5 @@ public void HasMessageAndExceptionConstructor()
Assert.AreEqual(text, instance.Message);
Assert.AreSame(inner, instance.InnerException);
}

/// <summary>
/// Verifies that the exception has a serialization constructor.
/// </summary>
[Test]
public void HasSerializationConstructor()
{
var constructor = typeof(TException).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[]
{
typeof(SerializationInfo),
typeof(StreamingContext),
},
null);
Assert.NotNull(constructor);
}

/// <summary>
/// Verifies that the exception can be serialized, then deserialized while maintaining
/// the inner exception and the message.
/// </summary>
[Test]
[SuppressMessage(
"Microsoft.Usage",
"CA2201:DoNotRaiseReservedExceptionTypes",
Justification = "Not actually throwing the exception. We just need an exception to store.")]
public void RoundTripSerializeAndDeserialize()
{
var constructor = typeof(TException).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[]
{
typeof(string),
typeof(Exception),
},
null);
Assert.NotNull(constructor);

var text = "a";
var inner = new Exception();
var instance = (TException)constructor.Invoke(
new object[]
{
text,
inner,
});
var copy = AssertExtensions.RoundTripSerialize(instance);

Assert.AreEqual(instance.Message, copy.Message);
Assert.AreEqual(instance.InnerException.GetType(), copy.InnerException.GetType());
}
}
}
6 changes: 5 additions & 1 deletion src/nuclei.nunit.extensions/Nuclei.NUnit.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.4</TargetFrameworks>
<TargetFrameworks>netstandard1.4;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
Expand Down Expand Up @@ -41,4 +41,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
<PackageReference Include="System.Reflection.TypeExtensions"
Version="4.5.1" />
</ItemGroup>
</Project>

0 comments on commit f8974c6

Please sign in to comment.