From 879d73daaeb25338fac409f6feff6474a17592ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:38:51 +0000 Subject: [PATCH] Bump the xunit group across 9 directories with 2 updates (#153) --- ...Fixture.XUnit2.AutoFakeItEasy.Tests.csproj | 12 +- ...y.AutoFixture.XUnit2.AutoFakeItEasy.csproj | 6 +- ...ty.AutoFixture.XUnit2.AutoMoq.Tests.csproj | 12 +- ...ectivity.AutoFixture.XUnit2.AutoMoq.csproj | 6 +- ...ixture.XUnit2.AutoNSubstitute.Tests.csproj | 12 +- ....AutoFixture.XUnit2.AutoNSubstitute.csproj | 6 +- .../MemberAutoDataBaseAttributeTests.cs | 57 +++- ....cs => MemberAutoDataItemExtenderTests.cs} | 245 ++++++++---------- ...ivity.AutoFixture.XUnit2.Core.Tests.csproj | 12 +- .../Attributes/MemberAutoDataBaseAttribute.cs | 36 ++- .../MemberData/IDataItemConverter.cs | 10 - .../MemberData/IDataItemExtender.cs | 10 + ...erter.cs => MemberAutoDataItemExtender.cs} | 98 +++---- ...Objectivity.AutoFixture.XUnit2.Core.csproj | 6 +- 14 files changed, 282 insertions(+), 246 deletions(-) rename src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/{MemberAutoDataItemConverterTests.cs => MemberAutoDataItemExtenderTests.cs} (66%) delete mode 100644 src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemConverter.cs create mode 100644 src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemExtender.cs rename src/Objectivity.AutoFixture.XUnit2.Core/MemberData/{MemberAutoDataItemConverter.cs => MemberAutoDataItemExtender.cs} (53%) diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.csproj index 5a4db199..f8ed0eb7 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.csproj @@ -86,17 +86,17 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.csproj index 3341a0f8..d3eafed2 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.csproj @@ -112,9 +112,9 @@ all - - - + + + diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.csproj index 2863ebbf..0499105d 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests/Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.csproj @@ -87,17 +87,17 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoMoq/Objectivity.AutoFixture.XUnit2.AutoMoq.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoMoq/Objectivity.AutoFixture.XUnit2.AutoMoq.csproj index e44eb93a..b4f542d7 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoMoq/Objectivity.AutoFixture.XUnit2.AutoMoq.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoMoq/Objectivity.AutoFixture.XUnit2.AutoMoq.csproj @@ -112,9 +112,9 @@ all - - - + + + diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.csproj index 1ab1cdda..c005b740 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.csproj @@ -86,17 +86,17 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.csproj b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.csproj index ea0ced28..fbf0c2ac 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.csproj @@ -112,9 +112,9 @@ all - - - + + + diff --git a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/MemberAutoDataBaseAttributeTests.cs b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/MemberAutoDataBaseAttributeTests.cs index 4e599e4a..3d5e7f73 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/MemberAutoDataBaseAttributeTests.cs +++ b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/MemberAutoDataBaseAttributeTests.cs @@ -1,6 +1,7 @@ namespace Objectivity.AutoFixture.XUnit2.Core.Tests.Attributes { using System; + using System.Reflection; using FluentAssertions; @@ -17,6 +18,18 @@ [Trait("Category", "DataAttribute")] public class MemberAutoDataBaseAttributeTests { + private static readonly Type MemberType = typeof(MemberAutoDataBaseAttributeTests); + private static readonly MethodInfo TestMethod = MemberType.GetMethod(nameof(MethodUnderTest), BindingFlags.Instance | BindingFlags.NonPublic); + + public static TheoryData MemberTypeTestData { get; } = new() + { + { MemberType, MemberType.Name }, + { typeof(string), nameof(String) }, + { null, MemberType.Name }, + }; + + public static TheoryData NullTheoryData { get; } + [AutoData] [Theory(DisplayName = "GIVEN uninitialized fixture WHEN constructor is invoked THEN exception is thrown")] public void GivenUninitializedFixture_WhenConstructorIsInvoked_ThenExceptionIsThrown(string memberName) @@ -33,6 +46,46 @@ public void GivenUninitializedFixture_WhenConstructorIsInvoked_ThenExceptionIsTh .And.ParamName.Should().Be("fixture"); } + [MemberData(nameof(MemberTypeTestData))] + [Theory(DisplayName = "GIVEN item of unexpected type WHEN Convert is invoked THEN exception is thrown")] + public void GivenItemOfUnexpectedType_WhenConvertIsInvoked_ThenExceptionIsThrown( + Type memberType, + string expectedTypeName) + { + // Arrange + var fixture = new Fixture(); + var memberName = fixture.Create(); + var item = fixture.Create(); + var attribute = new MemberAutoDataBaseAttributeUnderTest(fixture, memberName) { MemberType = memberType }; + + // Act + Func act = () => attribute.CallConvertDataItem(TestMethod, item); + + // Assert + act.Should().Throw() + .And.Message.Should().NotBeNullOrEmpty() + .And.Contain(memberName).And.Contain(expectedTypeName); + } + + [Fact(DisplayName = "GIVEN null theory data WHEN GetData is invoked THEN null is returned")] + public void GivenNullItem_WhenGetDataIsInvoked_ThenNullIsReturned() + { + // Arrange + var fixture = new Fixture(); + var attribute = new MemberAutoDataBaseAttributeUnderTest(fixture, nameof(NullTheoryData)); + + // Act + var data = attribute.GetData(TestMethod); + + // Assert + data.Should().BeNull(); + } + + protected void MethodUnderTest() + { + // Empty method under test + } + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] private sealed class MemberAutoDataBaseAttributeUnderTest : MemberAutoDataBaseAttribute { @@ -41,6 +94,8 @@ public MemberAutoDataBaseAttributeUnderTest(IFixture fixture, string memberName, { } + public object[] CallConvertDataItem(MethodInfo testMethod, object item) => this.ConvertDataItem(testMethod, item); + protected override IAutoFixtureInlineAttributeProvider CreateProvider() { throw new NotImplementedException(); @@ -48,7 +103,7 @@ protected override IAutoFixtureInlineAttributeProvider CreateProvider() protected override IFixture Customize(IFixture fixture) { - throw new NotImplementedException(); + return fixture; } } } diff --git a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemConverterTests.cs b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemExtenderTests.cs similarity index 66% rename from src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemConverterTests.cs rename to src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemExtenderTests.cs index e6875d47..bc498653 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemConverterTests.cs +++ b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/MemberData/MemberAutoDataItemExtenderTests.cs @@ -1,135 +1,110 @@ -namespace Objectivity.AutoFixture.XUnit2.Core.Tests.MemberData -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - - using FluentAssertions; - - using global::AutoFixture; - - using Moq; - - using Objectivity.AutoFixture.XUnit2.Core.MemberData; - using Objectivity.AutoFixture.XUnit2.Core.Providers; - - using Xunit; - using Xunit.Sdk; - - [Collection("MemberAutoDataItemConverter")] - [Trait("Category", "MemberData")] - public class MemberAutoDataItemConverterTests - { - private static readonly Type MemberType = typeof(MemberAutoDataItemConverterTests); - private static readonly MethodInfo TestMethod = MemberType.GetMethod(nameof(MethodUnderTest), BindingFlags.Instance | BindingFlags.NonPublic); - private readonly Fixture fixture = new(); - private readonly Mock dataAttributeProvider = new(); - private readonly Mock dataAttribute = new(); - private readonly IDataItemConverter converter; - private readonly string memberName; - - public MemberAutoDataItemConverterTests() - { - var data = this.fixture.Create>(); - this.dataAttributeProvider.Setup(p => p.GetAttribute(this.fixture, It.IsAny())).Returns(this.dataAttribute.Object); - this.dataAttribute.Setup(a => a.GetData(It.IsAny())).Returns(data); - this.converter = new MemberAutoDataItemConverter(this.fixture, this.dataAttributeProvider.Object); - this.memberName = this.fixture.Create(); - } - - public static TheoryData MemberTypeTestData { get; } = new() - { - { MemberType, MemberType.Name }, - { typeof(string), nameof(String) }, - { null, MemberType.Name }, - }; - - [Fact(DisplayName = "GIVEN provider with no data attribute WHEN Convert is invoked THEN Null is returned")] - public void GivenProviderWithNoDataAttribute_WhenConvertIsInvoked_ThenNullReturned() - { - // Arrange - var noData = Enumerable.Empty(); - var noDataAttribute = new Mock(); - noDataAttribute.Setup(a => a.GetData(It.IsAny())).Returns(noData); - var noDataProvider = new Mock(); - noDataProvider.Setup(x => x.GetAttribute(It.IsAny(), It.IsNotNull())).Returns(noDataAttribute.Object); - var noDataConverter = new MemberAutoDataItemConverter(this.fixture, noDataProvider.Object); - var item = this.fixture.Create(); - - // Act - var data = noDataConverter.Convert(TestMethod, item, this.memberName, MemberType); - - // Assert - data.Should().BeNull(); - noDataProvider.VerifyAll(); - noDataAttribute.VerifyAll(); - } - - [Fact(DisplayName = "GIVEN valid parameters WHEN Convert is invoked THEN appropriate code is invoked and data is returned")] - public void GivenValidParameters_WhenConvertIsInvoked_ThenAppropriateCodeIsInvokedAndDataIsReturned() - { - // Arrange - var item = this.fixture.Create(); - - // Act - var data = this.converter.Convert(TestMethod, item, this.memberName, MemberType); - - // Assert - data.Should().NotBeNull(); - this.dataAttributeProvider.VerifyAll(); - this.dataAttribute.VerifyAll(); - } - - [Fact(DisplayName = "GIVEN uninitialized item WHEN Convert is invoked THEN Null is returned")] - public void GivenUninitializedItem_WhenConvertInvoked_ThenNullReturned() - { - // Arrange - const object item = null; - - // Act - var data = this.converter.Convert(TestMethod, item, this.memberName, MemberType); - - // Assert - data.Should().BeNull(); - } - - [MemberData(nameof(MemberTypeTestData))] - [Theory(DisplayName = "GIVEN item of unexpected type WHEN Convert is invoked THEN exception is thrown")] - public void GivenItemOfUnexpectedType_WhenConvertIsInvoked_ThenExceptionIsThrown( - Type memberType, - string expectedTypeName) - { - // Arrange - var item = this.fixture.Create(); - - // Act - Func act = () => this.converter.Convert(TestMethod, item, this.memberName, memberType); - - // Assert - act.Should().Throw() - .And.Message.Should().NotBeNullOrEmpty() - .And.Contain(this.memberName).And.Contain(expectedTypeName); - } - - [Fact(DisplayName = "GIVEN uninitialized test method WHEN Convert is invoked THEN exception is thrown")] - public void GivenUninitializedTestMethod_WhenConvertIsInvoked_ThenExceptionIsThrown() - { - // Arrange - const MethodInfo method = null; - var item = this.fixture.Create(); - - // Act - Func act = () => this.converter.Convert(method, item, this.memberName, MemberType); - - // Assert - act.Should().Throw() - .And.ParamName.Should().Be("testMethod"); - } - - protected void MethodUnderTest() - { - // Empty method under test - } - } -} +namespace Objectivity.AutoFixture.XUnit2.Core.Tests.MemberData +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + + using FluentAssertions; + + using global::AutoFixture; + + using Moq; + + using Objectivity.AutoFixture.XUnit2.Core.MemberData; + using Objectivity.AutoFixture.XUnit2.Core.Providers; + + using Xunit; + using Xunit.Sdk; + + [Collection("MemberAutoDataItemConverter")] + [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 readonly Fixture fixture = new(); + private readonly Mock dataAttributeProvider = new(); + private readonly Mock dataAttribute = new(); + private readonly IDataItemExtender converter; + private readonly string memberName; + + public MemberAutoDataItemExtenderTests() + { + var data = this.fixture.Create>(); + this.dataAttributeProvider.Setup(p => p.GetAttribute(this.fixture, It.IsAny())).Returns(this.dataAttribute.Object); + this.dataAttribute.Setup(a => a.GetData(It.IsAny())).Returns(data); + this.converter = new MemberAutoDataItemExtender(this.fixture, this.dataAttributeProvider.Object); + this.memberName = this.fixture.Create(); + } + + [Fact(DisplayName = "GIVEN provider with no data attribute WHEN Convert is invoked THEN Null is returned")] + public void GivenProviderWithNoDataAttribute_WhenConvertIsInvoked_ThenNullReturned() + { + // Arrange + var noData = Enumerable.Empty(); + var noDataAttribute = new Mock(); + noDataAttribute.Setup(a => a.GetData(It.IsAny())).Returns(noData); + var noDataProvider = new Mock(); + noDataProvider.Setup(x => x.GetAttribute(It.IsAny(), It.IsNotNull())).Returns(noDataAttribute.Object); + var noDataConverter = new MemberAutoDataItemExtender(this.fixture, noDataProvider.Object); + var item = this.fixture.Create(); + + // Act + var data = noDataConverter.Extend(TestMethod, item, this.memberName, MemberType); + + // Assert + data.Should().BeNull(); + noDataProvider.VerifyAll(); + noDataAttribute.VerifyAll(); + } + + [Fact(DisplayName = "GIVEN valid parameters WHEN Convert is invoked THEN appropriate code is invoked and data is returned")] + public void GivenValidParameters_WhenConvertIsInvoked_ThenAppropriateCodeIsInvokedAndDataIsReturned() + { + // Arrange + var item = this.fixture.Create(); + + // Act + var data = this.converter.Extend(TestMethod, item, this.memberName, MemberType); + + // Assert + data.Should().NotBeNull(); + this.dataAttributeProvider.VerifyAll(); + this.dataAttribute.VerifyAll(); + } + + [Fact(DisplayName = "GIVEN uninitialized item WHEN Convert is invoked THEN Null is returned")] + public void GivenUninitializedItem_WhenConvertInvoked_ThenNullReturned() + { + // Arrange + const object[] item = null; + + // Act + var data = this.converter.Extend(TestMethod, item, this.memberName, MemberType); + + // Assert + data.Should().BeNull(); + } + + [Fact(DisplayName = "GIVEN uninitialized test method WHEN Convert is invoked THEN exception is thrown")] + public void GivenUninitializedTestMethod_WhenConvertIsInvoked_ThenExceptionIsThrown() + { + // Arrange + const MethodInfo method = null; + var item = this.fixture.Create(); + + // Act + Func act = () => this.converter.Extend(method, item, this.memberName, MemberType); + + // Assert + act.Should().Throw() + .And.ParamName.Should().Be("testMethod"); + } + + protected void MethodUnderTest() + { + // Empty method under test + } + } +} diff --git a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Objectivity.AutoFixture.XUnit2.Core.Tests.csproj b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Objectivity.AutoFixture.XUnit2.Core.Tests.csproj index 5fa471ab..4e999a3b 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Objectivity.AutoFixture.XUnit2.Core.Tests.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.Core.Tests/Objectivity.AutoFixture.XUnit2.Core.Tests.csproj @@ -85,17 +85,17 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Objectivity.AutoFixture.XUnit2.Core/Attributes/MemberAutoDataBaseAttribute.cs b/src/Objectivity.AutoFixture.XUnit2.Core/Attributes/MemberAutoDataBaseAttribute.cs index 30d59e80..8401512f 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core/Attributes/MemberAutoDataBaseAttribute.cs +++ b/src/Objectivity.AutoFixture.XUnit2.Core/Attributes/MemberAutoDataBaseAttribute.cs @@ -2,6 +2,8 @@ { using System; using System.Collections.Generic; + using System.Globalization; + using System.Linq; using System.Reflection; using global::AutoFixture; @@ -43,18 +45,23 @@ public override IEnumerable GetData(MethodInfo testMethod) // Customize shared fixture this.CustomizeFixture(this.Fixture); - return base.GetData(testMethod); + return base.GetData(testMethod)?.Select(values => this.ExtendDataItem(testMethod, values)); } protected override object[] ConvertDataItem(MethodInfo testMethod, object item) { - var fixture = this.ShareFixture - ? this.Fixture - : this.CustomizeFixture(new Fixture()); + if (item is object[] objArray) + { + return objArray; + } - var converter = new MemberAutoDataItemConverter(fixture, this.CreateProvider()); + var message = string.Format( + CultureInfo.InvariantCulture, + "Property {0} on {1} yielded an item that is not an object[]", + this.MemberName, + this.RetrieveMemberType(testMethod)); - return converter.Convert(testMethod, item, this.MemberName, this.MemberType); + throw new ArgumentException(message); } protected abstract IFixture Customize(IFixture fixture); @@ -66,5 +73,22 @@ private IFixture CustomizeFixture(IFixture fixture) fixture.Customize(new AutoDataCommonCustomization(this.IgnoreVirtualMembers)); return this.Customize(fixture); } + + private object[] ExtendDataItem(MethodInfo testMethod, object[] values) + { + var fixture = this.ShareFixture + ? this.Fixture + : this.CustomizeFixture(new Fixture()); + + var converter = new MemberAutoDataItemExtender(fixture, this.CreateProvider()); + + return converter.Extend(testMethod, values, this.MemberName, this.RetrieveMemberType(testMethod)); + } + + private Type RetrieveMemberType(MethodInfo testMethod) + { + return this.MemberType + ?? testMethod.NotNull(nameof(testMethod)).DeclaringType; + } } } diff --git a/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemConverter.cs b/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemConverter.cs deleted file mode 100644 index 48d04849..00000000 --- a/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemConverter.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Objectivity.AutoFixture.XUnit2.Core.MemberData -{ - using System; - using System.Reflection; - - public interface IDataItemConverter - { - object[] Convert(MethodInfo testMethod, object item, string memberName, Type memberType); - } -} diff --git a/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemExtender.cs b/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemExtender.cs new file mode 100644 index 00000000..30e3f4ae --- /dev/null +++ b/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/IDataItemExtender.cs @@ -0,0 +1,10 @@ +namespace Objectivity.AutoFixture.XUnit2.Core.MemberData +{ + using System; + using System.Reflection; + + public interface IDataItemExtender + { + object[] Extend(MethodInfo testMethod, object[] values, string memberName, Type memberType); + } +} diff --git a/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemConverter.cs b/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemExtender.cs similarity index 53% rename from src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemConverter.cs rename to src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemExtender.cs index 9772284d..f194bd0f 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemConverter.cs +++ b/src/Objectivity.AutoFixture.XUnit2.Core/MemberData/MemberAutoDataItemExtender.cs @@ -1,58 +1,40 @@ -namespace Objectivity.AutoFixture.XUnit2.Core.MemberData -{ - using System; - using System.Diagnostics.CodeAnalysis; - using System.Globalization; - using System.Linq; - using System.Reflection; - - using global::AutoFixture; - - using Objectivity.AutoFixture.XUnit2.Core.Common; - using Objectivity.AutoFixture.XUnit2.Core.Providers; - - internal class MemberAutoDataItemConverter : IDataItemConverter - { - public MemberAutoDataItemConverter(IFixture fixture, IAutoFixtureInlineAttributeProvider dataAttributeProvider) - { - this.Fixture = fixture.NotNull(nameof(fixture)); - this.DataAttributeProvider = dataAttributeProvider.NotNull(nameof(dataAttributeProvider)); - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Testable design.")] - public IFixture Fixture { get; } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Testable design.")] - public IAutoFixtureInlineAttributeProvider DataAttributeProvider { get; } - - public object[] Convert(MethodInfo testMethod, object item, string memberName, Type memberType) - { - if (item is null) - { - return null; - } - - var method = testMethod.NotNull(nameof(testMethod)); - var values = EnsureDataStructure(item, memberName, memberType ?? method.DeclaringType); - var dataAttribute = this.DataAttributeProvider.GetAttribute(this.Fixture, values); - - return dataAttribute.GetData(method).FirstOrDefault(); - } - - private static object[] EnsureDataStructure(object item, string memberName, Type memberType) - { - if (item is object[] objArray) - { - return objArray; - } - - var message = string.Format( - CultureInfo.InvariantCulture, - "Property {0} on {1} yielded an item that is not an object[]", - memberName, - memberType); - - throw new ArgumentException(message); - } - } -} +namespace Objectivity.AutoFixture.XUnit2.Core.MemberData +{ + using System; + using System.Diagnostics.CodeAnalysis; + using System.Linq; + using System.Reflection; + + using global::AutoFixture; + + using Objectivity.AutoFixture.XUnit2.Core.Common; + using Objectivity.AutoFixture.XUnit2.Core.Providers; + + internal class MemberAutoDataItemExtender : IDataItemExtender + { + public MemberAutoDataItemExtender(IFixture fixture, IAutoFixtureInlineAttributeProvider dataAttributeProvider) + { + this.Fixture = fixture.NotNull(nameof(fixture)); + this.DataAttributeProvider = dataAttributeProvider.NotNull(nameof(dataAttributeProvider)); + } + + [SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Testable design.")] + public IFixture Fixture { get; } + + [SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Testable design.")] + public IAutoFixtureInlineAttributeProvider DataAttributeProvider { get; } + + public object[] Extend(MethodInfo testMethod, object[] values, string memberName, Type memberType) + { + if (values is null) + { + return null; + } + + var method = testMethod.NotNull(nameof(testMethod)); + var dataAttribute = this.DataAttributeProvider.GetAttribute(this.Fixture, values); + + return dataAttribute.GetData(method).FirstOrDefault(); + } + } +} diff --git a/src/Objectivity.AutoFixture.XUnit2.Core/Objectivity.AutoFixture.XUnit2.Core.csproj b/src/Objectivity.AutoFixture.XUnit2.Core/Objectivity.AutoFixture.XUnit2.Core.csproj index 75dfc3d2..fa002de5 100644 --- a/src/Objectivity.AutoFixture.XUnit2.Core/Objectivity.AutoFixture.XUnit2.Core.csproj +++ b/src/Objectivity.AutoFixture.XUnit2.Core/Objectivity.AutoFixture.XUnit2.Core.csproj @@ -93,9 +93,9 @@ all - - - + + + \ No newline at end of file