Skip to content

Commit

Permalink
Code scanning improvements (#177)
Browse files Browse the repository at this point in the history
* No need for memberType in the IDataItemExtender.Extend method
* Ensure NullTheoryData always returns null.
  • Loading branch information
piotrzajac authored Nov 11, 2024
1 parent 6f27f73 commit 5de9125
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MemberAutoDataBaseAttributeTests
{ null, MemberType.Name },
};

public static TheoryData<string> NullTheoryData { get; }
public static TheoryData<string> NullTheoryData => null;

[AutoData]
[Theory(DisplayName = "GIVEN uninitialized fixture WHEN constructor is invoked THEN exception is thrown")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
[Trait("Category", "MemberData")]
public class MemberAutoDataItemExtenderTests
{
private static readonly Type MemberType = typeof(MemberAutoDataItemExtenderTests);
private static readonly MethodInfo TestMethod = MemberType.GetMethod(nameof(MethodUnderTest), BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly MethodInfo TestMethod = typeof(MemberAutoDataItemExtenderTests).GetMethod(nameof(MethodUnderTest), BindingFlags.Instance | BindingFlags.NonPublic);
private readonly Fixture fixture = new();
private readonly Mock<IAutoFixtureInlineAttributeProvider> dataAttributeProvider = new();
private readonly Mock<DataAttribute> dataAttribute = new();
Expand Down Expand Up @@ -51,7 +50,7 @@ public void GivenProviderWithNoDataAttribute_WhenConvertIsInvoked_ThenNullReturn
var item = this.fixture.Create<object[]>();

// Act
var data = noDataConverter.Extend(TestMethod, item, this.memberName, MemberType);
var data = noDataConverter.Extend(TestMethod, item, this.memberName);

// Assert
data.Should().BeNull();
Expand All @@ -66,7 +65,7 @@ public void GivenValidParameters_WhenConvertIsInvoked_ThenAppropriateCodeIsInvok
var item = this.fixture.Create<object[]>();

// Act
var data = this.converter.Extend(TestMethod, item, this.memberName, MemberType);
var data = this.converter.Extend(TestMethod, item, this.memberName);

// Assert
data.Should().NotBeNull();
Expand All @@ -81,7 +80,7 @@ public void GivenUninitializedItem_WhenConvertInvoked_ThenNullReturned()
const object[] item = null;

// Act
var data = this.converter.Extend(TestMethod, item, this.memberName, MemberType);
var data = this.converter.Extend(TestMethod, item, this.memberName);

// Assert
data.Should().BeNull();
Expand All @@ -95,7 +94,7 @@ public void GivenUninitializedTestMethod_WhenConvertIsInvoked_ThenExceptionIsThr
var item = this.fixture.Create<object[]>();

// Act
Func<object> act = () => this.converter.Extend(method, item, this.memberName, MemberType);
Func<object> act = () => this.converter.Extend(method, item, this.memberName);

// Assert
act.Should().Throw<ArgumentNullException>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private object[] ExtendDataItem(MethodInfo testMethod, object[] values)

var converter = new MemberAutoDataItemExtender(fixture, this.CreateProvider());

return converter.Extend(testMethod, values, this.MemberName, this.RetrieveMemberType(testMethod));
return converter.Extend(testMethod, values, this.MemberName);
}

private Type RetrieveMemberType(MethodInfo testMethod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Objectivity.AutoFixture.XUnit2.Core.MemberData
{
using System;
using System.Reflection;

public interface IDataItemExtender
{
object[] Extend(MethodInfo testMethod, object[] values, string memberName, Type memberType);
object[] Extend(MethodInfo testMethod, object[] values, string memberName);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.Core.MemberData
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
Expand All @@ -24,7 +23,7 @@ public MemberAutoDataItemExtender(IFixture fixture, IAutoFixtureInlineAttributeP
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Testable design.")]
public IAutoFixtureInlineAttributeProvider DataAttributeProvider { get; }

public object[] Extend(MethodInfo testMethod, object[] values, string memberName, Type memberType)
public object[] Extend(MethodInfo testMethod, object[] values, string memberName)
{
if (values is null)
{
Expand Down

0 comments on commit 5de9125

Please sign in to comment.