Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Filter\MethodExtensions.cs" />
<Compile Include="Filter\NotAbstractMethod.cs" />
<Compile Include="Filter\NotEqualsMethod.cs" />
<Compile Include="Filter\NotNullableValueType.cs" />
<Compile Include="Filter\NotOutParameter.cs" />
<Compile Include="Filter\NotPropertySetter.cs" />
<Compile Include="Filter\TypeFiltering.cs" />
Expand Down
36 changes: 36 additions & 0 deletions src/AutoTest.ArgumentNullException/Filter/NotNullableValueType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace AutoTest.ArgNullEx.Filter
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

/// <summary>
/// Filters out parameters that are <see cref="Nullable{T}"/> value types.
/// </summary>
public sealed class NotNullableValueType : FilterBase, IParameterFilter
{
/// <summary>
/// Filters out parameters that are <see cref="Nullable{T}"/> value types.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="method">The method.</param>
/// <param name="parameter">The parameter.</param>
/// <returns><see langword="true"/> if the <paramref name="parameter"/> should be excluded;
/// otherwise <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="type"/>, <paramref name="method"/> or
/// <paramref name="parameter"/> parameters are <see langword="null"/>.</exception>
bool IParameterFilter.ExcludeParameter(Type type, MethodBase method, ParameterInfo parameter)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
if (method == null)
throw new ArgumentNullException(nameof(method));
if (parameter == null)
throw new ArgumentNullException(nameof(parameter));

Type parameterType = parameter.ParameterType;
return parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(Nullable<>);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="Execution\DefaultExecutionSetupShould.cs" />
<Compile Include="Execution\ErroredExecutionSetupShould.cs" />
<Compile Include="Filter\NotAbstractMethodShould.cs" />
<Compile Include="Filter\NotNullableValueTypeShould.cs" />
<Compile Include="Filter\NotOutParameterShould.cs" />
<Compile Include="Filter\NotPropertySetterShould.cs" />
<Compile Include="Filter\ParameterFilteringShould.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace AutoTest.ArgNullEx.Filter
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using global::Xunit;

public class NotNullableValueTypeShould
{
private static void SomeNullableParametersMethod(
int intInput,
string stringInput,
Guid guidInput,
int? intNullable,
Guid? guidNullable)
{
}

public static IEnumerable<object[]> SomeOutParameters => GetSomeOutParameters();

internal static IEnumerable<object[]> GetSomeOutParameters()
{
Type type = typeof(NotNullableValueTypeShould);

MethodInfo method = type.GetMethod(
nameof(SomeNullableParametersMethod),
BindingFlags.NonPublic | BindingFlags.Static);
ParameterInfo[] someOutParameters = method.GetParameters();

return someOutParameters.Select(
parameter => new object[] { type, method, parameter, parameter.Name.Contains("Nullable") });
}

[Theory, AutoMock]
public void ReturnName(NotNullableValueType sut)
{
Assert.Equal(nameof(NotNullableValueType), sut.Name);
}

[Theory, MemberData(nameof(SomeOutParameters))]
public void ExcludeNullableValueTypeParameter(
Type type,
MethodInfo method,
ParameterInfo parameter,
bool expected)
{
// Arrange
IParameterFilter sut = new NotNullableValueType();

// Act
bool actual = sut.ExcludeParameter(type, method, parameter);

// Assert
Assert.Equal(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="Issues\Issue015\Issue015.cs" />
<Compile Include="Issues\Issue020\Issue020.cs" />
<Compile Include="Issues\Issue022\Issue022.cs" />
<Compile Include="Issues\Issue031\Issue031.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequiresArgNullEx.cs" />
<Compile Include="RequiresArgNullExAutoMoqAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace AutoTest.ExampleLibrary.Issues.Issue031
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoTest.ArgNullEx;
using AutoTest.ArgNullEx.Xunit;
using Xunit;

public class Issue031
{
[Theory, RequiresArgNullExAutoMoq(typeof(SomeNullableValueTypeParameters))]
[Include(
ExclusionType = ExclusionType.All,
Type = typeof(SomeNullableValueTypeParameters),
Method = "SomeNullableValueTypeParametersMethod",
Parameter = "stringInput")]
public async Task TestStringInput(MethodData method)
{
await method.Execute();

Assert.True(SomeNullableValueTypeParameters.StringInputTested);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Issues\Issue015\OtherEquals.cs" />
<Compile Include="Issues\Issue020\Mixture.cs" />
<Compile Include="Issues\Issue022\GenericClass.cs" />
<Compile Include="Issues\Issue031\SomeNullableValueTypeParameters.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace AutoTest.ExampleLibrary.Issues.Issue031
{
using System;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// Test class used to demonstrate pull request 31
/// https://github.com/AutoTestNET/AutoTest.ArgumentNullException/pull/31
/// </summary>
public class SomeNullableValueTypeParameters
{
/// <summary>
/// Gets a value indicating if the <see cref="SomeNullableValueTypeParametersMethod"/> stringInput parameter
/// has been tested.
/// </summary>
public static bool StringInputTested { get; private set; }

private static void SomeNullableValueTypeParametersMethod(
int intInput,
string stringInput,
Guid guidInput,
int? intNullable,
Guid? guidNullable)
{
StringInputTested = false;

if (stringInput == null)
{
StringInputTested = true;
throw new ArgumentNullException(nameof(stringInput));
}

throw new Exception("Shouldn't ever get here.");
}
}
}