From b1845ccc1f8af33286960eb480b5574ef3cfe628 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:40:23 +0100 Subject: [PATCH 1/9] TUnit Support --- AutoFixture.TUnit.sln | 8 + .../ArgumentsAutoDataAttribute.cs | 54 ++ src/AutoFixture.TUnit/AutoDataAttribute.cs | 53 ++ .../AutoFixtureDataSourceAttribute.cs | 52 ++ .../AutoFixtureLogo200x200.png | Bin 0 -> 14319 bytes src/AutoFixture.TUnit/Class1.cs | 14 - .../ClassAutoDataAttribute.cs | 104 ++++ .../CompositeDataAttribute.cs | 56 ++ src/AutoFixture.TUnit/CustomizeAttribute.cs | 19 + .../DataGeneratorMetadataExtensions.cs | 17 + src/AutoFixture.TUnit/FavorArraysAttribute.cs | 33 ++ .../FavorEnumerablesAttribute.cs | 33 ++ src/AutoFixture.TUnit/FavorListsAttribute.cs | 33 ++ src/AutoFixture.TUnit/FrozenAttribute.cs | 73 +++ src/AutoFixture.TUnit/GreedyAttribute.cs | 33 ++ src/AutoFixture.TUnit/Internal/Argument.cs | 17 + .../Internal/AutoDataSource.cs | 94 +++ .../Internal/ClassDataSource.cs | 49 ++ .../Internal/CustomizationExtensions.cs | 10 + .../Internal/CustomizeAttributeComparer.cs | 15 + src/AutoFixture.TUnit/Internal/DataSource.cs | 13 + .../Internal/EnumerableExtensions.cs | 58 ++ .../Internal/FieldDataSource.cs | 48 ++ .../Internal/FrozenValueCustomization.cs | 26 + src/AutoFixture.TUnit/Internal/IDataSource.cs | 15 + .../Internal/InlineDataSource.cs | 49 ++ .../Internal/MemberDataSource.cs | 90 +++ .../Internal/MethodDataSource.cs | 48 ++ .../Internal/NullCustomization.cs | 20 + .../Internal/ParameterFilter.cs | 43 ++ .../Internal/ParameterMatcherBuilder.cs | 199 +++++++ .../Internal/PropertyDataSource.cs | 41 ++ .../Internal/ReflectionExtensions.cs | 23 + .../Internal/TestParameter.cs | 57 ++ .../Internal/ValueTaskExtensions.cs | 20 + src/AutoFixture.TUnit/Matching.cs | 62 ++ .../MemberAutoDataAttribute.cs | 109 ++++ src/AutoFixture.TUnit/ModestAttribute.cs | 33 ++ .../NoAutoPropertiesAttribute.cs | 34 ++ .../ArgumentsAutoDataAttributeTests.cs | 168 ++++++ .../AutoDataAttributeTest.cs | 178 ++++++ .../AutoFixture.TUnit.Tests.csproj | 1 + .../AutoFixtureLogo200x200.png | Bin 0 -> 14319 bytes .../ClassAutoDataAttributeTests.cs | 313 ++++++++++ .../ClassAutoDataScenarioTests.cs | 63 ++ ...ompositeDataAttributeSufficientDataTest.cs | 207 +++++++ .../CompositeDataAttributeTest.cs | 108 ++++ .../CustomizeAttributeTest.cs | 36 ++ .../DataGeneratorMetadataHelper.cs | 62 ++ .../DependencyConstraintsTests.cs | 46 ++ .../EnumerableExtensions.cs | 57 ++ .../FavorArraysAttributeTest.cs | 44 ++ .../FavorEnumerablesAttributeTest.cs | 44 ++ .../FavorListsAttributeTest.cs | 44 ++ .../FrozenAttributeTest.cs | 26 + .../GreedyAttributeTest.cs | 47 ++ .../Internal/AutoDataSourceTests.cs | 233 ++++++++ .../Internal/ClassDataSourceTests.cs | 138 +++++ .../Internal/DataSourceTests.cs | 112 ++++ .../Internal/FieldDataSourceTests.cs | 110 ++++ .../Internal/InlineDataSourceTests.cs | 99 ++++ .../Internal/MemberDataSourceTests.cs | 113 ++++ .../Internal/MethodDataSourceTests.cs | 106 ++++ .../Internal/PropertyDataSourceTests.cs | 144 +++++ .../MemberAutoDataAttributeScenarioTests.cs | 161 +++++ .../MemberAutoDataAttributeTest.cs | 408 +++++++++++++ .../ModestAttributeTest.cs | 45 ++ .../NoAutoPropertiesAttributeTest.cs | 41 ++ tests/AutoFixture.TUnit.Tests/Scenario.cs | 560 ++++++++++++++++++ .../TestTypes/ChildTestTypeMethodData.cs | 25 + .../TestTypes/ClassWithEmptyTestData.cs | 15 + .../TestTypes/ClassWithNullTestData.cs | 15 + ...CompositeTypeWithOverloadedConstructors.cs | 21 + .../TestTypes/DelegatingCustomization.cs | 16 + .../TestTypes/DelegatingCustomizeAttribute.cs | 18 + .../TestTypes/DelegatingDataSource.cs | 13 + .../TestTypes/DelegatingFixture.cs | 90 +++ .../TestTypes/DelegatingMemberDataSource.cs | 13 + .../TestTypes/DelegatingSpecimenBuilder.cs | 13 + .../TestTypes/DelegatingTestData.cs | 22 + .../DerivedArgumentsAutoDataAttribute.cs | 9 + .../TestTypes/DerivedAutoDataAttribute.cs | 9 + .../DerivedClassAutoDataAttribute.cs | 14 + .../DerivedMemberAutoDataAttribute.cs | 14 + .../TestTypes/EmptyClassData.cs | 13 + .../TestTypes/ExampleTestClass.cs | 22 + .../TestTypes/FakeDataAttribute.cs | 20 + .../TestTypes/FixedParameterBuilder.cs | 11 + .../TestTypes/InlineAttributeTestData.cs | 53 ++ .../TestTypes/InlineFrozenValuesTestData.cs | 32 + .../InlinePrimitiveValuesTestData.cs | 32 + .../TestTypes/MixedTypeClassData.cs | 18 + .../TestTypes/MyClass.cs | 6 + .../TestTypes/ParameterNameCriterion.cs | 28 + .../TestTypes/ParameterizedClassData.cs | 26 + .../TestTypes/SampleTestType.cs | 38 ++ .../TestTypes/TestTypeWithMemberDataSource.cs | 37 ++ .../TestTypes/TestTypeWithMethodData.cs | 159 +++++ .../TypeWithCustomizationAttributes.cs | 54 ++ ...eWithIParameterCustomizationSourceUsage.cs | 26 + tests/AutoFixture.TUnit.Tests/UnitTest1.cs | 14 - .../ValueTaskExtensions.cs | 20 + .../AbstractClassWithPublicConstructor.cs | 9 + .../TestTypeFoundation/AbstractGenericType.cs | 12 + tests/TestTypeFoundation/AbstractType.cs | 19 + ...peWithConstructorWithMultipleParameters.cs | 17 + .../AbstractTypeWithNonDefaultConstructor.cs | 17 + tests/TestTypeFoundation/ActivityScope.cs | 46 ++ tests/TestTypeFoundation/CollectionHolder.cs | 12 + tests/TestTypeFoundation/CompositeType.cs | 22 + tests/TestTypeFoundation/ConcreteType.cs | 39 ++ ...TypeWithPrivateParameterlessConstructor.cs | 13 + tests/TestTypeFoundation/DoubleFieldHolder.cs | 9 + .../TestTypeFoundation/DoubleParameterType.cs | 15 + .../DoublePropertyHolder.cs | 9 + tests/TestTypeFoundation/EmptyEnum.cs | 7 + tests/TestTypeFoundation/EnumType.cs | 58 ++ tests/TestTypeFoundation/EqualityResponder.cs | 22 + tests/TestTypeFoundation/FieldHolder.cs | 15 + tests/TestTypeFoundation/GenericType.cs | 18 + .../GuardedConstructorHost.cs | 18 + ...nstructorHostHoldingStaticReadOnlyField.cs | 20 + ...ructorHostHoldingStaticReadOnlyProperty.cs | 25 + tests/TestTypeFoundation/GuardedMethodHost.cs | 81 +++ .../GuardedPropertyHolder.cs | 26 + .../GuardedStaticMethodOnStaticTypeHost.cs | 10 + tests/TestTypeFoundation/IInterface.cs | 7 + .../IllBehavedPropertyHolder.cs | 32 + .../IndexedPropertyHolder.cs | 18 + .../InternalGetterPropertyHolder.cs | 12 + tests/TestTypeFoundation/ItemContainer.cs | 22 + tests/TestTypeFoundation/ItemHolder.cs | 61 ++ .../MultiUnorderedConstructorType.cs | 48 ++ tests/TestTypeFoundation/MutableValueType.cs | 19 + .../MutableValueTypeWithoutConstructor.cs | 8 + .../NonCompliantCollectionHolder.cs | 12 + .../NoopInterfaceImplementer.cs | 10 + .../Properties/AssemblyInfo.cs | 12 + tests/TestTypeFoundation/PropertyHolder.cs | 20 + .../QuadrupleParameterType.cs | 21 + .../TestTypeFoundation/ReadOnlyFieldHolder.cs | 7 + .../ReadOnlyPropertyHolder.cs | 7 + tests/TestTypeFoundation/RecordType.cs | 29 + .../TestTypeFoundation/SingleParameterType.cs | 12 + tests/TestTypeFoundation/StaticFieldHolder.cs | 7 + .../StaticPropertyHolder.cs | 7 + .../TestTypeFoundation.csproj | 12 + tests/TestTypeFoundation/TriState.cs | 9 + .../TestTypeFoundation/TripleParameterType.cs | 18 + .../TriplePropertyHolder.cs | 11 + ...thCastOperatorsWithoutPublicConstructor.cs | 19 + .../TypeWithConcreteParameterMethod.cs | 9 + .../TypeWithEmptyEnumField.cs | 9 + .../TypeWithFactoryMethod.cs | 24 + .../TypeWithFactoryProperty.cs | 17 + tests/TestTypeFoundation/TypeWithIndexer.cs | 24 + .../TypeWithOverloadedMembers.cs | 29 + .../TypeWithPseudoFactoryMethod.cs | 21 + tests/TestTypeFoundation/TypeWithRefMethod.cs | 13 + .../UnguardedConstructorHost.cs | 27 + .../TestTypeFoundation/UnguardedMethodHost.cs | 17 + .../UnguardedStaticMethodOnStaticTypeHost.cs | 9 + ...UnguardedStaticPropertyOnStaticTypeHost.cs | 11 + 163 files changed, 7546 insertions(+), 28 deletions(-) create mode 100644 src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs create mode 100644 src/AutoFixture.TUnit/AutoDataAttribute.cs create mode 100644 src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs create mode 100644 src/AutoFixture.TUnit/AutoFixtureLogo200x200.png delete mode 100644 src/AutoFixture.TUnit/Class1.cs create mode 100644 src/AutoFixture.TUnit/ClassAutoDataAttribute.cs create mode 100644 src/AutoFixture.TUnit/CompositeDataAttribute.cs create mode 100644 src/AutoFixture.TUnit/CustomizeAttribute.cs create mode 100644 src/AutoFixture.TUnit/Extensions/DataGeneratorMetadataExtensions.cs create mode 100644 src/AutoFixture.TUnit/FavorArraysAttribute.cs create mode 100644 src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs create mode 100644 src/AutoFixture.TUnit/FavorListsAttribute.cs create mode 100644 src/AutoFixture.TUnit/FrozenAttribute.cs create mode 100644 src/AutoFixture.TUnit/GreedyAttribute.cs create mode 100644 src/AutoFixture.TUnit/Internal/Argument.cs create mode 100644 src/AutoFixture.TUnit/Internal/AutoDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/ClassDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs create mode 100644 src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs create mode 100644 src/AutoFixture.TUnit/Internal/DataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs create mode 100644 src/AutoFixture.TUnit/Internal/FieldDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs create mode 100644 src/AutoFixture.TUnit/Internal/IDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/InlineDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/MemberDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/MethodDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/NullCustomization.cs create mode 100644 src/AutoFixture.TUnit/Internal/ParameterFilter.cs create mode 100644 src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs create mode 100644 src/AutoFixture.TUnit/Internal/PropertyDataSource.cs create mode 100644 src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs create mode 100644 src/AutoFixture.TUnit/Internal/TestParameter.cs create mode 100644 src/AutoFixture.TUnit/Internal/ValueTaskExtensions.cs create mode 100644 src/AutoFixture.TUnit/Matching.cs create mode 100644 src/AutoFixture.TUnit/MemberAutoDataAttribute.cs create mode 100644 src/AutoFixture.TUnit/ModestAttribute.cs create mode 100644 src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/AutoFixtureLogo200x200.png create mode 100644 tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/ClassAutoDataScenarioTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/CompositeDataAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/CustomizeAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs create mode 100644 tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs create mode 100644 tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs create mode 100644 tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs create mode 100644 tests/AutoFixture.TUnit.Tests/Scenario.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ChildTestTypeMethodData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ExampleTestClass.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/MyClass.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/SampleTestType.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMemberDataSource.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithCustomizationAttributes.cs create mode 100644 tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithIParameterCustomizationSourceUsage.cs delete mode 100644 tests/AutoFixture.TUnit.Tests/UnitTest1.cs create mode 100644 tests/AutoFixture.TUnit.Tests/ValueTaskExtensions.cs create mode 100644 tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs create mode 100644 tests/TestTypeFoundation/AbstractGenericType.cs create mode 100644 tests/TestTypeFoundation/AbstractType.cs create mode 100644 tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs create mode 100644 tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs create mode 100644 tests/TestTypeFoundation/ActivityScope.cs create mode 100644 tests/TestTypeFoundation/CollectionHolder.cs create mode 100644 tests/TestTypeFoundation/CompositeType.cs create mode 100644 tests/TestTypeFoundation/ConcreteType.cs create mode 100644 tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs create mode 100644 tests/TestTypeFoundation/DoubleFieldHolder.cs create mode 100644 tests/TestTypeFoundation/DoubleParameterType.cs create mode 100644 tests/TestTypeFoundation/DoublePropertyHolder.cs create mode 100644 tests/TestTypeFoundation/EmptyEnum.cs create mode 100644 tests/TestTypeFoundation/EnumType.cs create mode 100644 tests/TestTypeFoundation/EqualityResponder.cs create mode 100644 tests/TestTypeFoundation/FieldHolder.cs create mode 100644 tests/TestTypeFoundation/GenericType.cs create mode 100644 tests/TestTypeFoundation/GuardedConstructorHost.cs create mode 100644 tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs create mode 100644 tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs create mode 100644 tests/TestTypeFoundation/GuardedMethodHost.cs create mode 100644 tests/TestTypeFoundation/GuardedPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs create mode 100644 tests/TestTypeFoundation/IInterface.cs create mode 100644 tests/TestTypeFoundation/IllBehavedPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/IndexedPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/InternalGetterPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/ItemContainer.cs create mode 100644 tests/TestTypeFoundation/ItemHolder.cs create mode 100644 tests/TestTypeFoundation/MultiUnorderedConstructorType.cs create mode 100644 tests/TestTypeFoundation/MutableValueType.cs create mode 100644 tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs create mode 100644 tests/TestTypeFoundation/NonCompliantCollectionHolder.cs create mode 100644 tests/TestTypeFoundation/NoopInterfaceImplementer.cs create mode 100644 tests/TestTypeFoundation/Properties/AssemblyInfo.cs create mode 100644 tests/TestTypeFoundation/PropertyHolder.cs create mode 100644 tests/TestTypeFoundation/QuadrupleParameterType.cs create mode 100644 tests/TestTypeFoundation/ReadOnlyFieldHolder.cs create mode 100644 tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/RecordType.cs create mode 100644 tests/TestTypeFoundation/SingleParameterType.cs create mode 100644 tests/TestTypeFoundation/StaticFieldHolder.cs create mode 100644 tests/TestTypeFoundation/StaticPropertyHolder.cs create mode 100644 tests/TestTypeFoundation/TestTypeFoundation.csproj create mode 100644 tests/TestTypeFoundation/TriState.cs create mode 100644 tests/TestTypeFoundation/TripleParameterType.cs create mode 100644 tests/TestTypeFoundation/TriplePropertyHolder.cs create mode 100644 tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs create mode 100644 tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs create mode 100644 tests/TestTypeFoundation/TypeWithEmptyEnumField.cs create mode 100644 tests/TestTypeFoundation/TypeWithFactoryMethod.cs create mode 100644 tests/TestTypeFoundation/TypeWithFactoryProperty.cs create mode 100644 tests/TestTypeFoundation/TypeWithIndexer.cs create mode 100644 tests/TestTypeFoundation/TypeWithOverloadedMembers.cs create mode 100644 tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs create mode 100644 tests/TestTypeFoundation/TypeWithRefMethod.cs create mode 100644 tests/TestTypeFoundation/UnguardedConstructorHost.cs create mode 100644 tests/TestTypeFoundation/UnguardedMethodHost.cs create mode 100644 tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs create mode 100644 tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs diff --git a/AutoFixture.TUnit.sln b/AutoFixture.TUnit.sln index 92436f4..425e306 100644 --- a/AutoFixture.TUnit.sln +++ b/AutoFixture.TUnit.sln @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution LICENCE.txt = LICENCE.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTypeFoundation", "tests\TestTypeFoundation\TestTypeFoundation.csproj", "{5F812210-5B61-4CBF-A033-4C33067A5DE9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,12 @@ Global {4056BD12-5FA8-4D2E-274A-7E85E858A5FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4056BD12-5FA8-4D2E-274A-7E85E858A5FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {4056BD12-5FA8-4D2E-274A-7E85E858A5FC}.Verify|Any CPU.ActiveCfg = Verify|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Release|Any CPU.Build.0 = Release|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Verify|Any CPU.ActiveCfg = Verify|Any CPU + {5F812210-5B61-4CBF-A033-4C33067A5DE9}.Verify|Any CPU.Build.0 = Verify|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs new file mode 100644 index 0000000..57703a7 --- /dev/null +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -0,0 +1,54 @@ +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// Provides a data source for a data theory, with the data coming from inline + /// values combined with auto-generated data specimens generated by AutoFixture. + /// + [CLSCompliant(false)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// The data values to pass to the theory. + public ArgumentsAutoDataAttribute(params object[] values) + : this(() => new Fixture(), values) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory. + /// The data values to pass to the theory. + /// + protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.Values = values ?? new object[] { null }; + } + + /// + /// Gets the fixture factory. + /// + public Func FixtureFactory { get; } + + /// + /// Gets the data values to pass to the theory. + /// + public object[] Values { get; } + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) + .GenerateDataSources(dataGeneratorMetadata) + .Select(x => x()); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs new file mode 100644 index 0000000..798d754 --- /dev/null +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -0,0 +1,53 @@ +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// Provides auto-generated data specimens generated by AutoFixture as an extension to + /// xUnit.net's Theory attribute. + /// + [CLSCompliant(false)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class AutoDataAttribute : AutoFixtureDataSourceAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// This constructor overload initializes the to an instance of + /// . + /// + /// + public AutoDataAttribute() + : this(() => new Fixture()) + { + } + + /// + /// Initializes a new instance of the class + /// with the supplied . Fixture will be created + /// on demand using the provided factory. + /// + /// The fixture factory used to construct the fixture. + protected AutoDataAttribute(Func fixtureFactory) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + } + + /// + /// Gets the fixture factory. + /// + public Func FixtureFactory { get; } + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var source = new AutoDataSource(this.FixtureFactory); + + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs new file mode 100644 index 0000000..ff2c83f --- /dev/null +++ b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs @@ -0,0 +1,52 @@ +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit; + +/// +/// Base class for data sources that provide AutoFixture test data for TUnit data driven tests. +/// +public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGeneratorAttribute, IDataSource +{ + /// + /// Returns the test data provided by the source. + /// + /// + /// + public abstract IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); + + /// + public override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) + { + if (dataGeneratorMetadata is null) + { + throw new ArgumentNullException(nameof(dataGeneratorMetadata)); + } + + return GetTestDataEnumerable(); + + IEnumerable> GetTestDataEnumerable() + { + var parameters = dataGeneratorMetadata.MembersToGenerate; + if (parameters.Length == 0) + { + // If the method has no parameters, a single test run is enough. + yield return () => []; + yield break; + } + + var enumerable = this.GetData(dataGeneratorMetadata) + ?? throw new InvalidOperationException("The source member yielded no test data."); + + foreach (var testData in enumerable) + { + if (testData is null) + throw new InvalidOperationException("The source member yielded a null test data."); + + if (testData.Length > parameters.Length) + throw new InvalidOperationException("The number of arguments provided exceeds the number of parameters."); + + yield return () => testData; + } + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/AutoFixtureLogo200x200.png b/src/AutoFixture.TUnit/AutoFixtureLogo200x200.png new file mode 100644 index 0000000000000000000000000000000000000000..32a82c5d19774c5ae7c44b9b37ccb569c4a049cc GIT binary patch literal 14319 zcmaL8b97$uvp1T?wrw=F%_p|)CuU>Ywi}yG8l%Azvq@vyc5~D7p5J-zANSn7*5;b| z4EJ}>nprzaSy37Z9v>bI3=9b%Bcb|v2L0P%p+Aqc+I9J#CpdQm4&K>iMf~asD%I+7z8O$UE57tL7vad(VofV9}SbIz0)T*7?^;tr;~}9 zt%Vz@sf88LL6H2ivzMF{Xf8;u#i_ue;3RHg4V3YAu~73?R5$asHRClW7ZxHF@Z|dh zu(xnCA@#Jkb8zMJ6eRyIT)xlie~+2TN&kz)%~p{7|0t!cpiC<6=wd<2$;85F#=^xy z%EijW%Fe;f&CNi{#=^?N%)-XZ%Erjb&BxBh$HGGT-y8X-G#7JAK2-^+|CaT6CrEDX z=H|r5%%*xBl`wxSSjq#I$(bdbr&BT+@!Ik1a2oe^qW-dS{H=v^f z=|4mhQ%836YD-+8pJUM|T&q&%jwy{1fHGC+=cl;^ye0?&xUuA1^9fJGwc#T01(C zimP#wY5^V09X(wCi&{Z}58&YHX5wIG0gw z_N4!1Fdy)L*G2q)#rtnw^Z#8JiT{Ee0on*-E-y44{pIiBW*)yT6h$G(2z^Eh`a&~O9dL{?5;46Yut@+ zhj2E1co`cC%0d--bwDifL<-Z{F6uW=OSC92Q} z4Ihs`J_X&=-Iu?OGy<3o)z?3|JtADEeIK6A8@6vYyVE26b7aR#zY@=X>);^Xj2cP1 zev%Y$h#O(ve5-I=*T}Zc1yT{8?l>zAyg`DiWcp>j7X+aAL-)PioNXM)rJQWSp3!ui z^*QX)c;T%GocMr`7Z~IlvFFe3A5KI1IT{}x9tV5+eoa5@+9kQKB^YyRCs0h}G5*kr z_v9TGwVBaN301&;4St>vfMJGsYl<45V%L1$)~_Bn8cMj`IegiDd|!MVL#5*folxz0 zSChEUW$ZeuXW>#^6H(%sF&<+8ktAMBrMxFD#HAz5+fttNyZCu_+o_6p6lji0 zCww#0s1AsONh5foxTmY=#n}?T?|cG?K6+RcV|%}ff2aHrG69qPg8?EaiTH@DZ4M22 zm+u5oG?teINX*+EOd2v^mkjcN6y4!;x48(mbm1F52!7f^Q2cWlJYbe;u8^3x{S|~; z14`sQ8XYnDDwaqnT)@yjP3Py)Kts>tLGt7ygcH!kq8PtAu1q_cPr7wlBkkbjBR>`j zbBGt9l(Z&D`WSf7#wm#b%&CZ|N+IpGyxsqGy^BS27Vu?^g?98%G*(m&;vtpn5ed%= z*AofBFk=b5>9YFzR)Z#eRAsJ#sH8v?dqMLeYpVh6Xw-JL<*YfVb?`9XW9JJF=Ds07 z{2MBIiTou`C_4195Bs<`Q$3lhia_wtp@V#H6b%aBaUg=fMn_Kx88DglkBC?mC8S(- zZ!4x#7F=)-mJvO+2JeixW7Mn3Ld4Mm4=)q_y5XD?`ZzwwrUBY9nW2x+$#S_v5H|(V zE(0DSiEtTkm;GlJobi5yw!YqoZWsE0L5N zV%%zAhpp>*_h(op3bbP#9y4q@YCoO&`+ckD%g?zDiE61G$g+0~+(Wx9b3;`2 zf>FPl^)e?qe$4M-d){5Lv_~ZxHXpNS7MLxOc$zfMF#=D&p&mu`OI9R)1#aVrO?tTf zB@&@Qo2MXJ%vNf}C$Z@yZ||l|sq5*bCt*r3nqpknn_IjkUAvZ%Pc~-SJfZ ze{aO-E^O`xRV@=r@CIw|73DP-*kzVz5A8F+#p+F<%*_^1-4>#4N@bRaUvxjSe2>)@&< z;N^Qfm#moqXp>q6o2Iz!p=P$c#7!J!mbtyt|68W4rG39sgY@BW8&@hPr)xnBN#{_} z?qf~hYS|5Y=nK)d`=@|=x}VKll&`pOeAZrvd!+YN&Lh3$g+DTg;G|-Uki5EaD@=Fo zRiMT=bNE!?a8vx?*?TP4ckI%hNwz<^bqHCkERFmH#AqfCP^aO7&RwIWO-bk(8AE8H za*(}bG|-vjGMftlcS45VB@~!Lc<46G_3?$Kte=|-!c^w_EPS3xo*y<>^;3hX?D^5h zfB2|wh3Xs;hlB-9re_|xjRnp25GT7D3E!h|;glK!R-J-z%@#4{vvKERBjCb&y`zIc z237xy3n zfK`|RrEUg*RSE?LXZv~-uPM$Y-RtszuVy);0tJ9eo_7>xrav82_RQ1jG>T05A zp;ggpbOST4wxaJ+R8ZCShu?bJGCu z#}0y9@sUo7@C6_u*mj#RZ6(S+qzAEBz45atd>IIX4v6tb6INtiSD%Y7ASFW@%SzNr z-Ntx&48>7FCez?nx#I^9g}DS;2|ceu`F4~Laf_}r!qFXLm86>Zq{Rde6V)^|!re9^ zmdo}(rZRm6j$Du~IEq;F${|75K3t6cG5uYxX-(ad?UN<`~E>A5rS3$Zf=dsl`yY%8cSB0BlN#Z(>xdVu#B0%T=WX5ro9o=zyXWTon>@!j zF9*Vhp%Fq{VdT-28eEAvx?}jL{^^2|Zp{aVeRgC~JJ$0#FPjzjS z$NWIXsoTF>KKU<7 zZsx0o?w{Nks&Qn-GsB743!=}LjMAl$N}8Qbe3e%)J&qCGMmjx|s2pYMvgUWXPb1nn zZLwZ1T?cO?YZU%=`jP$s&w(w{$cQ^3S-iu)Lif}CrvWJMD7+QA-w`M0#2fAlv8mHo zHbV5D73i?dDw1nBy&a6h$(>k~pYkW)1q)fe*&cr}d0$rQbz6|_|Fc*h`@>&iX)cfR z3ucxaQyPR7uIL``D`N69;v17Bw$6OH(sXH3TEBIN2>esXp4SdK|J-!RE*7%O-KR z+M6f6qj=+$md&h2pdU4?QIj&cK?P^7olKbWRjf=185DeLUvkpuaVD%yafphLI1hBS zd}^!GRiO(YNr~(hnTpkJ>_@PL1mzK0t>+_osr{+j+-tu7aYcW*nMQe|+@i%wA%QXO z3{F}xiBk{FmXF^w^VcrI#c3cB1Y^8X;Z2C7q?diLe0SWr+t9$|WY}Gzo-PYsAE`vN zD17@Iypb41g3Rm5w4is})3vwi9CpGm3iPC7)&p4gS{T1&aQ_w;q%KJ1B~T<>a*M);oTr4;g}K-f2el`_Vr@9DGP&@kv7g6J1+JL*jyhWbJW@6%mw3;qXc zjShA*c|N>wF}X*}HSQBnE%i@3y!&!uFkh>Pn6z*Vg2hlPbd2(nB3RZxNE#g6#n2^kt zG=hIIPSy@0jPeS9V*}9cjpjVG75k=Sdqp1B3N4lCY`hppPk}@ZBxJ*NZQB6Ey4!-r zvF(0mEX{&zZqsy>(2XNlFG`qdI9~TPhE+BH>p%x|xOQ zg7uUBA`$==pmnMU?;G#Di|P+KZs+8!5CKY~3EB3qqcO<2@-0aOELk zMUEbezqa)BB)&R0b)MEWJ%`2RX(l7U`yNZ$La-Ql z_JZYF*Eu~WllzvY{StD?jWo+km1znkr0nFG9yL^+Y6D%W>CZx-0JXUY)ha|uCb1hv zm>E&vJ9bsdinN6Gg?e;j6i#)YbK^^Ed(m*jMmrPH>-ORM`=7L6$5@h1voBD%;jL}? zurZ0$Alzir{u^Kq76fiEnS8(UL9kuMd6Dl3X_xhkazJALUS6@f-L!!sg%*6zo!aXq zp8=$1jIW`P?BI&hcoX_+vtTH7ckygwyR|GaC9YbMTp&HCSxFRfJpbYICK2}&hh^;Z zR6ccfHGko|X{wz%b9R~3@&W;*YtoG-mn|a4cdPf3ej&=8(ZEFT+-7*vLig)^Ay(1n zT-XFd&uFpZ)uPj}tLgP9Z1wf0o-Q%`Ge$_W)00%*N`ao@5XrcowR>+LT7OSPH;LRO zRx;iu{ZZmH{DIQo6MAbmrVg1ZEY$!PU7X*<>H{vs=*K4%3=tyCoTDt(DV zh%aH2(yu<-9TTg~B)Q(%6& zurSLfjPNz>r5Q;mM=B~{WOPC&8M2kTiF>K>QEeLahe@ihm>*8bPcjYcF0=W|vDdQG z?$QSuw}C0yZ(@)TFhQU88FJ4eq}6YztDMUE3Y9=|zxVXyKmWBi4jgIG^N?ZSen(dB zPJz?7ugHqcODv;k5hGixFOUuKcc9OG%UCQiSq+W(iN3@7`GAgNi)-plR|Mu*!TnNz z%X3^YbuEiHt(Sn2P*}1C&r_f%&3-GvaH@-iLjgtvdX)$iFFK(uY-L`?&uI?{Q(XYH zJ?W%;L#eR29iU{`aAR{H<>?o}pclHoq8Bi#m9&yj!}!b{mhH7nEH~0h^q-QUtS`82Z*{Q|ZUkY73F=8EQFZ#Tg5Dk% zE(lCS@(gLOPb12l*5`4Nj&;EL)sN7Go}-&adMK2bk>1~K?q(Y^455L8`mlC$AZWlW!*(TApLp+gf0^#r=s~X`V%rTN9qIV}A`0P$@{EL4HPq(O##?mzX3vp+ zf8y#pVg|3x)_I$d8&=3xrqaSvmn>_~B&;c&5W1IOHV%YrmjhI0QLzt6@Y7Qg;k}!G zHPKJtX2c-252wwRMNxurcxW=SlvPrdwcC_6be)LZq&`2^H>Y&#sfuruGBR6kB~P4g zcR~V<@~9kfRCG38Gi3*&VtW%SaB*@BkkKaOe>G_MjJ%>6D2&i(qkV}cyAhjp>gk^F0WOL(MS+z5fD#}FF9Ns?C6xg->G+dVwl@%8 z4%2X>R^UD_>k!Fs>(lD6WEfw!o|FYb_8RI8cFb!WunjZ!0Ox58-?~+#OZ@t!iSGxW zu4~9zT1I2~oXuKqL=SS!mZJ&lL)=_+25^*s@%fF3ls!D2kD7RrkrAgBeLu4IuZ@*C zrp?>6R0}wnbBFH%1FJjtDlzV-{hr>6O+Qghgsuz;ey~yE`VnJJ8G~l2j-N#E#?!-m z<9){388AZkF95qC3+kESYH)~}mK#@j83f~xXG%SHK1-hkn7~J_^gH0q)3Q-9Lv@>3ZRX zW$6i5fzl4JS{~~q117slB%y?oi5H}L$vsFQ?wd+&EBUe*If7rJ$=Yize#xqlF)Yh{SMZD3~cP zN!H(R74kiT{SNyQM$aV+N?Cf0#0y$>I1>bQ9mI+YwV4D5ZtMqRal$G=pJYZ5%cc7T z5hN3bGT#4E6J8)yf^@g>S$iD%9VI=+y9@ByqKzo{SNR+78`fx-7h^mrF}{yp$Kes` z{w{BtfaWq*?4uCH1r6@Iz*I&k$qTjs|@ZAOK6_idip93`bmUa7>RX#<3>%{KnHi* zJx~J4DL@BoMra9=7z$qirw(=Vr7Am9Yl@kD>pG8wT3c95foqEADlnz20>d`BtO~x0 z{Jj!qoQ@X_6GXFed(^+Y88hXxj}^duP z+Bpb*AJDnaGfn%B3LmwNTQo4EnLfhBaxagZU5(O5+jOBQm-xDO!w ztYS@gq1X3Ud5Sq=bEckf+dO2*<#BC2g**s6mj3s*Lwy~(msgLZCK#6)p7$%WZv-kz zyg>RS1sqJ6m9pe)ZI+r~N)Tn{UQDVK z{tZ9=Eml9l5!=L2MYAy8;~m%Q*nx%TrcF@R3|o$Q8Usc>jHjQ9+?9IH#Ms~oe95yn zHW3^uG+S(UD|UspL3JJY*<6<+fj&dso7pg9?Yxo|whFV#Ezsk@3Z>g+0S#Di-{Y50 zaQgfzOFaHGOuBy<=Yd~BTi&dYOl(g|Tpi+9zuFxPFFcR0ExODq%C^QgBW>ITKxfcg zErATu|8pl8tRGyYIqsDNfzYm%(P^_26i9YZ=uQsatYW*GK-THB@C%x$#S8XDC}!D_ zOuIjkD&(_&g}68BgkH!zU@xP3|1;QQLSjumc8e1hlzhoY&&C5 z5cC&~F|N^<4`Dz=r6?}<>`i=1i{5>LrgievAEW?t0b?897JDIVj3D4thay2%&n8DI!DHEM`Vm$B=Ur zOHOF#^6#F&%AQ#3U!Sc$v5AFIO_i>fvbjg8WXG>dJyh)Pry)leT{^{eUmHp1w6 z^m7F$@AbKi81yEwjClw~bDUU_U6?yzDov~)(oM6?jA`R&u*ENB*_a< z{0RtjeKQkKq!TZt%D3eHy$!DYm`l>yR1Fsg7)I~z)-e+~-}5??D$tDO>=d>`L~mvxPeqs1 zN45yFpSAN$v-tJMK9`uICr`-j6>Vgt2Bmfz*w!5B;jE#4mMH^w|ajk{IPG~Jkjk*{rSxQcQNh3}+M48}QLO|FEtowc*%MU5?ZtWOHgNdBC4gI#tCFBgdXH zTBuJdy7*?jGGkvcIBgQ|trVaUR69Lt0P?xx+;pNU=E<8U?}?ACAnf0w%+%DDytX8E zRw%&;Nj~?v+GxI7FH-{H6uwC+T`ZJW&5ycF^O~W9DmPdj*!&V+jo)Ee3)6lV0R>L> z%Yw2i4s`Kt0r4b`+r%R}Tlz!N>N1X%3O^5h}G&*WZ&hvWw z2Y!&m6gxGyekXF7>2po4nR~%}UT-?eyCLm`9MJmLi#MZX?5ZYZkPSAeS-qxEBi@^H%ym2eU^LK}i`n$frKY}N`OSgcIfRyuJs9`@-ok^R5#B~ z%CYOuCWsBUsk^GD=*c~%wn%+TYTnI!4+2VwRf;9C#cPNYR)EA5 zReEWvQHvW&k~OIeJa14O>d#x&qPC-5D?hS&09Hh5te1jvOQ|j4l)7q!p_5Sy(QKOS z^D$VRy}|7{sB}jKV}BI*sLQTt2fO9!Q(H9WBnkXcb-)PMt$PV_&{?c#aJeXQ(K5^l zRw`7je^E``+NXx6&18Xa6V=ddALkgUYD-(Ze%%`-P~5#OylAp7Q!;p#zA}YC+c0{O z5q+1D>)Gop3!uI}h{#}~10u1VNt;#)5SlvvI1+sa(J`W+CkWH7tIX-jWpus2*#0~u z`iPKO`68HsePk~zmh6Ee=Lg3 z^eHrZP2wvbef(?zJX@s;rq4>b_WnRJHAH%flp!5l3*Uvf{31KP;#<_H!a%=Wy8_-EZ>X`d=HRH z`DJxujxV|YUeVXy%=|$XQSOXcLoVdJq}&Zv*H;Z^%HNS-Wuduv42QWe=qN7Xl(iw^ zz89DP=TfFN#aiw_{%KAC*|c-_l%eMBxJf~xefLlL-Fola?BmXp08Dj}0!c+$fm6i2 zcRDd{LWmHEiGDWvO)1wx>5_nldZln!lZuP2~`~4?-B}d`kO~ z-t#y`vW^aO28??&K9vNaV$gG~l)5ye?7N^yu-HwB1Cd z%&6nxKVQl@7FK4j-?&MfpYju!4AkayWwg3p!#gbz`44|F9;xo26|4KYJ3#8-J?Su} z{>QloG)u!=w@?If0BI_ zf^}bcilVOmY7Xq68+8|ZbDrF&U*EmIe$x84rt}lOvR+^2>59rwZ*eZOqJ>c>4Qiqj ze>;LG`>EZD$dnk1{L<{1t3~p0c+wo;t99I%-0I=|Wc$EF=1Htu+NDWWI)lGI!CXuZY@_1-{W>4kf6q(Qaga%@xFQs?C+ zUzk;ba%7z4jqW!w!s4op{l-bZUrx_g-K!zJjn`cTvwTVvezydq>)lB|abxS#HiCY` zfL0$t(YqcDHlnzEKbtJU$?Th$vK}@aFXm1hX1zL#o4Xg&E7zrAvtHYc#}xiyKG7X9 zVfWve;EnaotAAEi6VGp>97n+E9_&Mi#zbf&kbU7RuR6Q*ux2t!zfh^N*);7=Bsr~E z?Eq8AQoJbOa>>os+@EBS!|Cbls8HrqQxWPgP=IYSgKm1V#k5>kr3FF$>ehr>prTaWPlCYCD3M~$Fv5n^{-7}XFv;7Odu2|L6%>V@Hy*&CA4 zDXYTN;zUkYE{c2HbUHd&M4uz}YYbGu-`J$PD!ky1G*UlKmFIuPw&3z^_W05abH?Wq zwYYG5C9C?LFA`Vf49zxdu?~eXo$n8e%X0t4B?(L3Iq2;LEF9R^-NIKkdmyU-aa#^m zKyglWC@lS}f9?W9cvIlu+4=l6z(uR(P-VGMf?%scNw(@c z;+UWJY@G&fF=O*cLS`L0WS~N*5G;%Q01u(WsLL|GqvuYdMh>pAS-9bmYQVYTOUh5J z*(Ytx&*sz6I8;*DI%iO5@k;oSz4u(7_H@3`7~^M_r(|bF3{TA&*~o6Iw$tzW^xZ(Z zT|vZ$4yl*EFJyF!{q8{nn1lOty$9k&;e^!d^kch`u&FDcz=}&-q-M9snK5oc!K?76 z^+%qghE*gKn)J|^@?mIdMi~lFQ?$iVE?N zjbBRRlD?*tO(pBEu`cDUmUp2PB-Rnfds`#~sNe4`+tvm8b|(S#5d5j-I?#}Asx=WT z*+(}7{~CmDpr85@AQ6gh{LEA)Pfn{&qH>^0xSn8Zd=NG7uWoKNJzbo)LYCU^zEUDf-0i`Tqn zMJ?4fkK53hj+A)BS&pNyrxfLIG!#dkM3v%^$?ZkAh;?AY!RM3Jx!+?SK}YYS82?Ut zDRD`crpDV5HxmQA!F1IVwR3O2ic0lzCZ`KQe6`J^sU;OBZ)_^D-2?2V?!{w@%a`573w)So zu+Gk5rktU5ipyYTuX*Uofx+cUQ+OPZKP&hQ?MAXHC6f3(mA8#}_l8Y0O5@RyKLThd zzSAO>B_+--j%C1y+Qr~~lVP`Sb9`vqzXRXp8tw#L{ZTj1a1S6am8jyy zY5DQ%_4u1v=OW+C&$I~cT-RNBFY9atp1|J}h>{}Q*pxrU|^`FBLlJ@Hk zRxOtVoXwBw>s>&M5cjoAmW20yjp1ToK@S!X+T6GZwY$bH+1U1(_+0x%l1Lu=}Z z**KGPd@VMIgo}ETSLI}h8xgQUpW4b;9AJ@QD4Ad?rG|~7YG&pUb);eJoW6!VFp4_cANhJQ}m&D_z_w-*kH-OM=p*T_lSyCxjZV7lCwle*!4g!H+ z9il>hLk3dKHpH@rxqL01-jZS4n*8#o18d!|tg@$#)1$oL=WD^nWtLe!sqp)0!8+>e zwp~TMbof+$=6ApG!-1p|?G@em5{Z4ed^VJxP+Hq6`Iwv$wW(0STL(4MJrx!_46pB9 zrgLW)<&Nk@u_m>Ag$i67A6u_+1j_-~ycrH$uk)z$N=;k}5<2`eL@rD0uZ8)47LUZc z$BTuL;YZV&+ni_by)k_(y%<=3G!hh!*oB6-=Fk-4UUfB6oMZKp@O>`IyY0fS<=RVX z`ab-UQ1TpOxux|D3s7aNbRgp^`{OuCNiZ)P!uS?A2wKn8aP&IN5W;a|@ zFeT2tWT`|9XrLX>JnQ&P(v@c40;UANeE-$DVnU*#C3TwIXFEf4krJR_91Ew7z!6%| zF#vvaBc>X^z@%uq6*7@hLIvh%E0dDy&fzlstHAHfO6{$cf=cL1%1+ZaxX$jao;KA! zCTe2<2=-f(2+e(lWT47`$QM=Ebs2W$2wi}#@~R4Kyjx88m$18_0?+AFZz_;^qB}Ky zIDTl)qxp)U$H&`>{q<#!@W-F&dXig-_Dh7z*EsE^O^?-B8#_Z6Tu~g}5W5(C2aMFn zb)VcIV>%SZn_-t8SzH@jN(}u2Lj(+Y7i2CSrF`%t0V+(I(k)$h+m%_>6>2_eX{SOg zGbc!fv#h+`j1;MQf!uR)=x2Q-*Z`J6G&sBpub8AW*D7*x@wLN+xx=fbqh{WqKn=?~ zZG^k$d5S~jMOVkVO_%f2X*cIhvZM~&A2(NJ2_J7e_;5o+zf#EJo%2PF7f%+IF@9b& zw0A-0QZ%Lh5`5k}3GUM1pAEK{>PqmwDgN?q_BlJ)=K)vg4M4%zvg;x^BR@4;zq}gW zE$O{a`eHi%_%$~v#6l{tQlLR1w?T4dysk_lJOD&)ak06dzKXXUld`=!@Z3CqQ(8n* z$8X(M9`6;r_7+v36vr_g+zcUaM}?=4qdWH(g^4E!S{QZ;9?>GF{vFqNIw6!u?>+ zy2oCA1dn~0KxmVPtw}&d1cKE#Cg@;i+tg}Nl?uN~m#fA0j1Mvunb$Hi{%bC1KeDr; zTnGjMCq3Z??PS}UGHtsAcO{&T{blAsp9J_sT{G~Sgg6s;)!_MWMoZfEHmT4y%$Gkf z;@zC6z>pxEp&5o!D$aC=glJ8GC=Q^M^+0n`hN<<9va=?AQWki?SFXCVi8?02m3nscTD|_po}mlunOuPDeoU)I=dXsOgD{uZ^|lfu6X)| zl{CmZ1w7VklfYJ>6z{$irLbYD_y6XsbQMg30iVC@??|8DhT=>VGc3XeUGu}?SrouC z?WF^kBjM^yTjty661mQ+!+-aN8!jnRE2c%Dbl%T%uk##4xm+Hee^dD!QdQGZvS|vz zyszmW&-6z99B+VlHZwe3rDJgllNhF}z7(+YY23(j+9ED^jW4oa(L(xjo`2r_9F_-! zFJ}LH$JZ$J_TajhC3IZfh-!($=U&{Zn#BwxyP!2dtkfvwVfVW6R2|nXKwP$%?3nM% zfR2GiATRqfu-|4%i?(UtWcBuKOE}kK{xc$EpN6(64JL$?aprr5eoY=G8CLGQ@=gw% ze;^ehf2xl=Uom7aYGIfAnrnf9Csj!Ypt+gA!k6f=mr-T^DHq^VOTHP~=Qd1s(_IU? zLJs?yQ7kZvK2jG;f9*N4Zj8e#MC>sIV8FOz9I_)H3FiKiNdYk!$2YEn^kk`59xm}_ z79^iSH>z5MDkD@+)s#=wK$SmF>JAyN@2JByZmrMtl;6VYuUN9Yv;moXH1|xS#dHgZ6X| z&C#`p-r`XLo9QyyWs9+GQ{=fsolX?anpNT~SrP(UI_F8rm!rGkDz=56Nzk~w2l75M zDKI*?;OmW!0?5R-XHWZ94n3TU&v#Mfbyu;s)_sH^{A(SNsZ?&N&z7t_8ZY%aN7oyG zU;9$hA!4F;+|J5;DXHs`YJakNjZY6Y3*uJYLh#&h+OTaNrG%5R+Erjb)VBTIRej;`sDPE+S09@)GE^NZRFbrWXht+U>xU6 z!{pP{H#X9u(sVDf=#tzj8=^ z#`M=_yOAEKR{UD4jS;!DFaxNKsne7ltOAkHUf3@U&GFzPx17_70ieD*%hUa+1fP>w zh9ew(R&QpC3p#uGg(%{=_#@z>?{M7*Fqa<|>Gp&8YuO-}(baG48FO(F<{QO3pXWLB zeSHZTD27>TyjDvxE;xi1SKXMBL*>)Hygm`r;Zb)n0gv=ewA~v!ZM0jdG7%xj0rNEw@)@o#j?R7kfW!rx Yq;SvdMtd^;_X{3CQc -/// This is a placeholder class for the AutoFixture.TUnit library. -/// -public class Class1 -{ - /// - /// Initializes a new instance of the class. - /// - public Class1() - { - } -} diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs new file mode 100644 index 0000000..3da73ca --- /dev/null +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -0,0 +1,104 @@ +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// Provides a data source for a data theory, with the data coming from a class + /// which must implement IEnumerable<object?[]>, + /// combined with auto-generated data specimens generated by AutoFixture. + /// + [CLSCompliant(false)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// The type of the class that provides the data. + /// The parameters passed to the data provider class constructor. + public ClassAutoDataAttribute(Type sourceType, params object[] parameters) + : this(() => new Fixture(), sourceType, parameters) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory that provides missing data from . + /// The type of the class that provides the data. + /// The parameters passed to the data provider class constructor. + /// + /// This constructor overload exists to enable a derived attribute to + /// supply a custom fixture factory that again may contain custom behavior. + /// + /// + /// In the following example MyTestData is a class that provides test data, + /// that would be complicated or probably impossible to provide using other options. + /// The missing arguments for the test are being supplied from the Fixture instance. + /// + /// [Theory] + /// [CustomAutoClassData(typeof(MyTestData))] + /// public void ClassDataSuppliesExtraValues(int sum, int[] numbers, Person client) + /// { + /// var actual = numbers.Sum(x => x); + /// + /// Assert.Equal(sum, actual); + /// Assert.NotNull(client); + /// } + /// + /// private class CustomAutoClassData : ClassAutoDataAttribute + /// { + /// public CustomAutoClassData(Type sourceType) : + /// base(() => new Fixture(), sourceType) + /// { + /// } + /// } + /// + /// private class MyTestData : IEnumerable<object[]> + /// { + /// public IEnumerator<object[]> GetEnumerator() + /// { + /// yield return new object[] { 0, new int[0] }; + /// yield return new object[] { 4, new int[] { 1, 2, 1} }; + /// yield return new object[] { 23, new int [] { 0, 13, 15, -5 } }; + /// } + /// + /// IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + /// } + /// + /// + protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); + this.Parameters = parameters ?? new object[] { null }; + } + + /// + /// Gets the fixture factory that provides the missing data from . + /// + public Func FixtureFactory { get; } + + /// + /// Gets the type of the class that provides the data. + /// + public Type SourceType { get; } + + /// + /// Gets the constructor parameters for . + /// + public object[] Parameters { get; } + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var source = new AutoDataSource( + this.FixtureFactory, + new ClassDataSource(this.SourceType, this.Parameters)); + + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + } + } +} diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs new file mode 100644 index 0000000..b04d3a1 --- /dev/null +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -0,0 +1,56 @@ +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// An implementation of DataAttribute that composes other DataAttribute instances. + /// + [CLSCompliant(false)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class CompositeDataAttribute : AutoFixtureDataSourceAttribute + { + private readonly AutoFixtureDataSourceAttribute[] attributes; + + /// + /// Initializes a new instance of the class. + /// + /// The attributes representing a data source for a data theory. + public CompositeDataAttribute(IEnumerable attributes) + : this(attributes as AutoFixtureDataSourceAttribute[] ?? attributes.ToArray()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The attributes representing a data source for a data theory. + public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) + { + this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); + } + + /// + /// Gets the attributes supplied through one of the constructors. + /// + public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); + + /// + public override IEnumerable GetData(DataGeneratorMetadata metadata) + { + if (metadata is null) throw new ArgumentNullException(nameof(metadata)); + + var results = this.attributes + .Select(attr => attr.GenerateDataSources(metadata)) + .ToArray(); + + var theoryRows = results + .Select(x => x.Select(y => y())) + .Zip(dataSets => dataSets.Collapse().ToArray()) + .ToArray(); + + return theoryRows; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/CustomizeAttribute.cs b/src/AutoFixture.TUnit/CustomizeAttribute.cs new file mode 100644 index 0000000..2e78b63 --- /dev/null +++ b/src/AutoFixture.TUnit/CustomizeAttribute.cs @@ -0,0 +1,19 @@ +using System.Reflection; + +namespace AutoFixture.TUnit +{ + /// + /// Base class for customizing parameters in methods decorated with + /// . + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] + public abstract class CustomizeAttribute : Attribute, IParameterCustomizationSource + { + /// + /// Gets a customization for a parameter. + /// + /// The parameter for which the customization is requested. + /// A customization for the parameter. + public abstract ICustomization GetCustomization(ParameterInfo parameter); + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Extensions/DataGeneratorMetadataExtensions.cs b/src/AutoFixture.TUnit/Extensions/DataGeneratorMetadataExtensions.cs new file mode 100644 index 0000000..82a51e0 --- /dev/null +++ b/src/AutoFixture.TUnit/Extensions/DataGeneratorMetadataExtensions.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using TUnit.Core.Enums; + +namespace AutoFixture.TUnit.Extensions; + +internal static class DataGeneratorMetadataExtensions +{ + public static MethodBase GetMethod(this DataGeneratorMetadata dataGeneratorMetadata) + { + if (dataGeneratorMetadata.Type == DataGeneratorType.ClassParameters) + { + return dataGeneratorMetadata.TestClassType.GetConstructors().First(); + } + + return dataGeneratorMetadata.TestInformation.ReflectionInformation; + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/FavorArraysAttribute.cs b/src/AutoFixture.TUnit/FavorArraysAttribute.cs new file mode 100644 index 0000000..bf0173b --- /dev/null +++ b/src/AutoFixture.TUnit/FavorArraysAttribute.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be created using a constructor with one + /// or more array arguments, if applicable. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class FavorArraysAttribute : CustomizeAttribute + { + /// + /// Gets a customization that associates a with + /// the of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + return new ConstructorCustomization(parameter.ParameterType, new ArrayFavoringConstructorQuery()); + } + } +} diff --git a/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs b/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs new file mode 100644 index 0000000..bf402ae --- /dev/null +++ b/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be created using a constructor with one + /// or more arguments, if applicable. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class FavorEnumerablesAttribute : CustomizeAttribute + { + /// + /// Gets a customization that associates a + /// with the of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with + /// the of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter == null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + return new ConstructorCustomization(parameter.ParameterType, new EnumerableFavoringConstructorQuery()); + } + } +} diff --git a/src/AutoFixture.TUnit/FavorListsAttribute.cs b/src/AutoFixture.TUnit/FavorListsAttribute.cs new file mode 100644 index 0000000..1eeb80b --- /dev/null +++ b/src/AutoFixture.TUnit/FavorListsAttribute.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be created using a constructor with one + /// or more arguments, if applicable. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class FavorListsAttribute : CustomizeAttribute + { + /// + /// Gets a customization that associates a with + /// the of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter == null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + return new ConstructorCustomization(parameter.ParameterType, new ListFavoringConstructorQuery()); + } + } +} diff --git a/src/AutoFixture.TUnit/FrozenAttribute.cs b/src/AutoFixture.TUnit/FrozenAttribute.cs new file mode 100644 index 0000000..aa20907 --- /dev/null +++ b/src/AutoFixture.TUnit/FrozenAttribute.cs @@ -0,0 +1,73 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be frozen so that the same instance is + /// returned every time the creates an instance of that type. + /// + [AttributeUsage(AttributeTargets.Parameter)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class FrozenAttribute : CustomizeAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The criteria used to determine + /// which requests will be satisfied by the frozen parameter value + /// is . + /// + public FrozenAttribute() + : this(Matching.ExactType) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The criteria used to determine + /// which requests will be satisfied by the frozen parameter value. + /// + public FrozenAttribute(Matching by) + { + this.By = by; + } + + /// + /// Gets the criteria used to determine + /// which requests will be satisfied by the frozen parameter value. + /// + public Matching By { get; } + + /// + /// Gets a configured + /// to match requests based on the and optionally + /// the name of the parameter. + /// + /// + /// The parameter for which the customization is requested. + /// + /// + /// A configured + /// to match requests based on the and optionally + /// the name of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); + + return new FreezeOnMatchCustomization(parameter, matcher); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/GreedyAttribute.cs b/src/AutoFixture.TUnit/GreedyAttribute.cs new file mode 100644 index 0000000..bea3562 --- /dev/null +++ b/src/AutoFixture.TUnit/GreedyAttribute.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be created using the most greedy + /// constructor that can be satisfied by an . + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class GreedyAttribute : CustomizeAttribute + { + /// + /// Gets a customization that associates a with the + /// of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + return new ConstructorCustomization(parameter.ParameterType, new GreedyConstructorQuery()); + } + } +} diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs new file mode 100644 index 0000000..4776251 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -0,0 +1,17 @@ +namespace AutoFixture.TUnit.Internal +{ + internal class Argument + { + public Argument(TestParameter parameter, object value) + { + this.Parameter = parameter ?? throw new ArgumentNullException(nameof(parameter)); + this.Value = value; + } + + public TestParameter Parameter { get; } + + public object Value { get; } + + public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs new file mode 100644 index 0000000..eb94706 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -0,0 +1,94 @@ +#nullable enable +using AutoFixture.TUnit.Extensions; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Combines the values from a source with auto-generated values. + /// + public class AutoDataSource : DataSource + { + /// + /// Initializes a new instance of the class. + /// + /// The factory method for creating a fixture. + /// The source of test data to combine with auto-generated values. + /// + /// Thrown when is . + /// + public AutoDataSource(Func createFixture, IDataSource? source = default) + { + this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); + this.Source = source; + } + + /// + /// Gets the factory method for creating a fixture. + /// + public Func CreateFixture { get; } + + /// + /// Gets the source of test data to combine with auto-generated values. + /// + public IDataSource? Source { get; } + + /// + /// Returns the combined test data provided by the source and auto-generated values. + /// + /// The target method for which to provide the arguments. + /// Returns a sequence of argument collections. + public override IEnumerable GetData(DataGeneratorMetadata metadata) + { + return this.Source is null + ? this.GenerateValues(metadata) + : this.CombineValues(metadata, this.Source); + } + + private IEnumerable GenerateValues(DataGeneratorMetadata metadata) + { + var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); + var fixture = this.CreateFixture(); + yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); + } + + private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDataSource source) + { + var method = metadata.GetMethod(); + + var parameters = Array.ConvertAll(method.GetParameters(), TestParameter.From); + + foreach (var testData in source.GetData(metadata)) + { + var customizations = parameters.Take(testData.Length) + .Zip(testData, (parameter, value) => new Argument(parameter, value)) + .Select(argument => argument.GetCustomization()) + .Where(x => x is not NullCustomization); + + var fixture = this.CreateFixture(); + + foreach (var customization in customizations) + { + fixture.Customize(customization); + } + + var missingValues = parameters.Skip(testData.Length) + .Select(parameter => GenerateAutoValue(parameter, fixture)) + .ToArray(); + + yield return testData.Concat(missingValues).ToArray(); + } + } + + private static object GenerateAutoValue(TestParameter parameter, IFixture fixture) + { + var customization = parameter.GetCustomization(); + + if (customization is not NullCustomization) + { + fixture.Customize(customization); + } + + return fixture.Resolve(parameter.ParameterInfo); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs new file mode 100644 index 0000000..90e0ad5 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -0,0 +1,49 @@ +using System.Diagnostics.CodeAnalysis; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Encapsulates the access to a test data source type. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] + public class ClassDataSource : DataSource + { + private readonly object[] parameters; + + /// + /// Creates an instance of type . + /// + /// The test data source type. + /// Constructor arguments for the source type. + /// Thrown when arguments are . + public ClassDataSource(Type type, params object[] parameters) + { + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + } + + /// + /// Gets the test data source type. + /// + public Type Type { get; } + + /// + /// Gets the constructor parameters for test data source type. + /// + public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); + + if (instance is not IEnumerable enumerable) + { + throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); + } + + return enumerable; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs b/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs new file mode 100644 index 0000000..ad39704 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs @@ -0,0 +1,10 @@ +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Internal +{ + internal static class CustomizationExtensions + { + public static object Resolve(this IFixture source, object request) + => new SpecimenContext(source).Resolve(request); + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs new file mode 100644 index 0000000..b196f12 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs @@ -0,0 +1,15 @@ +namespace AutoFixture.TUnit.Internal +{ + internal class CustomizeAttributeComparer : Comparer + { + public override int Compare(IParameterCustomizationSource x, IParameterCustomizationSource y) + { + return (x is FrozenAttribute, y is FrozenAttribute) switch + { + (true, false) => 1, + (false, true) => -1, + _ => 0 + }; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/DataSource.cs b/src/AutoFixture.TUnit/Internal/DataSource.cs new file mode 100644 index 0000000..85efa95 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/DataSource.cs @@ -0,0 +1,13 @@ +using System.Diagnostics.CodeAnalysis; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// The base class for test case sources. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "The type is not a collection.")] + [SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", + Justification = "The type is not a collection.")] + public abstract class DataSource : AutoFixtureDataSourceAttribute, IDataSource; +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs new file mode 100644 index 0000000..4d95409 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs @@ -0,0 +1,58 @@ +namespace AutoFixture.TUnit.Internal +{ + internal static class EnumerableExtensions + { + /// + /// Applies a specified function to the corresponding elements of any number of sequences. + /// + /// The type of the elements of the input sequences. + /// The type of the elements of the result sequence. + /// The input sequences. + /// A function that specifies how to combine the corresponding elements of the sequences. + /// An that contains elements of the input sequences, combined by resultSelector. + internal static IEnumerable Zip(this IEnumerable> sequences, + Func, TResult> resultSelector) + { + var enumerators = sequences.Select(s => s.GetEnumerator()).ToList(); + while (enumerators.TrueForAll(e => e.MoveNext())) + { + yield return resultSelector(enumerators.Select(e => e.Current)); + } + } + + /// + /// Collapses a series of sequences down by using items from the first sequence until it finishes, + /// then continuing from the same index through the second sequence, and so on until all sequences + /// have been exhausted. + /// + /// The type of the elements of the input sequences. + /// The input sequences. + /// Items from each sequence in turn, yielding those from the first sequence first. + internal static IEnumerable Collapse(this IEnumerable> sequences) + { + var position = 0; + foreach (var sequence in sequences) + { + foreach (var item in sequence.Skip(position)) + { + position++; + yield return item; + } + } + } + + /// + /// Casts the source sequence to an . + /// Enumerates the source sequence to an array if it is not an enumerated collection. + /// + /// The source sequence. + /// The sequence item type. + /// An that contains elements of the source sequence. + public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) + { + return source is not null + ? source as IReadOnlyCollection ?? source.ToArray() + : null; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs new file mode 100644 index 0000000..dff73b1 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs @@ -0,0 +1,48 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Encapsulates access to a field that provides test data. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] + public class FieldDataSource : DataSource + { + /// + /// Creates an instance of type . + /// + /// The source field info. + /// + /// Thrown when is . + /// + public FieldDataSource(FieldInfo fieldInfo) + { + this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); + } + + /// + /// Gets the source field. + /// + public FieldInfo FieldInfo { get; } + + /// + /// Gets the test data from the source field. + /// + /// Returns a sequence of argument collections. + /// + /// Thrown when the field does not return an enumerable value. + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.FieldInfo.GetValue(null); + if (value is not IEnumerable enumerable) + { + throw new InvalidCastException("Member does not return an enumerable value."); + } + + return enumerable; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs new file mode 100644 index 0000000..098f732 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -0,0 +1,26 @@ +#nullable enable +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Internal +{ + internal class FrozenValueCustomization : ICustomization + { + private readonly IRequestSpecification specification; + private readonly object? value; + + public FrozenValueCustomization(IRequestSpecification specification, object? value) + { + this.specification = specification ?? throw new ArgumentNullException(nameof(specification)); + this.value = value; + } + + public void Customize(IFixture fixture) + { + var builder = new FilteringSpecimenBuilder( + builder: new FixedBuilder(this.value), + specification: this.specification); + + fixture.Customizations.Insert(0, builder); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/IDataSource.cs b/src/AutoFixture.TUnit/Internal/IDataSource.cs new file mode 100644 index 0000000..32ee2ac --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/IDataSource.cs @@ -0,0 +1,15 @@ +namespace AutoFixture.TUnit.Internal +{ + /// + /// Exposes the factory method for a sequence of test data. + /// + public interface IDataSource + { + /// + /// Returns the test data provided by the source. + /// + /// The target method for which to provide the arguments. + /// Returns a sequence of argument collections. + IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs new file mode 100644 index 0000000..de305ce --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -0,0 +1,49 @@ +using System.Diagnostics.CodeAnalysis; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Provides test data from a predefined collection of values. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] + public sealed class InlineDataSource : AutoFixtureDataSourceAttribute + { + private readonly object[] values; + + /// + /// Creates an instance of type . + /// + /// The collection of inline values. + /// + /// Thrown when the values collection is . + /// + public InlineDataSource(object[] values) + { + this.values = values ?? throw new ArgumentNullException(nameof(values)); + } + + /// + /// The collection of inline values. + /// + public IReadOnlyList Values => Array.AsReadOnly(this.values); + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + if (dataGeneratorMetadata is null) + { + throw new ArgumentNullException(nameof(dataGeneratorMetadata)); + } + + var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; + if (this.values.Length > membersToGenerate.Length) + { + throw new InvalidOperationException( + "The number of arguments provided exceeds the number of parameters."); + } + + yield return this.values; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs new file mode 100644 index 0000000..bcbcb59 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -0,0 +1,90 @@ +#nullable enable +using System.Globalization; +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Encapsulates access to a member that provides test data. + /// + public class MemberDataSource : IDataSource + { + private readonly object[] arguments; + + /// + /// Creates an instance of type . + /// + /// The containing type of the member. + /// The name of the member. + /// The arguments provided to the member. + /// Thrown when arguments are . + public MemberDataSource(Type type, string name, params object[] arguments) + { + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.Name = name ?? throw new ArgumentNullException(nameof(name)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this.Source = this.GetTestDataSource(); + } + + /// + /// Gets the containing type of the member. + /// + public Type Type { get; } + + /// + /// Gets the name of the member. + /// + public string Name { get; } + + /// + /// Gets the arguments provided to the member. + /// + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + + /// + /// Gets the test data source. + /// + protected DataSource Source { get; } + + private DataSource GetTestDataSource() + { + var sourceMember = this.Type.GetMember(this.Name, + MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, + BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) + .FirstOrDefault(); + + if (sourceMember is null) + { + var message = string.Format( + CultureInfo.CurrentCulture, + "Could not find public static member (property, field, or method) named '{0}' on {1}", + this.Name, this.Type.FullName); + throw new ArgumentException(message); + } + + var returnType = sourceMember.GetReturnType(); + if (!typeof(IEnumerable).IsAssignableFrom(returnType)) + { + var message = string.Format( + CultureInfo.CurrentCulture, + "Member {0} on {1} does not return IEnumerable", + this.Name, this.Type.FullName); + throw new ArgumentException(message); + } + + return sourceMember switch + { + FieldInfo fieldInfo => new FieldDataSource(fieldInfo), + PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), + MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), + _ => throw new InvalidOperationException("Unsupported member type.") + }; + } + + /// + public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs new file mode 100644 index 0000000..973bea1 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -0,0 +1,48 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Encapsulates access to a method that provides test data. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] + public class MethodDataSource : DataSource + { + private readonly object[] arguments; + + /// + /// Creates an instance of type . + /// + /// The source method. + /// The source method arguments. + public MethodDataSource(MethodInfo methodInfo, params object[] arguments) + { + this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + } + + /// + /// Gets the source method info. + /// + public MethodInfo MethodInfo { get; } + + /// + /// Gets the source method arguments. + /// + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.MethodInfo.Invoke(null, this.arguments); + if (value is not IEnumerable enumerable) + { + throw new InvalidCastException("Member does not return an enumerable value."); + } + + return enumerable; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/NullCustomization.cs b/src/AutoFixture.TUnit/Internal/NullCustomization.cs new file mode 100644 index 0000000..0d5e1f1 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/NullCustomization.cs @@ -0,0 +1,20 @@ +namespace AutoFixture.TUnit.Internal +{ + internal sealed class NullCustomization : ICustomization + { + private NullCustomization() + { + // prevent external instantiation + } + + private static readonly Lazy LazyInstance = new( + () => new NullCustomization(), isThreadSafe: true); + + public static NullCustomization Instance => LazyInstance.Value; + + public void Customize(IFixture fixture) + { + // intentionally left blank + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs new file mode 100644 index 0000000..ecd68a8 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -0,0 +1,43 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Specification for identifying requests that match the test parameter by provided criteria. + /// + internal class ParameterFilter : IRequestSpecification + { + private readonly IRequestSpecification matcherSpecification; + + /// + /// Creates an instance of type . + /// + /// The parameter. + /// The flags specifying the matching criteria. + /// Thrown when is null. + public ParameterFilter(ParameterInfo parameterInfo, Matching flags) + { + this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + this.Flags = flags; + this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) + .SetFlags(this.Flags).Build(); + } + + /// + /// Gets the source parameter. + /// + public ParameterInfo ParameterInfo { get; } + + /// + /// Gets the matching flags. + /// + public Matching Flags { get; } + + /// + public bool IsSatisfiedBy(object request) + { + return this.matcherSpecification.IsSatisfiedBy(request); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs new file mode 100644 index 0000000..fd5e458 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -0,0 +1,199 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// A builder type that creates a instance, + /// for a instance, based on the builder's matching configuration. + /// + public class ParameterMatcherBuilder + { + private readonly ParameterInfo parameterInfo; + + /// + /// Creates an instance of type . + /// + /// The parameter info. + /// + /// Thrown when is . + /// + public ParameterMatcherBuilder(ParameterInfo parameterInfo) + { + this.parameterInfo = parameterInfo + ?? throw new ArgumentNullException(nameof(parameterInfo)); + } + + /// + /// Gets or sets a value indicating whether the exact parameter request should be matched. + /// Default is . + /// + public bool MatchExactRequest { get; set; } = true; + + /// + /// Gets or sets a value indicating whether the exact parameter type should be matched. + /// + public bool MatchExactType { get; set; } + + /// + /// Gets or sets a value indicating whether the direct base type should be matched. + /// + public bool MatchDirectBaseType { get; set; } + + /// + /// Gets or sets a value indicating whether the interfaces implemented + /// by the parameter type should be matched. + /// + public bool MatchImplementedInterfaces { get; set; } + + /// + /// Gets or sets a value indicating whether the parameter type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchParameter { get; set; } + + /// + /// Gets or sets a value indicating whether the property type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchProperty { get; set; } + + /// + /// Gets or sets a value indicating whether the field type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchField { get; set; } + + /// + /// Sets the matching flags. + /// + /// The matching flags. + /// The current instance. + public ParameterMatcherBuilder SetFlags(Matching flags) + { + this.MatchExactType = flags.HasFlag(Matching.ExactType); + this.MatchDirectBaseType = flags.HasFlag(Matching.DirectBaseType); + this.MatchImplementedInterfaces = flags.HasFlag(Matching.ImplementedInterfaces); + this.MatchParameter = flags.HasFlag(Matching.ParameterName); + this.MatchProperty = flags.HasFlag(Matching.PropertyName); + this.MatchField = flags.HasFlag(Matching.FieldName); + return this; + } + + /// + /// Builds the instance. + /// + /// + /// A new instance of , matching the configuration. + /// + public IRequestSpecification Build() + { + var specifications = new List(7); + if (this.MatchExactRequest) + { + specifications.Add(this.AsExactRequest()); + } + + if (this.MatchExactType) + { + specifications.Add(this.AsExactType()); + } + + if (this.MatchDirectBaseType) + { + specifications.Add(this.AsDirectBaseType()); + } + + if (this.MatchImplementedInterfaces) + { + specifications.Add(this.AsImplementedInterfaces()); + } + + if (this.MatchProperty) + { + specifications.Add(this.AsProperty()); + } + + if (this.MatchParameter) + { + specifications.Add(this.AsParameter()); + } + + if (this.MatchField) + { + specifications.Add(this.AsField()); + } + + return specifications.Count == 1 + ? specifications[0] + : new OrRequestSpecification(specifications); + } + + private IRequestSpecification AsExactRequest() + { + return new EqualRequestSpecification(this.parameterInfo); + } + + private IRequestSpecification AsExactType() + { + return new OrRequestSpecification( + new ExactTypeSpecification(this.parameterInfo.ParameterType), + new SeedRequestSpecification(this.parameterInfo.ParameterType)); + } + + private IRequestSpecification AsDirectBaseType() + { + return new AndRequestSpecification( + new InverseRequestSpecification( + new ExactTypeSpecification(this.parameterInfo.ParameterType)), + new DirectBaseTypeSpecification(this.parameterInfo.ParameterType)); + } + + private IRequestSpecification AsImplementedInterfaces() + { + return new AndRequestSpecification( + new InverseRequestSpecification( + new ExactTypeSpecification(this.parameterInfo.ParameterType)), + new ImplementedInterfaceSpecification(this.parameterInfo.ParameterType)); + } + + private IRequestSpecification AsParameter() + { + return new ParameterSpecification( + new ParameterTypeAndNameCriterion( + new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private IRequestSpecification AsProperty() + { + return new PropertySpecification( + new PropertyTypeAndNameCriterion( + new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private IRequestSpecification AsField() + { + return new FieldSpecification( + new FieldTypeAndNameCriterion( + new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private class DerivesFromTypeComparer : IEqualityComparer + { + public bool Equals(Type x, Type y) + { + return y switch + { + null when x is null => true, + null => false, + _ => y.GetTypeInfo().IsAssignableFrom(x) + }; + } + + public int GetHashCode(Type obj) => 0; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs new file mode 100644 index 0000000..ba5b7f0 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs @@ -0,0 +1,41 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + /// + /// Encapsulates access to a property that provides test data. + /// + [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] + public class PropertyDataSource : DataSource + { + /// + /// Creates an instance of type . + /// + /// + /// + public PropertyDataSource(PropertyInfo propertyInfo) + { + this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); + } + + /// + /// Gets the source property. + /// + public PropertyInfo PropertyInfo { get; } + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.PropertyInfo.GetValue(null); + + if (value is not IEnumerable enumerable) + { + throw new InvalidCastException("Member does not return an enumerable value."); + } + + return enumerable; + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs b/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs new file mode 100644 index 0000000..fb6436a --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs @@ -0,0 +1,23 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + internal static class ReflectionExtensions + { + public static Type GetReturnType(this MemberInfo member) + { + if (member is null) + { + throw new ArgumentNullException(nameof(member)); + } + + return member switch + { + MethodInfo methodInfo => methodInfo.ReturnType, + PropertyInfo propertyInfo => propertyInfo.PropertyType, + FieldInfo fieldInfo => fieldInfo.FieldType, + _ => throw new ArgumentException("Member is not a method, property, or field.", nameof(member)) + }; + } + } +} diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs new file mode 100644 index 0000000..4dd8e08 --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -0,0 +1,57 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Internal +{ + internal class TestParameter + { + private readonly Lazy lazyCustomization; + private readonly Lazy lazyFrozenAttribute; + + public TestParameter(ParameterInfo parameterInfo) + { + this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + + this.lazyCustomization = new Lazy( + () => GetCustomization(parameterInfo)); + this.lazyFrozenAttribute = new Lazy( + () => parameterInfo.GetCustomAttributes() + .OfType().FirstOrDefault()); + } + + public ParameterInfo ParameterInfo { get; } + + public ICustomization GetCustomization() => this.lazyCustomization.Value; + + public ICustomization GetCustomization(object value) + { + var frozenAttribute = this.lazyFrozenAttribute.Value; + + if (frozenAttribute is null) + { + return NullCustomization.Instance; + } + + return new FrozenValueCustomization( + new ParameterFilter(this.ParameterInfo, frozenAttribute.By), + value); + } + + private static ICustomization GetCustomization(ParameterInfo parameter) + { + var customizations = parameter.GetCustomAttributes() + .OfType() + .OrderBy(x => x, new CustomizeAttributeComparer()) + .Select(x => x.GetCustomization(parameter)) + .ToArray(); + + return customizations switch + { + { Length: 0 } => NullCustomization.Instance, + { Length: 1 } => customizations[0], + _ => new CompositeCustomization(customizations), + }; + } + + public static TestParameter From(ParameterInfo parameterInfo) => new(parameterInfo); + } +} diff --git a/src/AutoFixture.TUnit/Internal/ValueTaskExtensions.cs b/src/AutoFixture.TUnit/Internal/ValueTaskExtensions.cs new file mode 100644 index 0000000..4c5aeec --- /dev/null +++ b/src/AutoFixture.TUnit/Internal/ValueTaskExtensions.cs @@ -0,0 +1,20 @@ +namespace AutoFixture.TUnit.Internal; + +internal static class ValueTaskExtensions +{ + /// + /// Wraps the value in a . + /// + /// The value to be wrapped. + /// The generic type of the value task. + /// Returns a completed instance. + public static ValueTask ToValueTask(this T value) => new(value); + + /// + /// Wraps the task in a . + /// + /// The task to be wrapped. + /// The generic type of the value task. + /// Returns a instance. + public static ValueTask ToValueTask(this Task task) => new(task); +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Matching.cs b/src/AutoFixture.TUnit/Matching.cs new file mode 100644 index 0000000..c31bc9d --- /dev/null +++ b/src/AutoFixture.TUnit/Matching.cs @@ -0,0 +1,62 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +namespace AutoFixture.TUnit +{ + /// + /// The criteria used to determine which requests will be satisfied + /// by the frozen specimen created for a parameter + /// decorated with the attribute. + /// + [SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames", + Justification = "This enumeration is designed to be used together with an attribute and is named to improve readability.")] + [Flags] + public enum Matching + { + /// + /// Matches requests for the exact same + /// as the type of the parameter. + /// + ExactType = 1, + + /// + /// Matches requests for a that is + /// a direct base of the type of the parameter. + /// + DirectBaseType = 2, + + /// + /// Matches requests for an interface that is + /// implemented by the type of the parameter. + /// + ImplementedInterfaces = 4, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + ParameterName = 8, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + PropertyName = 16, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + FieldName = 32, + + /// + /// Matches requests for a parameter, property or field whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + MemberName = ParameterName | PropertyName | FieldName + } +} diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs new file mode 100644 index 0000000..c87a941 --- /dev/null +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -0,0 +1,109 @@ +#nullable enable +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Extensions; +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit +{ + /// + /// Provides a data source for a data theory, with the data coming from one of the following sources + /// and combined with auto-generated data specimens generated by AutoFixture: + /// 1. A static property + /// 2. A static field + /// 3. A static method (with parameters) + /// The member must return something compatible with IEnumerable<object[]> with the test data. + /// + [CLSCompliant(false)] + [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] + public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + public MemberAutoDataAttribute(string memberName, params object[] parameters) + : this(() => new Fixture(), memberType: null, memberName, parameters) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The type declaring the source member. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + public MemberAutoDataAttribute(Type? memberType, string memberName, params object[] parameters) + : this(() => new Fixture(), memberType, memberName, parameters) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory delegate. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + protected MemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) + : this(fixtureFactory, memberType: null, memberName, parameters) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory delegate. + /// The type declaring the source member. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + /// Thrown when arguments are null. + protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); + this.Parameters = parameters ?? new object[] { null! }; + this.MemberType = memberType; + } + + /// + /// Gets the fixture factory that provides the missing data from . + /// + public Func FixtureFactory { get; } + + /// + /// Gets the type of the class that provides the data. + /// + public Type? MemberType { get; } + + /// + /// Gets the member name. + /// + public string MemberName { get; } + + /// + /// Gets the parameters passed to the member. Only supported for static methods. + /// + public object[] Parameters { get; } + + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var testMethod = dataGeneratorMetadata.GetMethod(); + + if (testMethod is null) + { + throw new ArgumentNullException(nameof(testMethod)); + } + + var sourceType = this.MemberType ?? testMethod.DeclaringType + ?? throw new InvalidOperationException("Source type cannot be null."); + + var source = new AutoDataSource( + createFixture: this.FixtureFactory, + source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); + + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + } + } +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/ModestAttribute.cs b/src/AutoFixture.TUnit/ModestAttribute.cs new file mode 100644 index 0000000..c7206ce --- /dev/null +++ b/src/AutoFixture.TUnit/ModestAttribute.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should be created using the most modest + /// constructor that can be satisfied by an . + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class ModestAttribute : CustomizeAttribute + { + /// + /// Gets a customization that associates a with the + /// of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + return new ConstructorCustomization(parameter.ParameterType, new ModestConstructorQuery()); + } + } +} diff --git a/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs b/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs new file mode 100644 index 0000000..1906c51 --- /dev/null +++ b/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs @@ -0,0 +1,34 @@ +using System.Reflection; + +namespace AutoFixture.TUnit +{ + /// + /// An attribute that can be applied to parameters in an -driven + /// Theory to indicate that the parameter value should not have properties auto populated + /// when the creates an instance of that type. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class NoAutoPropertiesAttribute : CustomizeAttribute + { + /// + /// Gets a customization that stops auto population of properties for the type of the parameter. + /// + /// The parameter for which the customization is requested. + /// + /// A customization that stops auto population of the of the parameter. + /// + /// + /// is null. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + var targetType = parameter.ParameterType; + return new NoAutoPropertiesCustomization(targetType); + } + } +} diff --git a/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs new file mode 100644 index 0000000..5aa8835 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs @@ -0,0 +1,168 @@ +using System.Reflection; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests; + +public class ArgumentsAutoDataAttributeTests +{ + [Test] + public async Task SutIsDataAttribute() + { + // Arrange & Act + var sut = new ArgumentsAutoDataAttribute(); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ValuesWillBeEmptyWhenSutIsCreatedWithDefaultConstructor() + { + // Arrange + var sut = new ArgumentsAutoDataAttribute(); + var expected = Enumerable.Empty(); + + // Act + var result = sut.Values; + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + [Test] + public async Task ValuesWillNotBeEmptyWhenSutIsCreatedWithConstructorArguments() + { + // Arrange + var expectedValues = new[] { new object(), new object(), new object() }; + var sut = new ArgumentsAutoDataAttribute(expectedValues); + + // Act + var result = sut.Values; + + // Assert + await Assert.That(result).IsEquivalentTo(expectedValues); + } + + [Test] + public async Task ValuesAreCorrectWhenConstructedWithExplicitAutoDataAttribute() + { + // Arrange + var expectedValues = new[] { new object(), new object(), new object() }; + var sut = new DerivedArgumentsAutoDataAttribute(() => new DelegatingFixture(), expectedValues); + + // Act + var result = sut.Values; + + // Assert + await Assert.That(result).IsEqualTo(expectedValues); + } + + [Test] + public async Task DoesntActivateFixtureImmediately() + { + // Arrange + var wasInvoked = false; + + // Act + _ = new DerivedArgumentsAutoDataAttribute(() => + { + wasInvoked = true; + return new DelegatingFixture(); + }); + + // Assert + await Assert.That(wasInvoked).IsFalse(); + } + + [Test] + [Arguments("CreateWithFrozenAndFavorArrays")] + [Arguments("CreateWithFavorArraysAndFrozen")] + [Arguments("CreateWithFrozenAndFavorEnumerables")] + [Arguments("CreateWithFavorEnumerablesAndFrozen")] + [Arguments("CreateWithFrozenAndFavorLists")] + [Arguments("CreateWithFavorListsAndFrozen")] + [Arguments("CreateWithFrozenAndGreedy")] + [Arguments("CreateWithGreedyAndFrozen")] + [Arguments("CreateWithFrozenAndModest")] + [Arguments("CreateWithModestAndFrozen")] + [Arguments("CreateWithFrozenAndNoAutoProperties")] + [Arguments("CreateWithNoAutoPropertiesAndFrozen")] + public async Task GetDataOrdersCustomizationAttributes(string methodName) + { + // Arrange + var customizationLog = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizationLog.Add(c) + }; + var sut = new DerivedArgumentsAutoDataAttribute(() => fixture); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(typeof(TypeWithCustomizationAttributes), methodName)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(customizationLog[0]).IsAssignableTo(); + + var composite = (CompositeCustomization)customizationLog[0]; + + await Assert.That(composite.Customizations.First()).IsNotTypeOf(); + await Assert.That(composite.Customizations.Last()).IsAssignableTo(); + } + + [Test] + [MethodDataSource(typeof(InlinePrimitiveValuesTestData), nameof(InlinePrimitiveValuesTestData.GetData))] + [MethodDataSource(typeof(InlineFrozenValuesTestData), nameof(InlineFrozenValuesTestData.GetData))] + public async Task ReturnsSingleTestDataWithExpectedValues(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, + object[] expected) + { + // Act + var actual = attribute.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod.DeclaringType, testMethod.Name)).ToArray(); + + // Assert + await Assert.That(actual).HasSingleItem(); + await Assert.That(actual[0]).IsEquivalentTo(expected); + } + + [Test] + [ArgumentsAutoData] + public async Task GeneratesRandomData(int a, float b, string c, decimal d) + { + await Assert.That(a).IsNotEqualTo(0); + await Assert.That(b).IsNotEqualTo(0); + await Assert.That(c).IsNotNull(); + await Assert.That(d).IsNotEqualTo(0); + } + + [Test] + [ArgumentsAutoData(12, 32.1f, "hello", 71.231d)] + public async Task InlinesAllData(int a, float b, string c, decimal d) + { + await Assert.That(a).IsEqualTo(12); + await Assert.That(b).IsEqualTo(32.1f); + await Assert.That(c).IsEqualTo("hello"); + await Assert.That(d).IsEqualTo(71.231m); + } + + [Test] + [ArgumentsAutoData(0)] + [ArgumentsAutoData(5)] + [ArgumentsAutoData(-12)] + [ArgumentsAutoData(21.3f)] + [ArgumentsAutoData(18.7d)] + [ArgumentsAutoData(EnumType.First)] + [ArgumentsAutoData("Hello World")] + [ArgumentsAutoData("\t\r\n")] + [ArgumentsAutoData(" ")] + [ArgumentsAutoData("")] + [ArgumentsAutoData([null])] + public async Task InjectsInlineValues([Frozen] object a, + [Frozen] PropertyHolder value, + PropertyHolder frozen) + { + await Assert.That(value.Property).IsEqualTo(a); + await Assert.That(value).IsSameReferenceAs(frozen); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs new file mode 100644 index 0000000..faa2db0 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs @@ -0,0 +1,178 @@ +using AutoFixture.Kernel; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class AutoDataAttributeTest +{ + [Test] + public async Task SutIsDataAttribute() + { + // Arrange & Act + var sut = new AutoDataAttribute(); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task InitializedWithDefaultConstructorHasCorrectFixture() + { + // Arrange + var sut = new AutoDataAttribute(); + + // Act + var result = sut.FixtureFactory(); + + // Assert + await Assert.That(result).IsAssignableTo(); + } + + [Test] + public async Task InitializedWithFixtureFactoryConstructorHasCorrectFixture() + { + // Arrange + var fixture = new Fixture(); + + // Act + var sut = new DerivedAutoDataAttribute(() => fixture); + + // Assert + await Assert.That(sut.FixtureFactory()).IsSameReferenceAs(fixture); + } + + [Test] + public async Task InitializeWithNullFixtureFactoryThrows() + { + // Arrange + // Act & Assert + await Assert.That(() => + new DerivedAutoDataAttribute(null)).ThrowsExactly(); + } + + [Test] + public async Task DoesntActivateFixtureImmediately() + { + // Arrange + var wasInvoked = false; + + // Act + _ = new DerivedAutoDataAttribute(() => + { + wasInvoked = true; + return null; + }); + + // Assert + await Assert.That(wasInvoked).IsFalse(); + } + + [Test] + public async Task GetDataWithNullMethodThrows() + { + // Arrange + var sut = new AutoDataAttribute(); + + // Act & assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null!, null!))).ThrowsException(); + } + + [Test] + public async Task GetDataReturnsCorrectResult() + { + // Arrange + var method = typeof(TypeWithOverloadedMembers) + .GetMethod("DoSomething", [typeof(object)]); + var parameters = method!.GetParameters(); + var expectedResult = new object(); + + object actualParameter = null; + ISpecimenContext actualContext = null; + var builder = new DelegatingSpecimenBuilder + { + OnCreate = (r, c) => + { + actualParameter = r; + actualContext = c; + return expectedResult; + } + }; + var composer = new DelegatingFixture { OnCreate = builder.OnCreate }; + var sut = new DerivedAutoDataAttribute(() => composer); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(actualContext).IsNotNull(); + await Assert.That(parameters).HasSingleItem(); + await Assert.That(actualParameter).IsEqualTo(parameters[0]); + await Assert.That(result.Single()).IsEquivalentTo(new[] { expectedResult }); + } + + [Test] + [Arguments("CreateWithFrozenAndFavorArrays")] + [Arguments("CreateWithFavorArraysAndFrozen")] + [Arguments("CreateWithFrozenAndFavorEnumerables")] + [Arguments("CreateWithFavorEnumerablesAndFrozen")] + [Arguments("CreateWithFrozenAndFavorLists")] + [Arguments("CreateWithFavorListsAndFrozen")] + [Arguments("CreateWithFrozenAndGreedy")] + [Arguments("CreateWithGreedyAndFrozen")] + [Arguments("CreateWithFrozenAndModest")] + [Arguments("CreateWithModestAndFrozen")] + [Arguments("CreateWithFrozenAndNoAutoProperties")] + [Arguments("CreateWithNoAutoPropertiesAndFrozen")] + public async Task GetDataOrdersCustomizationAttributes(string methodName) + { + // Arrange + var method = typeof(TypeWithCustomizationAttributes) + .GetMethod(methodName, [typeof(ConcreteType)]); + var customizationLog = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizationLog.Add(c) + }; + var sut = new DerivedAutoDataAttribute(() => fixture); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method.DeclaringType, method.Name)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(customizationLog[0]).IsAssignableTo(); + + var composite = (CompositeCustomization)customizationLog[0]; + + await Assert.That(composite.Customizations.First()).IsNotTypeOf(); + await Assert.That(composite.Customizations.Last()).IsAssignableTo(); + } + + [Test] + public async Task ShouldRecognizeAttributesImplementingIParameterCustomizationSource() + { + // Arrange + var method = typeof(TypeWithIParameterCustomizationSourceUsage) + .GetMethod(nameof(TypeWithIParameterCustomizationSourceUsage.DecoratedMethod)); + + var customizationLog = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizationLog.Add(c) + }; + var sut = new DerivedAutoDataAttribute(() => fixture); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method.DeclaringType, method.Name)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(customizationLog[0]).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj b/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj index d8bc53f..9f192d3 100644 --- a/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj +++ b/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj @@ -26,6 +26,7 @@ + diff --git a/tests/AutoFixture.TUnit.Tests/AutoFixtureLogo200x200.png b/tests/AutoFixture.TUnit.Tests/AutoFixtureLogo200x200.png new file mode 100644 index 0000000000000000000000000000000000000000..32a82c5d19774c5ae7c44b9b37ccb569c4a049cc GIT binary patch literal 14319 zcmaL8b97$uvp1T?wrw=F%_p|)CuU>Ywi}yG8l%Azvq@vyc5~D7p5J-zANSn7*5;b| z4EJ}>nprzaSy37Z9v>bI3=9b%Bcb|v2L0P%p+Aqc+I9J#CpdQm4&K>iMf~asD%I+7z8O$UE57tL7vad(VofV9}SbIz0)T*7?^;tr;~}9 zt%Vz@sf88LL6H2ivzMF{Xf8;u#i_ue;3RHg4V3YAu~73?R5$asHRClW7ZxHF@Z|dh zu(xnCA@#Jkb8zMJ6eRyIT)xlie~+2TN&kz)%~p{7|0t!cpiC<6=wd<2$;85F#=^xy z%EijW%Fe;f&CNi{#=^?N%)-XZ%Erjb&BxBh$HGGT-y8X-G#7JAK2-^+|CaT6CrEDX z=H|r5%%*xBl`wxSSjq#I$(bdbr&BT+@!Ik1a2oe^qW-dS{H=v^f z=|4mhQ%836YD-+8pJUM|T&q&%jwy{1fHGC+=cl;^ye0?&xUuA1^9fJGwc#T01(C zimP#wY5^V09X(wCi&{Z}58&YHX5wIG0gw z_N4!1Fdy)L*G2q)#rtnw^Z#8JiT{Ee0on*-E-y44{pIiBW*)yT6h$G(2z^Eh`a&~O9dL{?5;46Yut@+ zhj2E1co`cC%0d--bwDifL<-Z{F6uW=OSC92Q} z4Ihs`J_X&=-Iu?OGy<3o)z?3|JtADEeIK6A8@6vYyVE26b7aR#zY@=X>);^Xj2cP1 zev%Y$h#O(ve5-I=*T}Zc1yT{8?l>zAyg`DiWcp>j7X+aAL-)PioNXM)rJQWSp3!ui z^*QX)c;T%GocMr`7Z~IlvFFe3A5KI1IT{}x9tV5+eoa5@+9kQKB^YyRCs0h}G5*kr z_v9TGwVBaN301&;4St>vfMJGsYl<45V%L1$)~_Bn8cMj`IegiDd|!MVL#5*folxz0 zSChEUW$ZeuXW>#^6H(%sF&<+8ktAMBrMxFD#HAz5+fttNyZCu_+o_6p6lji0 zCww#0s1AsONh5foxTmY=#n}?T?|cG?K6+RcV|%}ff2aHrG69qPg8?EaiTH@DZ4M22 zm+u5oG?teINX*+EOd2v^mkjcN6y4!;x48(mbm1F52!7f^Q2cWlJYbe;u8^3x{S|~; z14`sQ8XYnDDwaqnT)@yjP3Py)Kts>tLGt7ygcH!kq8PtAu1q_cPr7wlBkkbjBR>`j zbBGt9l(Z&D`WSf7#wm#b%&CZ|N+IpGyxsqGy^BS27Vu?^g?98%G*(m&;vtpn5ed%= z*AofBFk=b5>9YFzR)Z#eRAsJ#sH8v?dqMLeYpVh6Xw-JL<*YfVb?`9XW9JJF=Ds07 z{2MBIiTou`C_4195Bs<`Q$3lhia_wtp@V#H6b%aBaUg=fMn_Kx88DglkBC?mC8S(- zZ!4x#7F=)-mJvO+2JeixW7Mn3Ld4Mm4=)q_y5XD?`ZzwwrUBY9nW2x+$#S_v5H|(V zE(0DSiEtTkm;GlJobi5yw!YqoZWsE0L5N zV%%zAhpp>*_h(op3bbP#9y4q@YCoO&`+ckD%g?zDiE61G$g+0~+(Wx9b3;`2 zf>FPl^)e?qe$4M-d){5Lv_~ZxHXpNS7MLxOc$zfMF#=D&p&mu`OI9R)1#aVrO?tTf zB@&@Qo2MXJ%vNf}C$Z@yZ||l|sq5*bCt*r3nqpknn_IjkUAvZ%Pc~-SJfZ ze{aO-E^O`xRV@=r@CIw|73DP-*kzVz5A8F+#p+F<%*_^1-4>#4N@bRaUvxjSe2>)@&< z;N^Qfm#moqXp>q6o2Iz!p=P$c#7!J!mbtyt|68W4rG39sgY@BW8&@hPr)xnBN#{_} z?qf~hYS|5Y=nK)d`=@|=x}VKll&`pOeAZrvd!+YN&Lh3$g+DTg;G|-Uki5EaD@=Fo zRiMT=bNE!?a8vx?*?TP4ckI%hNwz<^bqHCkERFmH#AqfCP^aO7&RwIWO-bk(8AE8H za*(}bG|-vjGMftlcS45VB@~!Lc<46G_3?$Kte=|-!c^w_EPS3xo*y<>^;3hX?D^5h zfB2|wh3Xs;hlB-9re_|xjRnp25GT7D3E!h|;glK!R-J-z%@#4{vvKERBjCb&y`zIc z237xy3n zfK`|RrEUg*RSE?LXZv~-uPM$Y-RtszuVy);0tJ9eo_7>xrav82_RQ1jG>T05A zp;ggpbOST4wxaJ+R8ZCShu?bJGCu z#}0y9@sUo7@C6_u*mj#RZ6(S+qzAEBz45atd>IIX4v6tb6INtiSD%Y7ASFW@%SzNr z-Ntx&48>7FCez?nx#I^9g}DS;2|ceu`F4~Laf_}r!qFXLm86>Zq{Rde6V)^|!re9^ zmdo}(rZRm6j$Du~IEq;F${|75K3t6cG5uYxX-(ad?UN<`~E>A5rS3$Zf=dsl`yY%8cSB0BlN#Z(>xdVu#B0%T=WX5ro9o=zyXWTon>@!j zF9*Vhp%Fq{VdT-28eEAvx?}jL{^^2|Zp{aVeRgC~JJ$0#FPjzjS z$NWIXsoTF>KKU<7 zZsx0o?w{Nks&Qn-GsB743!=}LjMAl$N}8Qbe3e%)J&qCGMmjx|s2pYMvgUWXPb1nn zZLwZ1T?cO?YZU%=`jP$s&w(w{$cQ^3S-iu)Lif}CrvWJMD7+QA-w`M0#2fAlv8mHo zHbV5D73i?dDw1nBy&a6h$(>k~pYkW)1q)fe*&cr}d0$rQbz6|_|Fc*h`@>&iX)cfR z3ucxaQyPR7uIL``D`N69;v17Bw$6OH(sXH3TEBIN2>esXp4SdK|J-!RE*7%O-KR z+M6f6qj=+$md&h2pdU4?QIj&cK?P^7olKbWRjf=185DeLUvkpuaVD%yafphLI1hBS zd}^!GRiO(YNr~(hnTpkJ>_@PL1mzK0t>+_osr{+j+-tu7aYcW*nMQe|+@i%wA%QXO z3{F}xiBk{FmXF^w^VcrI#c3cB1Y^8X;Z2C7q?diLe0SWr+t9$|WY}Gzo-PYsAE`vN zD17@Iypb41g3Rm5w4is})3vwi9CpGm3iPC7)&p4gS{T1&aQ_w;q%KJ1B~T<>a*M);oTr4;g}K-f2el`_Vr@9DGP&@kv7g6J1+JL*jyhWbJW@6%mw3;qXc zjShA*c|N>wF}X*}HSQBnE%i@3y!&!uFkh>Pn6z*Vg2hlPbd2(nB3RZxNE#g6#n2^kt zG=hIIPSy@0jPeS9V*}9cjpjVG75k=Sdqp1B3N4lCY`hppPk}@ZBxJ*NZQB6Ey4!-r zvF(0mEX{&zZqsy>(2XNlFG`qdI9~TPhE+BH>p%x|xOQ zg7uUBA`$==pmnMU?;G#Di|P+KZs+8!5CKY~3EB3qqcO<2@-0aOELk zMUEbezqa)BB)&R0b)MEWJ%`2RX(l7U`yNZ$La-Ql z_JZYF*Eu~WllzvY{StD?jWo+km1znkr0nFG9yL^+Y6D%W>CZx-0JXUY)ha|uCb1hv zm>E&vJ9bsdinN6Gg?e;j6i#)YbK^^Ed(m*jMmrPH>-ORM`=7L6$5@h1voBD%;jL}? zurZ0$Alzir{u^Kq76fiEnS8(UL9kuMd6Dl3X_xhkazJALUS6@f-L!!sg%*6zo!aXq zp8=$1jIW`P?BI&hcoX_+vtTH7ckygwyR|GaC9YbMTp&HCSxFRfJpbYICK2}&hh^;Z zR6ccfHGko|X{wz%b9R~3@&W;*YtoG-mn|a4cdPf3ej&=8(ZEFT+-7*vLig)^Ay(1n zT-XFd&uFpZ)uPj}tLgP9Z1wf0o-Q%`Ge$_W)00%*N`ao@5XrcowR>+LT7OSPH;LRO zRx;iu{ZZmH{DIQo6MAbmrVg1ZEY$!PU7X*<>H{vs=*K4%3=tyCoTDt(DV zh%aH2(yu<-9TTg~B)Q(%6& zurSLfjPNz>r5Q;mM=B~{WOPC&8M2kTiF>K>QEeLahe@ihm>*8bPcjYcF0=W|vDdQG z?$QSuw}C0yZ(@)TFhQU88FJ4eq}6YztDMUE3Y9=|zxVXyKmWBi4jgIG^N?ZSen(dB zPJz?7ugHqcODv;k5hGixFOUuKcc9OG%UCQiSq+W(iN3@7`GAgNi)-plR|Mu*!TnNz z%X3^YbuEiHt(Sn2P*}1C&r_f%&3-GvaH@-iLjgtvdX)$iFFK(uY-L`?&uI?{Q(XYH zJ?W%;L#eR29iU{`aAR{H<>?o}pclHoq8Bi#m9&yj!}!b{mhH7nEH~0h^q-QUtS`82Z*{Q|ZUkY73F=8EQFZ#Tg5Dk% zE(lCS@(gLOPb12l*5`4Nj&;EL)sN7Go}-&adMK2bk>1~K?q(Y^455L8`mlC$AZWlW!*(TApLp+gf0^#r=s~X`V%rTN9qIV}A`0P$@{EL4HPq(O##?mzX3vp+ zf8y#pVg|3x)_I$d8&=3xrqaSvmn>_~B&;c&5W1IOHV%YrmjhI0QLzt6@Y7Qg;k}!G zHPKJtX2c-252wwRMNxurcxW=SlvPrdwcC_6be)LZq&`2^H>Y&#sfuruGBR6kB~P4g zcR~V<@~9kfRCG38Gi3*&VtW%SaB*@BkkKaOe>G_MjJ%>6D2&i(qkV}cyAhjp>gk^F0WOL(MS+z5fD#}FF9Ns?C6xg->G+dVwl@%8 z4%2X>R^UD_>k!Fs>(lD6WEfw!o|FYb_8RI8cFb!WunjZ!0Ox58-?~+#OZ@t!iSGxW zu4~9zT1I2~oXuKqL=SS!mZJ&lL)=_+25^*s@%fF3ls!D2kD7RrkrAgBeLu4IuZ@*C zrp?>6R0}wnbBFH%1FJjtDlzV-{hr>6O+Qghgsuz;ey~yE`VnJJ8G~l2j-N#E#?!-m z<9){388AZkF95qC3+kESYH)~}mK#@j83f~xXG%SHK1-hkn7~J_^gH0q)3Q-9Lv@>3ZRX zW$6i5fzl4JS{~~q117slB%y?oi5H}L$vsFQ?wd+&EBUe*If7rJ$=Yize#xqlF)Yh{SMZD3~cP zN!H(R74kiT{SNyQM$aV+N?Cf0#0y$>I1>bQ9mI+YwV4D5ZtMqRal$G=pJYZ5%cc7T z5hN3bGT#4E6J8)yf^@g>S$iD%9VI=+y9@ByqKzo{SNR+78`fx-7h^mrF}{yp$Kes` z{w{BtfaWq*?4uCH1r6@Iz*I&k$qTjs|@ZAOK6_idip93`bmUa7>RX#<3>%{KnHi* zJx~J4DL@BoMra9=7z$qirw(=Vr7Am9Yl@kD>pG8wT3c95foqEADlnz20>d`BtO~x0 z{Jj!qoQ@X_6GXFed(^+Y88hXxj}^duP z+Bpb*AJDnaGfn%B3LmwNTQo4EnLfhBaxagZU5(O5+jOBQm-xDO!w ztYS@gq1X3Ud5Sq=bEckf+dO2*<#BC2g**s6mj3s*Lwy~(msgLZCK#6)p7$%WZv-kz zyg>RS1sqJ6m9pe)ZI+r~N)Tn{UQDVK z{tZ9=Eml9l5!=L2MYAy8;~m%Q*nx%TrcF@R3|o$Q8Usc>jHjQ9+?9IH#Ms~oe95yn zHW3^uG+S(UD|UspL3JJY*<6<+fj&dso7pg9?Yxo|whFV#Ezsk@3Z>g+0S#Di-{Y50 zaQgfzOFaHGOuBy<=Yd~BTi&dYOl(g|Tpi+9zuFxPFFcR0ExODq%C^QgBW>ITKxfcg zErATu|8pl8tRGyYIqsDNfzYm%(P^_26i9YZ=uQsatYW*GK-THB@C%x$#S8XDC}!D_ zOuIjkD&(_&g}68BgkH!zU@xP3|1;QQLSjumc8e1hlzhoY&&C5 z5cC&~F|N^<4`Dz=r6?}<>`i=1i{5>LrgievAEW?t0b?897JDIVj3D4thay2%&n8DI!DHEM`Vm$B=Ur zOHOF#^6#F&%AQ#3U!Sc$v5AFIO_i>fvbjg8WXG>dJyh)Pry)leT{^{eUmHp1w6 z^m7F$@AbKi81yEwjClw~bDUU_U6?yzDov~)(oM6?jA`R&u*ENB*_a< z{0RtjeKQkKq!TZt%D3eHy$!DYm`l>yR1Fsg7)I~z)-e+~-}5??D$tDO>=d>`L~mvxPeqs1 zN45yFpSAN$v-tJMK9`uICr`-j6>Vgt2Bmfz*w!5B;jE#4mMH^w|ajk{IPG~Jkjk*{rSxQcQNh3}+M48}QLO|FEtowc*%MU5?ZtWOHgNdBC4gI#tCFBgdXH zTBuJdy7*?jGGkvcIBgQ|trVaUR69Lt0P?xx+;pNU=E<8U?}?ACAnf0w%+%DDytX8E zRw%&;Nj~?v+GxI7FH-{H6uwC+T`ZJW&5ycF^O~W9DmPdj*!&V+jo)Ee3)6lV0R>L> z%Yw2i4s`Kt0r4b`+r%R}Tlz!N>N1X%3O^5h}G&*WZ&hvWw z2Y!&m6gxGyekXF7>2po4nR~%}UT-?eyCLm`9MJmLi#MZX?5ZYZkPSAeS-qxEBi@^H%ym2eU^LK}i`n$frKY}N`OSgcIfRyuJs9`@-ok^R5#B~ z%CYOuCWsBUsk^GD=*c~%wn%+TYTnI!4+2VwRf;9C#cPNYR)EA5 zReEWvQHvW&k~OIeJa14O>d#x&qPC-5D?hS&09Hh5te1jvOQ|j4l)7q!p_5Sy(QKOS z^D$VRy}|7{sB}jKV}BI*sLQTt2fO9!Q(H9WBnkXcb-)PMt$PV_&{?c#aJeXQ(K5^l zRw`7je^E``+NXx6&18Xa6V=ddALkgUYD-(Ze%%`-P~5#OylAp7Q!;p#zA}YC+c0{O z5q+1D>)Gop3!uI}h{#}~10u1VNt;#)5SlvvI1+sa(J`W+CkWH7tIX-jWpus2*#0~u z`iPKO`68HsePk~zmh6Ee=Lg3 z^eHrZP2wvbef(?zJX@s;rq4>b_WnRJHAH%flp!5l3*Uvf{31KP;#<_H!a%=Wy8_-EZ>X`d=HRH z`DJxujxV|YUeVXy%=|$XQSOXcLoVdJq}&Zv*H;Z^%HNS-Wuduv42QWe=qN7Xl(iw^ zz89DP=TfFN#aiw_{%KAC*|c-_l%eMBxJf~xefLlL-Fola?BmXp08Dj}0!c+$fm6i2 zcRDd{LWmHEiGDWvO)1wx>5_nldZln!lZuP2~`~4?-B}d`kO~ z-t#y`vW^aO28??&K9vNaV$gG~l)5ye?7N^yu-HwB1Cd z%&6nxKVQl@7FK4j-?&MfpYju!4AkayWwg3p!#gbz`44|F9;xo26|4KYJ3#8-J?Su} z{>QloG)u!=w@?If0BI_ zf^}bcilVOmY7Xq68+8|ZbDrF&U*EmIe$x84rt}lOvR+^2>59rwZ*eZOqJ>c>4Qiqj ze>;LG`>EZD$dnk1{L<{1t3~p0c+wo;t99I%-0I=|Wc$EF=1Htu+NDWWI)lGI!CXuZY@_1-{W>4kf6q(Qaga%@xFQs?C+ zUzk;ba%7z4jqW!w!s4op{l-bZUrx_g-K!zJjn`cTvwTVvezydq>)lB|abxS#HiCY` zfL0$t(YqcDHlnzEKbtJU$?Th$vK}@aFXm1hX1zL#o4Xg&E7zrAvtHYc#}xiyKG7X9 zVfWve;EnaotAAEi6VGp>97n+E9_&Mi#zbf&kbU7RuR6Q*ux2t!zfh^N*);7=Bsr~E z?Eq8AQoJbOa>>os+@EBS!|Cbls8HrqQxWPgP=IYSgKm1V#k5>kr3FF$>ehr>prTaWPlCYCD3M~$Fv5n^{-7}XFv;7Odu2|L6%>V@Hy*&CA4 zDXYTN;zUkYE{c2HbUHd&M4uz}YYbGu-`J$PD!ky1G*UlKmFIuPw&3z^_W05abH?Wq zwYYG5C9C?LFA`Vf49zxdu?~eXo$n8e%X0t4B?(L3Iq2;LEF9R^-NIKkdmyU-aa#^m zKyglWC@lS}f9?W9cvIlu+4=l6z(uR(P-VGMf?%scNw(@c z;+UWJY@G&fF=O*cLS`L0WS~N*5G;%Q01u(WsLL|GqvuYdMh>pAS-9bmYQVYTOUh5J z*(Ytx&*sz6I8;*DI%iO5@k;oSz4u(7_H@3`7~^M_r(|bF3{TA&*~o6Iw$tzW^xZ(Z zT|vZ$4yl*EFJyF!{q8{nn1lOty$9k&;e^!d^kch`u&FDcz=}&-q-M9snK5oc!K?76 z^+%qghE*gKn)J|^@?mIdMi~lFQ?$iVE?N zjbBRRlD?*tO(pBEu`cDUmUp2PB-Rnfds`#~sNe4`+tvm8b|(S#5d5j-I?#}Asx=WT z*+(}7{~CmDpr85@AQ6gh{LEA)Pfn{&qH>^0xSn8Zd=NG7uWoKNJzbo)LYCU^zEUDf-0i`Tqn zMJ?4fkK53hj+A)BS&pNyrxfLIG!#dkM3v%^$?ZkAh;?AY!RM3Jx!+?SK}YYS82?Ut zDRD`crpDV5HxmQA!F1IVwR3O2ic0lzCZ`KQe6`J^sU;OBZ)_^D-2?2V?!{w@%a`573w)So zu+Gk5rktU5ipyYTuX*Uofx+cUQ+OPZKP&hQ?MAXHC6f3(mA8#}_l8Y0O5@RyKLThd zzSAO>B_+--j%C1y+Qr~~lVP`Sb9`vqzXRXp8tw#L{ZTj1a1S6am8jyy zY5DQ%_4u1v=OW+C&$I~cT-RNBFY9atp1|J}h>{}Q*pxrU|^`FBLlJ@Hk zRxOtVoXwBw>s>&M5cjoAmW20yjp1ToK@S!X+T6GZwY$bH+1U1(_+0x%l1Lu=}Z z**KGPd@VMIgo}ETSLI}h8xgQUpW4b;9AJ@QD4Ad?rG|~7YG&pUb);eJoW6!VFp4_cANhJQ}m&D_z_w-*kH-OM=p*T_lSyCxjZV7lCwle*!4g!H+ z9il>hLk3dKHpH@rxqL01-jZS4n*8#o18d!|tg@$#)1$oL=WD^nWtLe!sqp)0!8+>e zwp~TMbof+$=6ApG!-1p|?G@em5{Z4ed^VJxP+Hq6`Iwv$wW(0STL(4MJrx!_46pB9 zrgLW)<&Nk@u_m>Ag$i67A6u_+1j_-~ycrH$uk)z$N=;k}5<2`eL@rD0uZ8)47LUZc z$BTuL;YZV&+ni_by)k_(y%<=3G!hh!*oB6-=Fk-4UUfB6oMZKp@O>`IyY0fS<=RVX z`ab-UQ1TpOxux|D3s7aNbRgp^`{OuCNiZ)P!uS?A2wKn8aP&IN5W;a|@ zFeT2tWT`|9XrLX>JnQ&P(v@c40;UANeE-$DVnU*#C3TwIXFEf4krJR_91Ew7z!6%| zF#vvaBc>X^z@%uq6*7@hLIvh%E0dDy&fzlstHAHfO6{$cf=cL1%1+ZaxX$jao;KA! zCTe2<2=-f(2+e(lWT47`$QM=Ebs2W$2wi}#@~R4Kyjx88m$18_0?+AFZz_;^qB}Ky zIDTl)qxp)U$H&`>{q<#!@W-F&dXig-_Dh7z*EsE^O^?-B8#_Z6Tu~g}5W5(C2aMFn zb)VcIV>%SZn_-t8SzH@jN(}u2Lj(+Y7i2CSrF`%t0V+(I(k)$h+m%_>6>2_eX{SOg zGbc!fv#h+`j1;MQf!uR)=x2Q-*Z`J6G&sBpub8AW*D7*x@wLN+xx=fbqh{WqKn=?~ zZG^k$d5S~jMOVkVO_%f2X*cIhvZM~&A2(NJ2_J7e_;5o+zf#EJo%2PF7f%+IF@9b& zw0A-0QZ%Lh5`5k}3GUM1pAEK{>PqmwDgN?q_BlJ)=K)vg4M4%zvg;x^BR@4;zq}gW zE$O{a`eHi%_%$~v#6l{tQlLR1w?T4dysk_lJOD&)ak06dzKXXUld`=!@Z3CqQ(8n* z$8X(M9`6;r_7+v36vr_g+zcUaM}?=4qdWH(g^4E!S{QZ;9?>GF{vFqNIw6!u?>+ zy2oCA1dn~0KxmVPtw}&d1cKE#Cg@;i+tg}Nl?uN~m#fA0j1Mvunb$Hi{%bC1KeDr; zTnGjMCq3Z??PS}UGHtsAcO{&T{blAsp9J_sT{G~Sgg6s;)!_MWMoZfEHmT4y%$Gkf z;@zC6z>pxEp&5o!D$aC=glJ8GC=Q^M^+0n`hN<<9va=?AQWki?SFXCVi8?02m3nscTD|_po}mlunOuPDeoU)I=dXsOgD{uZ^|lfu6X)| zl{CmZ1w7VklfYJ>6z{$irLbYD_y6XsbQMg30iVC@??|8DhT=>VGc3XeUGu}?SrouC z?WF^kBjM^yTjty661mQ+!+-aN8!jnRE2c%Dbl%T%uk##4xm+Hee^dD!QdQGZvS|vz zyszmW&-6z99B+VlHZwe3rDJgllNhF}z7(+YY23(j+9ED^jW4oa(L(xjo`2r_9F_-! zFJ}LH$JZ$J_TajhC3IZfh-!($=U&{Zn#BwxyP!2dtkfvwVfVW6R2|nXKwP$%?3nM% zfR2GiATRqfu-|4%i?(UtWcBuKOE}kK{xc$EpN6(64JL$?aprr5eoY=G8CLGQ@=gw% ze;^ehf2xl=Uom7aYGIfAnrnf9Csj!Ypt+gA!k6f=mr-T^DHq^VOTHP~=Qd1s(_IU? zLJs?yQ7kZvK2jG;f9*N4Zj8e#MC>sIV8FOz9I_)H3FiKiNdYk!$2YEn^kk`59xm}_ z79^iSH>z5MDkD@+)s#=wK$SmF>JAyN@2JByZmrMtl;6VYuUN9Yv;moXH1|xS#dHgZ6X| z&C#`p-r`XLo9QyyWs9+GQ{=fsolX?anpNT~SrP(UI_F8rm!rGkDz=56Nzk~w2l75M zDKI*?;OmW!0?5R-XHWZ94n3TU&v#Mfbyu;s)_sH^{A(SNsZ?&N&z7t_8ZY%aN7oyG zU;9$hA!4F;+|J5;DXHs`YJakNjZY6Y3*uJYLh#&h+OTaNrG%5R+Erjb)VBTIRej;`sDPE+S09@)GE^NZRFbrWXht+U>xU6 z!{pP{H#X9u(sVDf=#tzj8=^ z#`M=_yOAEKR{UD4jS;!DFaxNKsne7ltOAkHUf3@U&GFzPx17_70ieD*%hUa+1fP>w zh9ew(R&QpC3p#uGg(%{=_#@z>?{M7*Fqa<|>Gp&8YuO-}(baG48FO(F<{QO3pXWLB zeSHZTD27>TyjDvxE;xi1SKXMBL*>)Hygm`r;Zb)n0gv=ewA~v!ZM0jdG7%xj0rNEw@)@o#j?R7kfW!rx Yq;SvdMtd^;_X{3CQc(); + } + + [Test] + public async Task ThrowsWhenSourceTypeIsNull() + { + // Act & Assert + await Assert.That(() => new ClassAutoDataAttribute(null)).ThrowsExactly(); + } + + [Test] + public async Task TreatsNullParameterValueAsArrayWithNull() + { + // Arrange & Act + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData), null); + + // Assert + await Assert.That(sut.Parameters).HasSingleItem() + .And + .IsNotNull(); + } + + [Test] + public async Task ThrowsWhenFixtureFactoryIsNull() + { + // Act & Assert + await Assert.That(() => new DerivedClassAutoDataAttribute( + fixtureFactory: null, typeof(MixedTypeClassData))).ThrowsExactly(); + } + + [Test] + public async Task GetDataThrowsWhenSourceTypeNotEnumerable() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MyClass)); + var testMethod = typeof(ExampleTestClass) + .GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()).ToArray()).ThrowsExactly(); + } + + [Test] + public async Task GetDataThrowsWhenParametersDoNotMatchConstructor() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MyClass), "myString", 33, null); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()).ToArray()).ThrowsException(); + } + + [Test] + public async Task GetDataDoesNotThrowWhenSourceYieldsNoResults() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(EmptyClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act + var data = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + ; + + // Assert + await Assert.That(data).IsEmpty(); + } + + [Test] + public async Task GetDataThrowsWhenSourceYieldsNullResults() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(ClassWithNullTestData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()).ToArray()).ThrowsException(); + } + + [Test] + public async Task GetDataDoesNotThrow() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & Assert + sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)); + } + + [Test] + public async Task GetDataReturnsEnumerable() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)); + + // Assert + await Assert.That(actual).IsNotNull(); + } + + [Test] + public async Task GetDataReturnsNonEmptyEnumerable() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)); + + // Assert + await Assert.That(actual).IsNotEmpty(); + } + + [Test] + public async Task GetDataReturnsExpectedTestDataCount() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)); + + // Assert + await Assert.That(actual).HasCount().EqualTo(5); + } + + [Test] + public async Task GetDataThrowsWhenDataSourceNotEnumerable() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(GuardedConstructorHost)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()).ToArray()).ThrowsException(); + } + + [Test] + public async Task GetDataThrowsForNonMatchingConstructorTypes() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(DelegatingTestData), "myString", 33, null); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()).ToArray()).ThrowsException(); + } + + [Test] + [Arguments("CreateWithFrozenAndFavorArrays")] + [Arguments("CreateWithFavorArraysAndFrozen")] + [Arguments("CreateWithFrozenAndFavorEnumerables")] + [Arguments("CreateWithFavorEnumerablesAndFrozen")] + [Arguments("CreateWithFrozenAndFavorLists")] + [Arguments("CreateWithFavorListsAndFrozen")] + [Arguments("CreateWithFrozenAndGreedy")] + [Arguments("CreateWithGreedyAndFrozen")] + [Arguments("CreateWithFrozenAndModest")] + [Arguments("CreateWithModestAndFrozen")] + [Arguments("CreateWithFrozenAndNoAutoProperties")] + [Arguments("CreateWithNoAutoPropertiesAndFrozen")] + public async Task GetDataOrdersCustomizationAttributes(string methodName) + { + // Arrange + var method = typeof(TypeWithCustomizationAttributes) + .GetMethod(methodName, [typeof(ConcreteType)]); + var customizationLog = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizationLog.Add(c) + }; + + var sut = new DerivedClassAutoDataAttribute(() => fixture, typeof(ClassWithEmptyTestData)); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(customizationLog[0]).IsAssignableTo(); + + var composite = (CompositeCustomization)customizationLog[0]; + + await Assert.That(composite.Customizations.First()).IsNotTypeOf(); + await Assert.That(composite.Customizations.Last()).IsAssignableTo(); + } + + [Test] + public async Task GetDataReturnsExpectedTestData() + { + var builder = new CompositeSpecimenBuilder( + new FixedParameterBuilder("a", 1), + new FixedParameterBuilder("b", "value"), + new FixedParameterBuilder("c", EnumType.First), + new FixedParameterBuilder>("d", new Tuple("value", 1))); + var sut = new DerivedClassAutoDataAttribute( + () => new DelegatingFixture { OnCreate = (r, c) => builder.Create(r, c) }, + typeof(MixedTypeClassData)); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + object[][] expected = + [ + [1, "value", EnumType.First, new Tuple("value", 1)], + [9, "value", EnumType.First, new Tuple("value", 1)], + [12, "test-12", EnumType.First, new Tuple("value", 1)], + [223, "test-17", EnumType.Third, new Tuple("value", 1)], + [-95, "test-92", EnumType.Second, new Tuple("myValue", 5)] + ]; + + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + await Assert.That(actual).IsEquivalentTo(expected); + } + + [Test] + public async Task GetDataReturnsExpectedTestDataFromParameterizedSource() + { + var builder = new CompositeSpecimenBuilder( + new FixedParameterBuilder("a", 1), + new FixedParameterBuilder("b", "value"), + new FixedParameterBuilder>("d", new Tuple("value", 1))); + var sut = new DerivedClassAutoDataAttribute( + () => new DelegatingFixture { OnCreate = (r, c) => builder.Create(r, c) }, + typeof(ParameterizedClassData), + 29, "myValue", EnumType.Third); + var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); + object[][] expected = + [ + [29, "myValue", EnumType.Third, new Tuple("value", 1)], + [29, "myValue", EnumType.Third, new Tuple("value", 1)] + ]; + + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + await Assert.That(actual).IsEquivalentTo(expected); + } + + [Test] + public async Task TestWithNullParametersPasses() + { + // Arrange + var sut = new ClassAutoDataAttribute(typeof(TestDataWithNullValues)); + var testMethod = typeof(ExampleTestClass>) + .GetMethod(nameof(ExampleTestClass>.TestMethod)); + var expected = new[] + { + new object[] { null, null, null, null }, + new object[] { string.Empty, null, null, null }, + new object[] { null, " ", null, null }, + }; + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(actual).IsEquivalentTo(expected); + } + + public class TestDataWithNullValues : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return [null, null, null, null]; + yield return [string.Empty, null, null, null]; + yield return [null, " ", null, null]; + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/ClassAutoDataScenarioTests.cs b/tests/AutoFixture.TUnit.Tests/ClassAutoDataScenarioTests.cs new file mode 100644 index 0000000..d9b146d --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/ClassAutoDataScenarioTests.cs @@ -0,0 +1,63 @@ +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests; + +public class ClassAutoDataScenarioTests +{ + [Test] + [ClassAutoData(typeof(MixedTypeClassData))] + public async Task TestWithMixedTypesPasses(int? a, string b, EnumType? c, Tuple d) + { + await Assert.That(a).IsNotNull(); + await Assert.That(b).IsNotNull(); + await Assert.That(c).IsNotNull(); + await Assert.That(d).IsNotNull(); + } + + [Test] + [ClassAutoData(typeof(ParameterizedClassData), 42, "test-13", EnumType.Third)] + public async Task TestWithParameterizedClassDataReceivesExpectedData( + int a, string b, EnumType c, PropertyHolder d) + { + await Assert.That(a).IsEqualTo(42); + await Assert.That(b).IsEqualTo("test-13"); + await Assert.That(c).IsEqualTo(EnumType.Third); + await Assert.That(d?.Property).IsNotNull(); + } + + [Test] + [ClassAutoData(typeof(ParameterizedClassData), 13, "test-46", EnumType.Second)] + public async Task TestWithFrozenParametersReceivesExpectedData( + [Frozen] int a, [Frozen] string b, [Frozen] EnumType c, + PropertyHolder a1, PropertyHolder b1, PropertyHolder c1) + { + await Assert.That(a).IsEqualTo(13); + await Assert.That(b).IsEqualTo("test-46"); + await Assert.That(c).IsEqualTo(EnumType.Second); + + await Assert.That(a1.Property).IsEqualTo(a); + await Assert.That(b1.Property).IsEqualTo(b); + await Assert.That(c1.Property).IsEqualTo(c); + } + + [Test] + [ClassAutoData(typeof(ParameterizedClassData), 59, "hello-world", EnumType.Second)] + public async Task TestWithInjectedValuesRespectsOtherParameterCustomizations( + [Frozen] int a, [Frozen] string b, [Frozen] EnumType c, + [FavorEnumerables] CompositeTypeWithOverloadedConstructors numbers, + [FavorArrays] CompositeTypeWithOverloadedConstructors strings, + [FavorLists] CompositeTypeWithOverloadedConstructors enums) + { + await Assert.That(numbers.Items).IsAssignableTo>(); + await Assert.That(numbers.Items).IsNotTypeOf>(); + await Assert.That(numbers.Items).IsNotTypeOf(); + await Assert.That(numbers.Items).All().Satisfy(item => item.IsEqualTo(a)); + + await Assert.That(strings.Items).IsAssignableTo(); + await Assert.That(strings.Items).All().Satisfy(item => item.IsEqualTo(b)); + + await Assert.That(enums.Items).IsAssignableTo>(); + await Assert.That(enums.Items).All().Satisfy(item => item.IsEqualTo(c)); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs new file mode 100644 index 0000000..6ec2a20 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs @@ -0,0 +1,207 @@ +using System.Reflection; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.Equality; + +namespace AutoFixture.TUnit.Tests; + +public class CompositeDataAttributeSufficientDataTest +{ + private readonly MethodInfo method = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), + [typeof(object), typeof(object), typeof(object)]); + + [Test] + [MethodDataSource(typeof(CompositeDataAttributeSufficientDataTest), nameof(GetEnumerator))] + public async Task GetDataReturnsCorrectResult(IEnumerable attributes, + IEnumerable expectedResult) + { + // Arrange + var attribute = new CompositeDataAttribute(attributes.ToArray()); + + // Act + var result = attribute.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(this.method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(result).IsEquivalentTo(expectedResult, new CollectionEquivalentToEqualityComparer()); + } + + public IEnumerable<(IEnumerable Attributes, + IEnumerable ExpectedResult)> GetEnumerator() + { + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3]]) + ], + expected: + [ + [1, 2, 3] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3]]), + new FakeDataAttribute(this.method, [[4, 5, 6]]) + ], + expected: + [ + [1, 2, 3] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1]]), + new FakeDataAttribute(this.method, [[2, 3, 4]]) + ], + expected: + [ + [1, 3, 4] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2]]), + new FakeDataAttribute(this.method, [[3, 4, 5]]) + ], + expected: + [ + [1, 2, 5] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3], [4, 5, 6]]) + ], + expected: + [ + [1, 2, 3], + [4, 5, 6] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3], [4, 5, 6]]), + new FakeDataAttribute(this.method, + [[7, 8], [9, 10], [11, 12]]) + ], + expected: + [ + [1, 2, 3], + [4, 5, 6] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, + [[1, 2], [3, 4], [5, 6]]), + new FakeDataAttribute(this.method, + [[7, 8, 9], [10, 11, 12], [13, 14, 15]]) + ], + expected: + [ + [1, 2, 9], + [3, 4, 12], + [5, 6, 15] + ]); + + // Second attribute restricts + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3], [4, 5, 6]]), + new FakeDataAttribute(this.method, [[7, 8, 9]]) + ], + expected: + [ + [1, 2, 3] + ]); + + // Shortest data provider is limiting factor + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2, 3]]), + new FakeDataAttribute(this.method, [[4, 5, 6], [7, 8, 9]]) + ], + expected: + [ + [1, 2, 3] + ]); + + // Test incorrect number of parameters - should just return what it's given + // and let xUnit deal with counting parameters + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1, 2]]), + new FakeDataAttribute(this.method, [[3, 4]]) + ], + expected: + [ + [1, 2] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1]]), + new FakeDataAttribute(this.method, [[2, 3]]) + ], + expected: + [ + [1, 3] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1]]), + new FakeDataAttribute(this.method, [[]]), + new FakeDataAttribute(this.method, [[2, 3]]) + ], + expected: + [ + [1, 3] + ]); + + yield return CreateTestData( + data: + [ + new FakeDataAttribute(this.method, [[1]]), + new FakeDataAttribute(this.method, [[2]]), + new FakeDataAttribute(this.method, [[3]]) + ], + expected: + [ + [1] + ]); + } + + private static (IEnumerable attributes, + IEnumerable expectedResult) CreateTestData(AutoFixtureDataSourceAttribute[] data, object[][] expected) + { + return (data, expected); + } + + private sealed class TheoryComparer : IEqualityComparer + { + public bool Equals(object[] x, object[] y) + { + return x!.SequenceEqual(y!); + } + + public int GetHashCode(object[] array) + { + return array.Select(obj => obj.GetHashCode()).Aggregate((x, y) => x ^ y); + } + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeTest.cs new file mode 100644 index 0000000..5e28f84 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeTest.cs @@ -0,0 +1,108 @@ +using System.Reflection; +using AutoFixture.TUnit.Tests.TestTypes; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class CompositeDataAttributeTest +{ + [Test] + public async Task SutIsDataAttribute() + { + // Arrange & Act + var sut = new CompositeDataAttribute(); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task InitializeWithNullArrayThrows() + { + // Arrange + // Act & assert + await Assert.That(() => new CompositeDataAttribute(null)).ThrowsExactly(); + } + + [Test] + public async Task AttributesIsCorrectWhenInitializedWithArray() + { + // Arrange + var a = () => { }; + var method = a.GetMethodInfo(); + + var attributes = new AutoFixtureDataSourceAttribute[] + { + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, []) + }; + + var sut = new CompositeDataAttribute(attributes); + // Act + IEnumerable result = sut.Attributes; + // Assert + await Assert.That(result).IsEquivalentTo(attributes); + } + + [Test] + public void InitializeWithNullEnumerableThrows() + { + // Arrange + // Act & assert + Assert.Throws( + () => new CompositeDataAttribute((IReadOnlyCollection)null)); + } + + [Test] + public async Task AttributesIsCorrectWhenInitializedWithEnumerable() + { + // Arrange + var a = () => { }; + var method = a.GetMethodInfo(); + + var attributes = new AutoFixtureDataSourceAttribute[] + { + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, []) + }; + + var sut = new CompositeDataAttribute(attributes); + // Act + var result = sut.Attributes; + // Assert + await Assert.That(result).IsEquivalentTo(attributes); + } + + [Test] + public async Task GetDataWithNullMethodThrows() + { + // Arrange + var sut = new CompositeDataAttribute(); + // Act & assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null, null)) + .Select(x => x()).ToArray()).ThrowsException(); + } + + [Test] + public async Task GetDataOnMethodWithNoParametersReturnsNoTheory() + { + // Arrange + Action a = () => { }; + var method = a.GetMethodInfo(); + + var sut = new CompositeDataAttribute( + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, []), + new FakeDataAttribute(method, [])); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(result).All().Satisfy(row => row.IsEmpty()); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CustomizeAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/CustomizeAttributeTest.cs new file mode 100644 index 0000000..d02724a --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/CustomizeAttributeTest.cs @@ -0,0 +1,36 @@ +using AutoFixture.TUnit.Tests.TestTypes; + +namespace AutoFixture.TUnit.Tests; + +public class CustomizeAttributeTest +{ + [Test] + public async Task TestableSutIsSut() + { + // Arrange + // Act + var sut = new DelegatingCustomizeAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new DelegatingCustomizeAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task SutImplementsIParameterCustomizationSource() + { + // Arrange + // Act + var sut = new DelegatingCustomizeAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs new file mode 100644 index 0000000..bda77fa --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs @@ -0,0 +1,62 @@ +using System.Reflection; +using TUnit.Core.Enums; + +namespace AutoFixture.TUnit.Tests; + +public class DataGeneratorMetadataHelper +{ + public static DataGeneratorMetadata CreateDataGeneratorMetadata(Type type, string methodName) + { + return CreateDataGeneratorMetadata(type.GetMethod(methodName)); + } + + public static DataGeneratorMetadata CreateDataGeneratorMetadata(MethodInfo methodInfo) + { + var parameters = methodInfo.GetParameters(); + var type = methodInfo.ReflectedType ?? methodInfo.DeclaringType!; + var methodName = methodInfo.Name; + var attributes = methodInfo.GetCustomAttributes().ToArray(); + + var sourceGeneratedParameterInformations = parameters?.Select(CreateParameter).ToArray() ?? []; + + return new DataGeneratorMetadata + { + Type = DataGeneratorType.TestParameters, + TestBuilderContext = null!, + TestSessionId = null!, + MembersToGenerate = sourceGeneratedParameterInformations.Cast() + .ToArray(), + TestInformation = new SourceGeneratedMethodInformation + { + Type = type, + Name = methodName, + Attributes = attributes ?? [], + GenericTypeCount = 0, + Class = new SourceGeneratedClassInformation + { + Type = type, + Assembly = null!, + Attributes = type.GetCustomAttributes() + .ToArray(), + Name = type.Name, + Namespace = null, + Parameters = [], + Properties = [] + }, + Parameters = sourceGeneratedParameterInformations, + ReturnType = typeof(void), + }, + TestClassInstance = null, + ClassInstanceArguments = [] + }; + } + + private static SourceGeneratedParameterInformation CreateParameter(ParameterInfo parameterInfo) + { + return new SourceGeneratedParameterInformation(parameterInfo.ParameterType) + { + Name = parameterInfo.Name!, + Attributes = parameterInfo.GetCustomAttributes().ToArray() + }; + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs new file mode 100644 index 0000000..2fe4723 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests; + +public class DependencyConstraintsTests +{ + [Test] + [Arguments("FakeItEasy")] + [Arguments("Foq")] + [Arguments("FsCheck")] + [Arguments("Moq")] + [Arguments("NSubstitute")] + [Arguments("nunit.framework")] + [Arguments("Rhino.Mocks")] + [Arguments("Unquote")] + [Arguments("xunit")] + [Arguments("xunit.extensions")] + public async Task AutoFixtureXunit3DoesNotReference(string assemblyName) + { + // Arrange + // Act + var references = typeof(AutoDataAttribute).GetTypeInfo().Assembly.GetReferencedAssemblies(); + // Assert + await Assert.That(references).DoesNotContain(an => an.Name == assemblyName); + } + + [Test] + [Arguments("FakeItEasy")] + [Arguments("Foq")] + [Arguments("FsCheck")] + [Arguments("Moq")] + [Arguments("NSubstitute")] + [Arguments("nunit.framework")] + [Arguments("Rhino.Mocks")] + [Arguments("Unquote")] + [Arguments("xunit")] + [Arguments("xunit.extensions")] + public async Task AutoFixtureXunit3UnitTestsDoNotReference(string assemblyName) + { + // Arrange + // Act + var references = this.GetType().GetTypeInfo().Assembly.GetReferencedAssemblies(); + // Assert + await Assert.That(references).DoesNotContain(an => an.Name == assemblyName); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs b/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs new file mode 100644 index 0000000..b1ffe1c --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs @@ -0,0 +1,57 @@ +namespace AutoFixture.TUnit.Tests; + +internal static class EnumerableExtensions +{ + /// + /// Applies a specified function to the corresponding elements of any number of sequences. + /// + /// The type of the elements of the input sequences. + /// The type of the elements of the result sequence. + /// The input sequences. + /// A function that specifies how to combine the corresponding elements of the sequences. + /// An that contains elements of the input sequences, combined by resultSelector. + internal static IEnumerable Zip(this IEnumerable> sequences, + Func, TResult> resultSelector) + { + var enumerators = sequences.Select(s => s.GetEnumerator()).ToList(); + while (enumerators.TrueForAll(e => e.MoveNext())) + { + yield return resultSelector(enumerators.Select(e => e.Current)); + } + } + + /// + /// Collapses a series of sequences down by using items from the first sequence until it finishes, + /// then continuing from the same index through the second sequence, and so on until all sequences + /// have been exhausted. + /// + /// The type of the elements of the input sequences. + /// The input sequences. + /// Items from each sequence in turn, yielding those from the first sequence first. + internal static IEnumerable Collapse(this IEnumerable> sequences) + { + var position = 0; + foreach (var sequence in sequences) + { + foreach (var item in sequence.Skip(position)) + { + position++; + yield return item; + } + } + } + + /// + /// Casts the source sequence to an . + /// Enumerates the source sequence to an array if it is not an enumerated collection. + /// + /// The source sequence. + /// The sequence item type. + /// An that contains elements of the source sequence. + public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) + { + return source is not null + ? source as IReadOnlyCollection ?? source.ToArray() + : null; + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs new file mode 100644 index 0000000..51f735b --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs @@ -0,0 +1,44 @@ +using AutoFixture.Kernel; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class FavorArraysAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new FavorArraysAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new FavorArraysAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsCorrectResult() + { + // Arrange + var sut = new FavorArraysAttribute(); + var parameter = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object)])! + .GetParameters().Single(); + // Act + var result = sut.GetCustomization(parameter); + // Assert + var invoker = await Assert.That(result).IsAssignableTo(); + await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker.Query).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs new file mode 100644 index 0000000..de94520 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs @@ -0,0 +1,44 @@ +using AutoFixture.Kernel; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class FavorEnumerablesAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new FavorEnumerablesAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new FavorEnumerablesAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsCorrectResult() + { + // Arrange + var sut = new FavorEnumerablesAttribute(); + var parameter = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object)])! + .GetParameters().Single(); + // Act + var result = sut.GetCustomization(parameter); + // Assert + var invoker = await Assert.That(result).IsAssignableTo(); + await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker.Query).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs new file mode 100644 index 0000000..9289cfc --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs @@ -0,0 +1,44 @@ +using AutoFixture.Kernel; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class FavorListsAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new FavorListsAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new FavorListsAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsCorrectResult() + { + // Arrange + var sut = new FavorListsAttribute(); + var parameter = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object)])! + .GetParameters().Single(); + // Act + var result = sut.GetCustomization(parameter); + // Assert + var invoker = await Assert.That(result).IsAssignableTo(); + await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker.Query).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs new file mode 100644 index 0000000..3357903 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs @@ -0,0 +1,26 @@ +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class FrozenAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new FrozenAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new FrozenAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs new file mode 100644 index 0000000..118a592 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs @@ -0,0 +1,47 @@ +using AutoFixture.Kernel; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; +#if NETCOREAPP1_1 +using System.Reflection; +#endif + +namespace AutoFixture.TUnit.Tests; + +public class GreedyAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new GreedyAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new GreedyAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsCorrectResult() + { + // Arrange + var sut = new GreedyAttribute(); + var parameter = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object)])! + .GetParameters().Single(); + // Act + var result = sut.GetCustomization(parameter); + // Assert + var invoker = await Assert.That(result).IsAssignableTo(); + await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker.Query).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs new file mode 100644 index 0000000..0fe03fa --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs @@ -0,0 +1,233 @@ +using AutoFixture.Kernel; +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class AutoDataSourceTests +{ + [Test] + public async Task SutIsTestDataSource() + { + // Arrange & Act + var sut = new AutoDataSource(() => new DelegatingFixture()); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task SetsPropertiesToExpectedValues() + { + // Arrange + var fixtureFactory = () => new DelegatingFixture(); + var source = new DelegatingDataSource(); + + // Act + var sut = new AutoDataSource(fixtureFactory, source); + + // Assert + await Assert.That>(sut.CreateFixture).IsSameReferenceAs(fixtureFactory); + await Assert.That(sut.Source).IsSameReferenceAs(source); + } + + [Test] + public async Task GeneratesTestDataUsingFixture() + { + // Arrange + var builder = new CompositeSpecimenBuilder( + new FixedParameterBuilder("a", "value"), + new FixedParameterBuilder("b", 1), + new FixedParameterBuilder("c", 12.2)); + var fixture = new DelegatingFixture + { + OnCreate = (r, c) => builder.Create(r, c), + }; + var sut = new AutoDataSource(() => fixture); + var method = typeof(SampleTestType).GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).Select(x => x()).ToArray(); + + // Assert + await Assert.That(result).IsNotNull(); + var item = await Assert.That(result).HasSingleItem(); + + await Assert.That(item).IsNotNull(); + await Assert.That(item.Length).IsEqualTo(3); + await Assert.That(item[0]).IsEqualTo("value"); + await Assert.That(item[1]).IsEqualTo(1); + await Assert.That(item[2]).IsEqualTo(12.2); + } + + [Test] + public async Task CombinesTestDataFromSourceWithAutoGeneratedValues() + { + // Arrange + var source = new DelegatingDataSource + { + TestData = + [ + ["a", 15], + ["b", 123], + ["c", 999] + ], + }; + var builder = new FixedParameterBuilder("c", 13.3); + var fixture = new DelegatingFixture + { + OnCreate = (r, c) => builder.Create(r, c), + }; + var sut = new AutoDataSource(() => fixture, source); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + await Assert.That(result).IsNotNull(); + await Assert.That(result.Length).IsEqualTo(3); + await Assert.That(result[0]).IsEquivalentTo(new object[] { "a", 15, 13.3 }); + await Assert.That(result[1]).IsEquivalentTo(new object[] { "b", 123, 13.3 }); + await Assert.That(result[2]).IsEquivalentTo(new object[] { "c", 999, 13.3 }); + } + + [Test] + public async Task DoesNotGenerateValuesWhenAllValuesProvidedBySource() + { + // Arrange + var source = new DelegatingDataSource + { + TestData = + [ + ["a", 85, 913.12], + ["b", 519, 73.1], + ["c", 411, 529.6] + ], + }; + var fixture = new DelegatingFixture + { + OnCreate = (_, _) => throw new InvalidOperationException("Fixture should not be called"), + }; + var sut = new AutoDataSource(() => fixture, source); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + await Assert.That(result).IsNotNull(); + await Assert.That(result.Length).IsEqualTo(3); + await Assert.That(result[0]).IsEquivalentTo(new object[] { "a", 85, 913.12 }); + await Assert.That(result[1]).IsEquivalentTo(new object[] { "b", 519, 73.1 }); + await Assert.That(result[2]).IsEquivalentTo(new object[] { "c", 411, 529.6 }); + } + + [Test] + public async Task ReturnsNoTestDataWhenSourceReturnsNoTestData() + { + // Arrange + var source = new DelegatingDataSource + { + TestData = Array.Empty(), + }; + var fixture = new DelegatingFixture(); + var sut = new AutoDataSource(() => fixture, source); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + await Assert.That(result).IsEmpty(); + } + + [Test] + public async Task ThrowsWhenSourceReturnsNull() + { + // Arrange + var source = new DelegatingDataSource { TestData = null }; + var fixture = new DelegatingFixture(); + var sut = new AutoDataSource(() => fixture, source); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)) + .ToArray()) + .ThrowsException(); + } + + [Test] + public async Task DoesNotCustomizeFixtureWhenParametersNotCustomized() + { + // Arrange + var customizations = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizations.Add(c) + }; + var sut = new AutoDataSource(() => fixture); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + await Assert.That(customizations).IsEmpty(); + } + + [Test] + public async Task CustomizesFixtureUsingParameterCustomizations() + { + // Arrange + var customizations = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizations.Add(c) + }; + var sut = new AutoDataSource(() => fixture); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithCustomizedParameter)); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + await Assert.That(customizations).IsNotEmpty(); + } + + [Test] + public async Task CustomizationsAreAppliedInExpectedOrder() + { + // Arrange + var customizations = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizations.Add(c) + }; + var sut = new AutoDataSource(() => fixture); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleCustomizations)); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray(); + + // Assert + using var scope = Assert.Multiple(); + + await Assert.That(customizations[0]).IsAssignableTo(); + await Assert.That(customizations[1]).IsAssignableTo(); + var composite = await Assert.That(customizations[2]).IsAssignableTo(); + + var compositeCustomizations = composite.Customizations.ToArray(); + await Assert.That(compositeCustomizations.Length).IsEqualTo(2); + await Assert.That(compositeCustomizations[0]).IsAssignableTo(); + await Assert.That(compositeCustomizations[1]).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs new file mode 100644 index 0000000..d58c0bf --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs @@ -0,0 +1,138 @@ +using System.Collections; +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class ClassDataSourceTests +{ + [Test] + public async Task SutIsTestDataSource() + { + // Arrange & Act + var sut = new ClassDataSource(typeof(object), Array.Empty()); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ConstructorWithNullTypeThrows() + { + // Act & Assert + await Assert.That(() => _ = new ClassDataSource(null!, Array.Empty())).ThrowsExactly(); + } + + [Test] + public async Task ConstructorWithNullParametersThrows() + { + // Act & Assert + await Assert.That(() => _ = new ClassDataSource(typeof(object), null!)).ThrowsExactly(); + } + + [Test] + public async Task TypeIsCorrect() + { + // Arrange + var expected = typeof(object); + var sut = new ClassDataSource(expected, Array.Empty()); + + // Act + var result = sut.Type; + + // Assert + await Assert.That(result).IsEqualTo(expected); + } + + [Test] + public async Task ParametersIsCorrect() + { + // Arrange + var expected = new[] { new object() }; + var sut = new ClassDataSource(typeof(object), expected); + + // Act + var result = sut.Parameters; + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + [Test] + public async Task ThrowsWhenSourceIsNotEnumerable() + { + // Arrange + var sut = new ClassDataSource(typeof(object), Array.Empty()); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)).ToArray()).ThrowsExactly(); + } + + [Test] + public async Task GeneratesTestDatWithPrimitiveValues() + { + // Arrange + var expected = new[] + { + new object[] { "hello", 1, new RecordType("world") }, + new object[] { "foo", 2, new RecordType("bar") }, + new object[] { "Han", 3, new RecordType("Solo") } + }; + var sut = new ClassDataSource(typeof(TestSourceWithMixedValues), Array.Empty()); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(actual).IsEquivalentTo(expected); + } + + private class TestSourceWithMixedValues : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return ["hello", 1, new RecordType("world")]; + yield return ["foo", 2, new RecordType("bar")]; + yield return ["Han", 3, new RecordType("Solo")]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + } + + [Test] + public async Task ThrowsWhenConstructorParametersDontMatch() + { + // Arrange + var parameters = new object[] { "a", 1 }; + var sut = new ClassDataSource(typeof(TestSourceWithMixedValues), parameters); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)).ToArray()).ThrowsException(); + } + + [Test] + public async Task AppliesExpectedConstructorParameters() + { + // Arrange + object[] parameters = [new object[] { "y", 25 }]; + var sut = new ClassDataSource(typeof(DelegatingTestData), parameters); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)).ToArray(); + + // Assert + await Assert.That(result.Single()).IsEquivalentTo(new object[] { "y", 25 }); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs new file mode 100644 index 0000000..4678dd3 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs @@ -0,0 +1,112 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class DataSourceTests +{ + [Test] + public async Task SutIsTestDataSource() + { + // Arrange + var sut = new DelegatingDataSource(); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ReturnSingleEmptyArrayWhenMethodHasNoParameters() + { + // Arrange + var sut = new DelegatingDataSource(); + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithoutParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)).ToArray(); + + // Assert + var item = await Assert.That(result).HasSingleItem(); + + await Assert.That(item).IsEmpty(); + } + + [Test] + public async Task ThrowsWhenNoDataFoundForMethod() + { + // Arrange + var sut = new DelegatingDataSource { TestData = null }; + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithSingleParameter)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)).ToArray()).ThrowsExactly(); + } + + [Test] + public async Task ReturnSingleArrayWithSingleItemWhenMethodHasSingleParameter() + { + // Arrange + var sut = new DelegatingDataSource + { + TestData = [["hello"]] + }; + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithSingleParameter)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)).ToArray(); + + // Assert + var testData = await Assert.That(result).HasSingleItem(); + var argument = await Assert.That(testData).HasSingleItem(); + await Assert.That(argument).IsEqualTo("hello"); + } + + [Test] + public async Task ReturnsArgumentsFittingTestParameters() + { + // Arrange + var testData = new[] + { + new object[] { "hello", 16, 32.86d }, + new object[] { null, -1, -20.22 }, + new object[] { "one", 2 }, + new object[] { null }, + new object[] { }, + }; + var sut = new DelegatingDataSource { TestData = testData }; + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var actual = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(actual.Length).IsEqualTo(testData.Length); + + await Assert.That(actual) + .All() + .Satisfy( + assert => assert.Satisfies(y => y.Length, + y => y.IsBetween(0, 3).WithInclusiveBounds()) + ); + } + + [Test] + public async Task ThrowsWhenTestDataContainsMoreArgumentsThanParameters() + { + // Arrange + var testData = new[] { new object[] { "hello", 16, 32.86d, "extra" } }; + var sut = new DelegatingDataSource { TestData = testData }; + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)).ToArray()).ThrowsExactly(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs new file mode 100644 index 0000000..2c0f953 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs @@ -0,0 +1,110 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class FieldDataSourceTests +{ + public static IEnumerable TestDataFieldWithMixedValues = + [ + ["hello", 1, new FieldHolder { Field = "world" }], + ["foo", 2, new FieldHolder { Field = "bar" }], + ["Han", 3, new FieldHolder { Field = "Solo" }] + ]; + + public static object NonEnumerableField = new object(); + + [Test] + public async Task SutIsTestDataSource() + { + // Arrange + var sourceField = typeof(FieldDataSourceTests) + .GetField(nameof(TestDataFieldWithMixedValues)); + var sut = new FieldDataSource(sourceField); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ThrowsWhenConstructedWithNullField() + { + // Act & Assert + await Assert.That(() => new FieldDataSource(null!)).ThrowsExactly(); + } + + [Test] + public async Task FieldIsCorrect() + { + // Arrange + var expected = typeof(FieldDataSourceTests) + .GetField(nameof(TestDataFieldWithMixedValues)); + var sut = new FieldDataSource(expected); + + // Act + var result = sut.FieldInfo; + + // Assert + await Assert.That(result).IsEqualTo(expected); + } + + [Test] + public async Task ThrowsWhenInvokedWithNullTestMethod() + { + // Arrange + var sourceField = typeof(FieldDataSourceTests) + .GetField(nameof(TestDataFieldWithMixedValues)); + var sut = new FieldDataSource(sourceField); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(null!)).ThrowsExactly(); + } + + [Test] + public async Task ThrowsWhenSourceIsNotEnumerable() + { + // Arrange + var sourceField = typeof(FieldDataSourceTests) + .GetField(nameof(NonEnumerableField)); + var sut = new FieldDataSource(sourceField); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)).ToArray()).ThrowsExactly(); + } + + [Test] + public async Task GeneratesTestDataMatchingTestParameters() + { + // Arrange + var expected = new[] + { + new object[] { "hello", 1, new RecordType("world") }, + new object[] { "foo", 2, new RecordType("bar") }, + new object[] { "Han", 3, new RecordType("Solo") } + }; + var sourceField = typeof(FieldDataSourceTests) + .GetField(nameof(TestDataFieldWithRecordValues)); + var sut = new FieldDataSource(sourceField); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithRecordTypeParameter)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + public static IEnumerable TestDataFieldWithRecordValues = + [ + ["hello", 1, new RecordType("world")], + ["foo", 2, new RecordType("bar")], + ["Han", 3, new RecordType("Solo")] + ]; +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs new file mode 100644 index 0000000..efcee16 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs @@ -0,0 +1,99 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class InlineDataSourceTests +{ + [Test] + public async Task SutIsTestDataSource() + { + // Arrange + // Act + var sut = new InlineDataSource(Array.Empty()); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task InitializeWithNullValuesThrows() + { + // Arrange + // Act & Assert + await Assert.That(() => + new InlineDataSource(null)).ThrowsExactly(); + } + + [Test] + public async Task ValuesIsCorrect() + { + // Arrange + var expectedValues = Array.Empty(); + var sut = new InlineDataSource(expectedValues); + // Act + var result = sut.Values; + // Assert + await Assert.That(result).IsEquivalentTo(expectedValues); + } + + [Test] + public async Task GetTestDataWithNullMethodThrows() + { + // Arrange + var sut = new InlineDataSource(Array.Empty()); + // Act & Assert + await Assert.That(() => + sut.GenerateDataSources(null)).ThrowsExactly(); + } + + [Test] + public async Task SourceThrowsWhenArgumentCountExceedParameterCount() + { + // Arrange + var values = new object[] { "aloha", 42, 12.3d, "extra" }; + var sut = new InlineDataSource(values); + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act & Assert + await Assert.That(() => + sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)) + .Select(x => x()).ToArray() + ).ThrowsExactly(); + } + + [Test] + public async Task ReturnsTestDataWhenArgumentCountMatchesParameterCount() + { + // Arrange + var values = new object[] { "aloha", 42, 12.3d }; + var sut = new InlineDataSource(values); + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)); + + // Assert + var testData = await Assert.That(result).HasSingleItem(); + await Assert.That(testData).IsEqualTo(values); + } + + [Test] + public async Task ReturnsAllArgumentsWhenArgumentCountLessThanParameterCount() + { + // Arrange + var values = new object[] { "aloha", 42 }; + var sut = new InlineDataSource(values); + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)); + + // Assert + var testData = await Assert.That(result).HasSingleItem(); + await Assert.That(testData).IsEqualTo(values); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs new file mode 100644 index 0000000..12b389d --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs @@ -0,0 +1,113 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class MemberDataSourceTests +{ + public static object NonTestDataField = new(); + public static object NonTestDataProperty => new(); + public static object NonTestDataMethod() => new(); + public static IEnumerable EmptyTestDataField = Array.Empty(); + public static IEnumerable EmptyTestData => Array.Empty(); + public static IEnumerable GetEmptyTestData() => Array.Empty(); + + [Test] + public async Task SutIsTestDataSource() + { + // Arrange & Act + var sut = new MemberDataSource( + typeof(MemberDataSourceTests), + nameof(GetEmptyTestData)); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ThrowsWhenTypeIsNull() + { + // Arrange + var method = nameof(GetEmptyTestData); + + // Act & Assert + await Assert.That(() => new MemberDataSource(null!, method)).ThrowsExactly(); + } + + [Test] + public async Task ThrowsWhenNameIsNull() + { + // Arrange + var type = typeof(MemberDataSourceTests); + + // Act & Assert + await Assert.That(() => new MemberDataSource(type, null!)).ThrowsExactly(); + } + + [Test] + public async Task ThrowsWhenArgumentsIsNull() + { + // Arrange + var type = typeof(MemberDataSourceTests); + var method = nameof(GetEmptyTestData); + + // Act & Assert + await Assert.That(() => new MemberDataSource(type, method, null!)).ThrowsExactly(); + } + + [Test] + public async Task InitializesTypeProperty() + { + // Arrange + var type = typeof(MemberDataSourceTests); + var method = nameof(GetEmptyTestData); + + // Act + var sut = new MemberDataSource(type, method); + + // Assert + await Assert.That(sut.Type).IsEqualTo(type); + await Assert.That(sut.Name).IsEqualTo(method); + await Assert.That(sut.Arguments).IsEmpty(); + } + + [Test] + [Arguments(nameof(EmptyTestDataField), typeof(FieldDataSource))] + [Arguments(nameof(EmptyTestData), typeof(PropertyDataSource))] + [Arguments(nameof(GetEmptyTestData), typeof(MethodDataSource))] + public async Task InitializesSourceProperty(string memberName, Type expectedInnerSourceType) + { + // Arrange + var type = typeof(MemberDataSourceTests); + + // Act + var sut = new DelegatingMemberDataSource(type, memberName); + + // Assert + await Assert.That(sut.GetSource()).IsTypeOf(expectedInnerSourceType); + } + + [Test] + public async Task ThrowsWhenSourceDoesNotExist() + { + // Arrange + var type = typeof(MemberDataSourceTests); + + // Act & Assert + await Assert.That(() => _ = new DelegatingMemberDataSource(type, "NonExistentMember")).ThrowsExactly(); + } + + [Test] + [Arguments(nameof(NonTestDataField))] + [Arguments(nameof(NonTestDataProperty))] + [Arguments(nameof(NonTestDataMethod))] + public async Task ThrowsWhenSourceDoesNotReturnTestData(string memberName) + { + // Arrange + var type = typeof(MemberDataSourceTests); + + // Act & Assert + await Assert.That(() => _ = new DelegatingMemberDataSource(type, memberName)).ThrowsExactly(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs new file mode 100644 index 0000000..bb6dddc --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs @@ -0,0 +1,106 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class MethodDataSourceTests +{ + public static IEnumerable GetTestDataFieldWithMixedValues() + { + yield return ["hello", 1, new RecordType("world")]; + yield return ["foo", 2, new RecordType("bar")]; + yield return ["Han", 3, new RecordType("Solo")]; + } + + [Test] + public async Task SutIsTestDataSource() + { + // Arrange + var methodInfo = typeof(MethodDataSourceTests) + .GetMethod(nameof(this.SutIsTestDataSource)); + + // Act + var sut = new MethodDataSource(methodInfo); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task ThrowsWhenMethodInfoIsNull() + { + // Act & Assert + await Assert.That(() => + new MethodDataSource(null!)).ThrowsExactly(); + } + + [Test] + public async Task ThrowsWhenArgumentsIsNull() + { + // Arrange + var methodInfo = typeof(MethodDataSourceTests) + .GetMethod(nameof(this.SutIsTestDataSource)); + + // Act & Assert + await Assert.That(() => + new MethodDataSource(methodInfo, null!)).ThrowsExactly(); + } + + [Test] + public async Task ConstructorSetsProperties() + { + // Arrange + var methodInfo = typeof(MethodDataSourceTests) + .GetMethod(nameof(this.SutIsTestDataSource)); + var arguments = new[] { new object() }; + + // Act + var sut = new MethodDataSource(methodInfo, arguments); + + // Assert + await Assert.That(sut.MethodInfo).IsEqualTo(methodInfo); + await Assert.That(sut.Arguments).IsEquivalentTo(arguments); + } + + [Test] + public async Task GetTestDataInvokesMethodInfo() + { + // Arrange + var expected = new[] + { + new object[] { "hello", 1, new RecordType("world") }, + new object[] { "foo", 2, new RecordType("bar") }, + new object[] { "Han", 3, new RecordType("Solo") } + }; + var testDataSource = typeof(MethodDataSourceTests) + .GetMethod(nameof(this.GetTestDataFieldWithMixedValues)); + var testData = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + var sut = new MethodDataSource(testDataSource); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testData)) + .Select(x => x()); + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + [Test] + public async Task ThrowsWhenMemberDoesNotReturnAnEnumerableValue() + { + // Arrange + var dataSource = typeof(MethodDataSourceTests) + .GetMethod(nameof(NonEnumerableTestData)); + var testData = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + var sut = new MethodDataSource(dataSource); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testData)).ToArray()).ThrowsExactly(); + } + + public static object NonEnumerableTestData() => new(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs new file mode 100644 index 0000000..15d4cb9 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs @@ -0,0 +1,144 @@ +using AutoFixture.TUnit.Internal; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests.Internal; + +public class PropertyDataSourceTests +{ + [Test] + public async Task SutIsTestDataSource() + { + // Arrange + var sourceProperty = typeof(PropertyDataSourceTests) + .GetProperty(nameof(TestDataPropertyWithMixedValues)); + var sut = new PropertyDataSource(sourceProperty); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + public static IEnumerable TestDataPropertyWithMixedValues => + [ + ["hello", 1, new PropertyHolder { Property = "world" }], + ["foo", 2, new PropertyHolder { Property = "bar" }], + ["Han", 3, new PropertyHolder { Property = "Solo" }] + ]; + + public static object NonEnumerableProperty => new object(); + + [Test] + public async Task ThrowsWhenConstructedWithNullProperty() + { + // Act & Assert + await Assert.That(() => new PropertyDataSource(null!)).ThrowsExactly(); + } + + [Test] + public async Task PropertyIsCorrect() + { + // Arrange + var expected = typeof(PropertyDataSourceTests) + .GetProperty(nameof(TestDataPropertyWithMixedValues)); + var sut = new PropertyDataSource(expected); + + // Act + var result = sut.PropertyInfo; + + // Assert + await Assert.That(result).IsEqualTo(expected); + } + + [Test] + public async Task ThrowsWhenInvokedWithNullTestMethod() + { + // Arrange + var sourceProperty = typeof(PropertyDataSourceTests) + .GetProperty(nameof(TestDataPropertyWithMixedValues)); + var sut = new PropertyDataSource(sourceProperty); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(null!)).ThrowsExactly(); + } + + [Test] + public async Task ThrowsWhenSourceIsNotEnumerable() + { + // Arrange + var sourceProperty = typeof(PropertyDataSourceTests) + .GetProperty(nameof(NonEnumerableProperty)); + var sut = new PropertyDataSource(sourceProperty); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); + + // Act & Assert + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + + .ToArray()).ThrowsExactly(); + } + + [Test] + public async Task GeneratesTestDataMatchingTestParameters() + { + // Arrange + var expected = new[] + { + new object[] { "hello", 1, new RecordType("world") }, + new object[] { "foo", 2, new RecordType("bar") }, + new object[] { "Han", 3, new RecordType("Solo") } + }; + var sourceProperty = typeof(PropertyDataSourceTests) + .GetProperty(nameof(TestDataPropertyWithRecordValues)); + var sut = new PropertyDataSource(sourceProperty); + var method = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithRecordTypeParameter)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + public static IEnumerable TestDataPropertyWithRecordValues => + [ + ["hello", 1, new RecordType("world")], + ["foo", 2, new RecordType("bar")], + ["Han", 3, new RecordType("Solo")] + ]; + + [Test] + public async Task ReturnsNullArguments() + { + // Arrange + var expected = new[] + { + new object[] { null, 1, null }, + new object[] { null, 2, null }, + new object[] { null, 3, null } + }; + var sourceProperty = typeof(PropertyDataSourceTests) + .GetProperty(nameof(TestDataPropertyWithNullValues)); + var sut = new PropertyDataSource(sourceProperty); + var testMethod = typeof(SampleTestType) + .GetMethod(nameof(SampleTestType.TestMethodWithRecordTypeParameter)); + + // Act + var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(result).IsEquivalentTo(expected); + } + + public static IEnumerable TestDataPropertyWithNullValues => + [ + [null, 1, null], + [null, 2, null], + [null, 3, null] + ]; +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs new file mode 100644 index 0000000..7f96fa2 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs @@ -0,0 +1,161 @@ +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests; + +public class MemberAutoDataAttributeScenarioTests +{ + [Test] + [MemberAutoData(nameof(GetSingleStringValueTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetEmptyTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetSingleStringValueTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetStringTestsFromArgument), + parameters: "argument")] + public async Task SingleStringValueTest(string value) + { + await Assert.That(value).IsNotNull(); + await Assert.That(value).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(value)).IsFalse(); + } + + [Test] + [MemberAutoData(nameof(GetMultipleValueTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetMultipleValueTestData))] + public async Task MultipleValueTest(string a, int b, decimal c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(a).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(a)).IsFalse(); + + await Assert.That(b != default, "Value should not be default").IsTrue(); + await Assert.That(c != default, "Value should not be default").IsTrue(); + } + + [Test] + [MemberAutoData(nameof(GetSingleStringValueTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetSingleStringValueTestData))] + public async Task FreezesUninjectedValues( + string a, [Frozen] string b, string c, + PropertyHolder d) + { + // Assert "a" ends with any possible ending from the test data + var aSuffix = a.Split('-').Last(); + await Assert.That(new[] { "one", "two", "three" }).Contains(x => aSuffix == x); + + await Assert.That(b).IsNotNull(); + await Assert.That(b).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(b)).IsFalse(); + + await Assert.That(c).IsEqualTo(b); + + await Assert.That(d).IsNotNull(); + await Assert.That(d.Property).IsEqualTo(b); + } + + [Test] + [MemberAutoData(nameof(GetMultipleValueTestData))] + public async Task InjectsValues([Frozen] string a, + [Frozen] int b, + [Frozen] decimal c, + PropertyHolder a1, + PropertyHolder b1, + PropertyHolder c1) + { + // Assert "a" ends with any possible ending from the test data + var aSuffix = a.Split('-').Last(); + await Assert.That(new[] { "one", "two", "three" }).Contains(x => aSuffix == x); + + await Assert.That(new[] { 22, 75, 19 }).Contains(x => x == b); + await Assert.That(new[] { 25.7m, 228.1m, 137.09m }).Contains(x => x == c); + + await Assert.That(a1).IsNotNull(); + await Assert.That(a1.Property).IsEqualTo(a); + + await Assert.That(b1).IsNotNull(); + await Assert.That(b1.Property).IsEqualTo(b); + + await Assert.That(c1).IsNotNull(); + await Assert.That(c1.Property).IsEqualTo(c); + } + + [Test] + [MemberAutoData(nameof(GetStringValuesTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetStringValuesTestData))] + public async Task DoesNotAlterTestDataValuesWhenFrozen( + [Frozen] string a, string b, string c) + { + var aSuffix = a.Split('-').Last(); + var bSuffix = b.Split('-').Last(); + await Assert.That(new[] { "one", "two", "three" }).Contains(x => aSuffix == x); + await Assert.That(new[] { "uno", "dos", "tres" }).Contains(x => bSuffix == x); + + await Assert.That(b).IsNotEqualTo(a); + await Assert.That(c).IsEqualTo(a); + } + + [Test] + [MemberAutoData(nameof(GetStringValuesTestData))] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetStringValuesTestData))] + public async Task LastInjectedValueIsFrozen( + [Frozen] string a, [Frozen] string b, string c) + { + var aSuffix = a.Split('-').Last(); + var bSuffix = b.Split('-').Last(); + await Assert.That(new[] { "one", "two", "three" }).Contains(x => aSuffix == x); + await Assert.That(new[] { "uno", "dos", "tres" }).Contains(x => bSuffix == x); + + await Assert.That(c).IsNotEqualTo(a); + await Assert.That(c).IsEqualTo(b); + } + + [Test] + [MemberAutoData( + memberType: typeof(TestTypeWithMethodData), + memberName: nameof(TestTypeWithMethodData.GetTestWithComplexTypesData))] + public async Task InjectsComplexTypes( + [Frozen] PropertyHolder a, + PropertyHolder b, + PropertyHolder c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(b).IsNotNull(); + + await Assert.That(b).IsNotSameReferenceAs(a); + await Assert.That(c).IsSameReferenceAs(a); + } + + public static IEnumerable GetSingleStringValueTestData() + { + yield return ["test-one"]; + yield return ["test-two"]; + yield return ["test-three"]; + } + + public static IEnumerable GetMultipleValueTestData() + { + yield return ["test-one", 22, 25.7m]; + yield return ["test-two", 75, 228.1m]; + yield return ["test-three", 19, 137.09m]; + } + + public static IEnumerable GetStringValuesTestData() + { + yield return ["test-one", "test-uno"]; + yield return ["test-two", "test-dos"]; + yield return ["test-three", "test-tres"]; + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs new file mode 100644 index 0000000..79f2712 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs @@ -0,0 +1,408 @@ +using System.Diagnostics.CodeAnalysis; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +[SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local", + Justification = "Using parameter for precondition checks is acceptable in assertions.")] +public class MemberAutoDataAttributeTest +{ + [Test] + public async Task SutIsDataAttribute() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + + // Act + var sut = new MemberAutoDataAttribute(memberName); + + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task InitializedWithMemberNameAndParameters() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + var parameters = new object[] { "value-one", 3, 12.2f }; + + // Act + var sut = new MemberAutoDataAttribute(memberName, parameters); + + // Assert + await Assert.That(sut.MemberName).IsEqualTo(memberName); + await Assert.That(sut.Parameters).IsEqualTo(parameters); + await Assert.That(sut.MemberType).IsNull(); + await Assert.That(sut.FixtureFactory).IsNotNull(); + } + + [Test] + public async Task InitializedWithTypeMemberNameAndParameters() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + var parameters = new object[] { "value-one", 3, 12.2f }; + var testType = typeof(MemberAutoDataAttributeTest); + + // Act + var sut = new MemberAutoDataAttribute(testType, memberName, parameters); + + // Assert + await Assert.That(sut.MemberName).IsEqualTo(memberName); + await Assert.That(sut.Parameters).IsEqualTo(parameters); + await Assert.That(sut.MemberType).IsEqualTo(testType); + await Assert.That(sut.FixtureFactory).IsNotNull(); + } + + [Test] + public async Task ThrowsWhenInitializedWithNullMemberName() + { + // Act & Assert + await Assert.That(() => new MemberAutoDataAttribute(null!)).ThrowsExactly(); + } + + [Test] + public async Task TreatsNullParametersAsArrayWithNullValue() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + + // Act + var actual = new MemberAutoDataAttribute(memberName, null!); + + // Act & Assert + var value = await Assert.That(actual.Parameters).HasSingleItem(); + await Assert.That(value).IsNull(); + } + + [Test] + public void DoesNotThrowWhenInitializedWithNullType() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + + // Act & Assert + _ = new MemberAutoDataAttribute(null!, memberName); + } + + [Test] + public void ThrowsWhenTestMethodNull() + { + // Arrange + var sut = new MemberAutoDataAttribute("memberName"); + + // Act & Assert + Assert.Throws( + () => sut.GenerateDataSources(null!).Select(x => x()).ToArray()); + } + + [Test] + public async Task ThrowsWhenMemberNotEnumerable() + { + // Arrange + var memberName = nameof(TestTypeWithMethodData.NonEnumerableMethod); + var sut = new MemberAutoDataAttribute(memberName); + var method = TestTypeWithMethodData.GetNonEnumerableMethodInfo(); + + // Act & Assert + var ex = Assert.Throws( + () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray() + ); + + await Assert.That(ex.Message).Contains(memberName); + } + + [Test] + public async Task ThrowsWhenMemberNotStatic() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.NonStaticSource); + var sut = new MemberAutoDataAttribute(memberName); + var method = TestTypeWithMethodData.GetNonStaticSourceMethodInfo(); + + // Act & Assert + var ex = Assert.Throws( + () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray() + ); + + await Assert.That(ex.Message).Contains(memberName); + } + + [Test] + public async Task ThrowsWhenMemberDoesNotExist() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + var sut = new MemberAutoDataAttribute(typeof(TestTypeWithMethodData), memberName); + var method = TestTypeWithMethodData.GetMultipleValueTestMethodInfo(); + + // Act & Assert + var ex = Assert.Throws( + () => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)) + .Select(x => x()) + .ToArray()); + await Assert.That(ex.Message).Contains(memberName); + } + + [Test] + public async Task DoesntActivateFixtureImmediately() + { + // Arrange + var memberName = Guid.NewGuid().ToString(); + var wasInvoked = false; + + // Act + _ = new DerivedMemberAutoDataAttribute(() => + { + wasInvoked = true; + return new DelegatingFixture(); + }, memberName); + + // Assert + await Assert.That(wasInvoked).IsFalse(); + } + + [Test] + [Arguments("CreateWithFrozenAndFavorArrays")] + [Arguments("CreateWithFavorArraysAndFrozen")] + [Arguments("CreateWithFrozenAndFavorEnumerables")] + [Arguments("CreateWithFavorEnumerablesAndFrozen")] + [Arguments("CreateWithFrozenAndFavorLists")] + [Arguments("CreateWithFavorListsAndFrozen")] + [Arguments("CreateWithFrozenAndGreedy")] + [Arguments("CreateWithGreedyAndFrozen")] + [Arguments("CreateWithFrozenAndModest")] + [Arguments("CreateWithModestAndFrozen")] + [Arguments("CreateWithFrozenAndNoAutoProperties")] + [Arguments("CreateWithNoAutoPropertiesAndFrozen")] + public async Task GetDataOrdersCustomizationAttributes(string methodName) + { + // Arrange + var method = typeof(TypeWithCustomizationAttributes) + .GetMethod(methodName, [typeof(ConcreteType)])!; + var customizationLog = new List(); + var fixture = new DelegatingFixture + { + OnCustomize = c => customizationLog.Add(c) + }; + + var sut = new DerivedMemberAutoDataAttribute( + () => fixture, + typeof(TestTypeWithMethodData), + nameof(TestTypeWithMethodData.TestDataWithNoValues)); + + // Act + _ = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)) + .Select(x => x()) + .ToArray(); + + // Assert + var composite = await Assert.That(customizationLog[0]).IsAssignableTo(); + await Assert.That(composite.Customizations.First()).IsNotTypeOf(); + await Assert.That(composite.Customizations.Last()).IsAssignableTo(); + } + + [Test] + public async Task GeneratesTestsFromParameterlessMethod() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetSingleStringValueTestData); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = TestTypeWithMethodData.GetSingleStringValueTestMethodInfo(); + var expected = new[] + { + new object[] { "value-one" }, + new object[] { "value-two" }, + new object[] { "value-three" } + }; + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(testData).IsEquivalentTo(expected); + } + + [Test] + public async Task GeneratesTestsFromMethodWithParameter() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetStringTestsFromArgument); + var sut = new MemberAutoDataAttribute(memberName, "value"); + var testMethod = TestTypeWithMethodData.GetStringTestsFromArgumentMethodInfo(); + var expected = new[] + { + new object[] { "value-one" }, + new object[] { "value-two" }, + new object[] { "value-three" } + }; + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + await Assert.That(testData).IsEquivalentTo(expected); + } + + [Test] + public async Task GeneratesTestDataForTestsWithMultipleParameters() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetMultipleValueTestData); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = TestTypeWithMethodData.GetMultipleValueTestMethodInfo(); + var expected = new[] + { + new object[] { "value-one", 12, 23.3m }, + new object[] { "value-two", 38, 12.7m }, + new object[] { "value-three", 94, 52.21m } + }; + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(testData).IsEquivalentTo(expected); + } + + [Test] + public async Task GeneratesMissingDataForTestsWithMultipleParameters() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetSingleStringValueTestData); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = TestTypeWithMethodData.GetMultipleValueTestMethodInfo(); + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + var arguments1 = testData[0]; + var arguments2 = testData[1]; + var arguments3 = testData[2]; + + // Assert + await Assert.That(arguments1.Length).IsEqualTo(3); + await Assert.That(arguments1[0]).IsEqualTo("value-one"); + await Assert.That(arguments1[1]).IsNotEqualTo(0); + await Assert.That(arguments1[2]).IsNotEqualTo(0); + + await Assert.That(arguments2.Length).IsEqualTo(3); + await Assert.That(arguments2[0]).IsEqualTo("value-two"); + await Assert.That(arguments2[1]).IsNotEqualTo(0); + await Assert.That(arguments2[2]).IsNotEqualTo(0); + + await Assert.That(arguments3.Length).IsEqualTo(3); + await Assert.That(arguments3[0]).IsEqualTo("value-three"); + await Assert.That(arguments3[1]).IsNotEqualTo(0); + await Assert.That(arguments3[2]).IsNotEqualTo(0); + } + + [Test] + public async Task GeneratesTestDataWithInjectedParameters() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetDataForTestWithFrozenParameter); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = TestTypeWithMethodData.GetTestWithFrozenParameter(); + var expected = new[] + { + new object[] { "value-one", "value-two", "value-two" }, + new object[] { "value-two", "value-three", "value-three" }, + new object[] { "value-three", "value-one", "value-one" } + }; + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(testData).IsEquivalentTo(expected); + } + + [Test] + public async Task AutoGeneratesValuesForFrozenParameters() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetSingleStringValueTestData); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = TestTypeWithMethodData.GetTestWithFrozenParameter(); + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + var arguments1 = testData[0]; + var arguments2 = testData[1]; + var arguments3 = testData[2]; + + // Assert + await Assert.That(arguments1.Length).IsEqualTo(3); + await Assert.That(arguments1[0]).IsEqualTo("value-one"); + await Assert.That(arguments1[1].ToString()!).IsNotEmpty(); + await Assert.That(arguments1[2]).IsEqualTo(arguments1[1]); + + await Assert.That(arguments2.Length).IsEqualTo(3); + await Assert.That(arguments2[0]).IsEqualTo("value-two"); + await Assert.That(arguments2[1].ToString()!).IsNotEmpty(); + await Assert.That(arguments2[2]).IsEqualTo(arguments2[1]); + + await Assert.That(arguments3.Length).IsEqualTo(3); + await Assert.That(arguments3[0]).IsEqualTo("value-three"); + await Assert.That(arguments3[1].ToString()!).IsNotEmpty(); + await Assert.That(arguments3[2]).IsEqualTo(arguments3[1]); + } + + [Test] + public async Task SupportsInheritedTestDataMembers() + { + // Arrange + const string memberName = nameof(TestTypeWithMethodData.GetMultipleValueTestData); + var sut = new MemberAutoDataAttribute(memberName); + var testMethod = ChildTestTypeMethodData.GetMultipleValueTestMethodInfo(); + var expected = new[] + { + new object[] { "value-one", 12, 23.3m }, + new object[] { "value-two", 38, 12.7m }, + new object[] { "value-three", 94, 52.21m } + }; + + // Act + var testData = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod!)) + .Select(x => x()) + .ToArray(); + + // Assert + await Assert.That(testData).IsEquivalentTo(expected); + } + + public static IEnumerable TestDataWithNullValues + { + get + { + yield return [null, null]; + yield return [string.Empty, null]; + yield return [" ", null]; + } + } + + [Test] + [MemberAutoData(nameof(TestDataWithNullValues))] + public async Task NullTestDataReturned(string a, string b, PropertyHolder c) + { + await Assert.That(string.IsNullOrWhiteSpace(a)).IsTrue(); + await Assert.That(b).IsNull(); + await Assert.That(c).IsNotNull(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs new file mode 100644 index 0000000..4550c8f --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs @@ -0,0 +1,45 @@ +using AutoFixture.Kernel; +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class ModestAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange & Act + var sut = new ModestAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new ModestAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsCorrectResult() + { + // Arrange + var sut = new ModestAttribute(); + var parameter = typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object)])! + .GetParameters().Single(); + + // Act + var result = sut.GetCustomization(parameter); + + // Assert + var invoker = await Assert.That(result).IsAssignableTo(); + await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker.Query).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs new file mode 100644 index 0000000..92791bf --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs @@ -0,0 +1,41 @@ +using TestTypeFoundation; +using TUnit.Assertions.AssertConditions.Throws; + +namespace AutoFixture.TUnit.Tests; + +public class NoAutoPropertiesAttributeTest +{ + [Test] + public async Task SutIsAttribute() + { + // Arrange + // Act + var sut = new NoAutoPropertiesAttribute(); + // Assert + await Assert.That(sut).IsAssignableTo(); + } + + [Test] + public async Task GetCustomizationFromNullParameterThrows() + { + // Arrange + var sut = new NoAutoPropertiesAttribute(); + // Act & assert + await Assert.That(() => + sut.GetCustomization(null)).ThrowsExactly(); + } + + [Test] + public async Task GetCustomizationReturnsTheCorrectResult() + { + // Arrange + var sut = new NoAutoPropertiesAttribute(); + var parameter = TypeWithOverloadedMembers + .GetDoSomethingMethod(typeof(object)) + .GetParameters().Single(); + // Act + var result = sut.GetCustomization(parameter); + // Assert + await Assert.That(result).IsAssignableTo(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Scenario.cs b/tests/AutoFixture.TUnit.Tests/Scenario.cs new file mode 100644 index 0000000..855c5be --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/Scenario.cs @@ -0,0 +1,560 @@ +using System.Collections; +using System.ComponentModel.DataAnnotations; +using AutoFixture.TUnit.Tests.TestTypes; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests; + +public class Scenario +{ + [Test, AutoData] + public async Task AutoDataProvidesCorrectInteger(int primitiveValue) + { + await Assert.That(primitiveValue).IsNotEqualTo(0); + } + + [Test, AutoData] + public async Task AutoDataProvidesCorrectString(string text) + { + await Assert.That(text).StartsWith("text"); + } + + [Test, AutoData] + public async Task AutoDataProvidesCorrectObject(PropertyHolder ph) + { + await Assert.That(ph).IsNotNull(); + await Assert.That(ph.Property).IsNotNull(); + } + + [Test, AutoData] + public async Task AutoDataProvidesMultipleObjects(PropertyHolder ph, SingleParameterType spt) + { + await Assert.That(ph).IsNotNull(); + await Assert.That(ph.Property).IsNotNull(); + + await Assert.That(spt).IsNotNull(); + await Assert.That(spt.Parameter).IsNotNull(); + } + + [Test] + [ArgumentsAutoData("foo")] + [ArgumentsAutoData("foo", "bar")] + public async Task InlineAutoDataUsesSuppliedDataValues(string s1, string s2) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + } + + [Test] + [ArgumentsAutoData("foo")] + [ArgumentsAutoData("foo", "bar")] + public async Task InlineAutoDataSuppliesDataSpecimens(string s1, string s2, MyClass myClass) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + await Assert.That(myClass).IsNotNull(); + } + + [Test] + [ArgumentsAutoData("foo")] + [ArgumentsAutoData("foo", "bar")] + public async Task InlineAutoDataSuppliesDataSpecimensOnlyForNonProvidedValues(string s1, string s2, string s3) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + await Assert.That(s3).IsNotEqualTo("foo"); + await Assert.That(s3).IsNotEqualTo("bar"); + } + + // This test and its associated types is used to document one of the + // InlineAutoDataAttribute constructor overloads. + [Test] + [MyCustomArgumentsAutoData(1337)] + [MyCustomArgumentsAutoData(1337, 7)] + [MyCustomArgumentsAutoData(1337, 7, 42)] +#pragma warning disable xUnit1026 // Test methods should use all of their parameters - it's required by the test logic. + public async Task CustomInlineDataSuppliesExtraValues(int x, int y, int z) +#pragma warning restore xUnit1026 // Test methods should use all of their parameters + { + await Assert.That(x).IsEqualTo(1337); + + // y can vary, so we can't express any meaningful assertion for it. + await Assert.That(z).IsEqualTo(42); + } + + public class MyCustomArgumentsAutoDataAttribute : ArgumentsAutoDataAttribute + { + public MyCustomArgumentsAutoDataAttribute(params object[] values) + : base(() => new Fixture().Customize(new TheAnswer()), values) + { + } + } + + [Test, MemberAutoData(nameof(StringData))] + public async Task MemberAutoDataUsesSuppliedDataValues(string s1, string s2) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + } + + [Test, MemberAutoData(nameof(StringData))] + public async Task MemberAutoDataSuppliesDataSpecimens(string s1, string s2, MyClass myClass) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + await Assert.That(myClass).IsNotNull(); + } + + [Test, MemberAutoData(nameof(StringData))] + public async Task MemberAutoDataSuppliesDataSpecimensOnlyForNonProvidedValues(string s1, string s2, string s3) + { + await Assert.That(s1).IsEqualTo("foo"); + await Assert.That(s2).IsNotNull(); + await Assert.That(s3).IsNotEqualTo("foo"); + await Assert.That(s3).IsNotEqualTo("bar"); + } + + [Test, MemberAutoData(nameof(GetParametrizedData), 21, 38, 43)] + public async Task MemberAutoDataCanBeParametrized(int x, int y, int z) + { + await Assert.That(x).IsEqualTo(21); + await Assert.That(y).IsEqualTo(38); + await Assert.That(z).IsEqualTo(43); + } + + [Test, MyCustomMemberAutoData(nameof(IntData))] + public async Task CustomMemberAutoDataSuppliesExtraValues(int x, int y, int z) + { + await Assert.That(x).IsEqualTo(1337); + await Assert.That(y).IsNotEqualTo(0); + await Assert.That(z).IsEqualTo(42); + } + + [Test, MyCustomMemberAutoData(nameof(GetParametrizedData), 21, 38, 43)] + public async Task CustomMemberAutoDataCanBeParametrized(int x, int y, int z) + { + await Assert.That(x).IsEqualTo(21); + await Assert.That(y).IsEqualTo(38); + await Assert.That(z).IsEqualTo(43); + } + + public static IEnumerable StringData + { + get + { + yield return ["foo"]; + yield return ["foo", "bar"]; + } + } + + public static IEnumerable IntData + { + get + { + yield return [1337]; + yield return [1337, 7]; + yield return [1337, 7, 42]; + } + } + + public static IEnumerable GetParametrizedData(int x, int y, int z) + { + yield return [x, y, z]; + } + + public class MyCustomMemberAutoDataAttribute : MemberAutoDataAttribute + { + public MyCustomMemberAutoDataAttribute(string memberName, params object[] parameters) + : base(() => new Fixture().Customize(new TheAnswer()), memberName, parameters) + { + } + } + + private class TheAnswer : ICustomization + { + public void Customize(IFixture fixture) + { + fixture.Inject(42); + } + } + + [Test, AutoData] + public async Task FreezeFirstParameter([Frozen] Guid g1, Guid g2) + { + await Assert.That(g2).IsEqualTo(g1); + } + + [Test, AutoData] + public async Task FreezeSecondParameterOnlyFreezesSubsequentParameters(Guid g1, [Frozen] Guid g2, Guid g3) + { + await Assert.That(g2).IsNotEqualTo(g1); + await Assert.That(g3).IsNotEqualTo(g1); + + await Assert.That(g3).IsEqualTo(g2); + } + + [Test, AutoData] + public async Task IntroductoryTest(int expectedNumber, MyClass sut) + { + // Arrange + // Act + int result = sut.Echo(expectedNumber); + + // Assert + await Assert.That(result).IsEqualTo(expectedNumber); + } + + [Test, AutoData] + public async Task ModestCreatesParameterWithModestConstructor([Modest] MultiUnorderedConstructorType p) + { + await Assert.That(string.IsNullOrEmpty(p.Text)).IsTrue(); + await Assert.That(p.Number).IsEqualTo(0); + } + + [Test, AutoData] + public async Task GreedyCreatesParameterWithGreedyConstructor([Greedy] MultiUnorderedConstructorType p) + { + await Assert.That(string.IsNullOrEmpty(p.Text)).IsFalse(); + await Assert.That(p.Number).IsNotEqualTo(0); + } + + [Test, AutoData] + public async Task BothFrozenAndGreedyAttributesCanBeAppliedToSameParameter( + [Frozen][Greedy] MultiUnorderedConstructorType p1, MultiUnorderedConstructorType p2) + { + await Assert.That(p1).IsNotNull(); + await Assert.That(string.IsNullOrEmpty(p2.Text)).IsFalse(); + await Assert.That(p2.Number).IsNotEqualTo(0); + } + + [Test, AutoData] + public async Task FavorArraysCausesArrayConstructorToBeInjectedWithFrozenItems([Frozen] int[] numbers, + [FavorArrays] ItemContainer container) + { + await Assert.That(numbers.SequenceEqual(container.Items)).IsTrue(); + } + + [Test, AutoData] + public async Task FreezeFirstParameterShouldAssignSameInstanceToSecondParameter([Frozen] string p1, + string p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByExactTypeShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.ExactType)] ConcreteType p1, + ConcreteType p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByExactTypeShouldNotAssignSameInstanceToSecondParameterOfDifferentType( + [Frozen(Matching.ExactType)] ConcreteType p1, + object p2) + { + await Assert.That(p2).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByDirectBaseTypeShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.DirectBaseType)] ConcreteType p1, + AbstractType p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByDirectBaseTypeShouldNotAssignSameInstanceToSecondParameterOfIndirectBaseType( + [Frozen(Matching.DirectBaseType)] ConcreteType p1, + object p2) + { + await Assert.That(p2).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByDirectBaseTypeShouldNotAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.DirectBaseType)] ConcreteType p1, + ConcreteType p2) + { + await Assert.That(p2).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByExactOrDirectBaseTypeShouldAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.ExactType | Matching.DirectBaseType)] + ConcreteType p1, + ConcreteType p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByInterfaceShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.ImplementedInterfaces)] + NoopInterfaceImplementer p1, + IInterface p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByInterfaceShouldNotAssignSameInstanceToSecondParameterOfNonInterfaceType( + [Frozen(Matching.ImplementedInterfaces)] + NoopInterfaceImplementer p1, + object p2) + { + await Assert.That(p2).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByInterfaceShouldNotAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.ImplementedInterfaces)] + NoopInterfaceImplementer p1, + NoopInterfaceImplementer p2) + { + await Assert.That(p2).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByDirectOrInterfaceShouldAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.ExactType | Matching.ImplementedInterfaces)] + NoopInterfaceImplementer p1, + NoopInterfaceImplementer p2) + { + await Assert.That(p2).IsEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByParameterWithSameNameShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.ParameterName)] string parameter, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsEqualTo(parameter); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByParameterWithDifferentNameShouldNotAssignSameInstanceToSecondParameter( + [Frozen(Matching.ParameterName)] string p1, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByParameterWithDifferentNameShouldNotAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.ParameterName)] string p1, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByPropertyWithSameNameShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.PropertyName)] string property, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsEqualTo(property); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByPropertyWithDifferentNameShouldNotAssignSameInstanceToSecondParameter( + [Frozen(Matching.PropertyName)] string p1, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByPropertyWithDifferentNameShouldNotAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.PropertyName)] string p1, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByFieldWithSameNameShouldAssignSameInstanceToSecondParameter( + [Frozen(Matching.FieldName)] string field, + FieldHolder p2) + { + await Assert.That(p2.Field).IsEqualTo(field); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByFieldWithDifferentNameShouldNotAssignSameInstanceToSecondParameter( + [Frozen(Matching.FieldName)] string p1, + FieldHolder p2) + { + await Assert.That(p2.Field).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByFieldWithDifferentNameShouldNotAssignSameInstanceToSecondParameterOfSameType( + [Frozen(Matching.FieldName)] string p1, + FieldHolder p2) + { + await Assert.That(p2.Field).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithSameNameShouldAssignSameInstanceToMatchingParameter( + [Frozen(Matching.MemberName)] string parameter, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsEqualTo(parameter); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToParameter( + [Frozen(Matching.MemberName)] string p1, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToParameterOfSameType( + [Frozen(Matching.MemberName)] string p1, + SingleParameterType p2) + { + await Assert.That(p2.Parameter).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithSameNameShouldAssignSameInstanceToMatchingProperty( + [Frozen(Matching.MemberName)] string property, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsEqualTo(property); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToProperty( + [Frozen(Matching.MemberName)] string p1, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToPropertyOfSameType( + [Frozen(Matching.MemberName)] string p1, + PropertyHolder p2) + { + await Assert.That(p2.Property).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithSameNameShouldAssignSameInstanceToMatchingField( + [Frozen(Matching.MemberName)] string field, + FieldHolder p2) + { + await Assert.That(p2.Field).IsEqualTo(field); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToField( + [Frozen(Matching.MemberName)] string p1, + FieldHolder p2) + { + await Assert.That(p2.Field).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeFirstParameterByMemberWithDifferentNameShouldNotAssignSameInstanceToFieldOfSameType( + [Frozen(Matching.MemberName)] string p1, + FieldHolder p2) + { + await Assert.That(p2.Field).IsNotEqualTo(p1); + } + + [Test, AutoData] + public async Task FreezeParameterWithStringLengthConstraintShouldCreateConstrainedSpecimen( + [Frozen, StringLength(3)] string p) + { + await Assert.That(p.Length == 3).IsTrue(); + } + + [Test, ClassAutoData(typeof(StringDataClass))] + public async Task ClassAutoDataUsesValuesSuppliedByClass(string s1, string s2, string s3) + { + await Assert.That(new[] { "foo", "dim" }).Contains(s1); + await Assert.That(s2).IsNotEmpty(); + await Assert.That(s3).IsNotEmpty(); + } + + [Test, ClassAutoData(typeof(StringDataClass))] + public async Task ClassAutoDataSuppliesDataSpecimens(string s1, string s2, string s3, MyClass myClass) + { + await Assert.That(s1).IsNotEmpty(); + await Assert.That(s2).IsNotEmpty(); + await Assert.That(s3).IsNotEmpty(); + await Assert.That(myClass).IsNotNull(); + } + + [Test, ClassAutoData(typeof(MixedDataClass))] + public async Task ClassAutoDataSuppliesDataOfMixedTypes(int p1, string p2, PropertyHolder p3, MyClass myClass) + { + await Assert.That(p1).IsNotEqualTo(0); + await Assert.That(p2).IsNotEmpty(); + await Assert.That(p3).IsNotNull(); + await Assert.That(p3.Property).IsNotEmpty(); + await Assert.That(myClass).IsNotNull(); + } + + [Test, ClassAutoData(typeof(ParameterizedDataClass), 28, "bar", 93.102)] + public async Task ClassAutoDataCanBeParameterized(int p1, string p2, double p3, RecordType p4) + { + var actual = new object[] { p1, p2, p3 }; + var expected = new object[] { 28, "bar", 93.102 }; + + await Assert.That(actual).IsEquivalentTo(expected); + await Assert.That(p4).IsNotNull(); + } + + public class StringDataClass : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return ["foo", "bar", "foobar"]; + yield return ["dim", "sum", "dimsum"]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + } + + public class MixedDataClass : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return [1]; + yield return [4, "testValue"]; + yield return [20, "otherValue", new PropertyHolder { Property = "testValue1" }]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + } + + public class ParameterizedDataClass : IEnumerable + { + private readonly int p1; + private readonly string p2; + private readonly double p3; + + public ParameterizedDataClass(int p1, string p2, double p3) + { + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + } + + public IEnumerator GetEnumerator() + { + yield return [this.p1, this.p2, this.p3]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ChildTestTypeMethodData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ChildTestTypeMethodData.cs new file mode 100644 index 0000000..350cb9e --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ChildTestTypeMethodData.cs @@ -0,0 +1,25 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +/// +/// Created to test whether MemberAutoDataAttribute can discover static test data members from parent classes. +/// +public class ChildTestTypeMethodData : TestTypeWithMethodData +{ + public new async Task MultipleValueTest(string a, int b, decimal c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(a).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(a)).IsFalse(); + + await Assert.That(b != 0, "Value should not be default").IsTrue(); + await Assert.That(c != 0, "Value should not be default").IsTrue(); + } + + public static new MethodInfo GetMultipleValueTestMethodInfo() + { + return typeof(ChildTestTypeMethodData) + .GetMethod(nameof(MultipleValueTest)); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs new file mode 100644 index 0000000..276aca2 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs @@ -0,0 +1,15 @@ +using System.Collections; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class ClassWithEmptyTestData : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return []; + yield return []; + yield return []; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs new file mode 100644 index 0000000..0180e82 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs @@ -0,0 +1,15 @@ +using System.Collections; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class ClassWithNullTestData : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return null; + yield return null; + yield return null; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs new file mode 100644 index 0000000..886ec48 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs @@ -0,0 +1,21 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class CompositeTypeWithOverloadedConstructors +{ + public CompositeTypeWithOverloadedConstructors(IEnumerable items) + { + this.Items = items; + } + + public CompositeTypeWithOverloadedConstructors(params T[] items) + { + this.Items = items; + } + + public CompositeTypeWithOverloadedConstructors(IList items) + { + this.Items = items; + } + + public IEnumerable Items { get; } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs new file mode 100644 index 0000000..d297a7c --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs @@ -0,0 +1,16 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class DelegatingCustomization : ICustomization +{ + internal DelegatingCustomization() + { + this.OnCustomize = _ => { }; + } + + public void Customize(IFixture fixture) + { + this.OnCustomize(fixture); + } + + internal Action OnCustomize { get; set; } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs new file mode 100644 index 0000000..01b6039 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs @@ -0,0 +1,18 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class DelegatingCustomizeAttribute : CustomizeAttribute +{ + public DelegatingCustomizeAttribute() + { + this.OnGetCustomization = p => new DelegatingCustomization(); + } + + public override ICustomization GetCustomization(ParameterInfo parameter) + { + return this.OnGetCustomization(parameter); + } + + public Func OnGetCustomization { get; set; } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs new file mode 100644 index 0000000..136c159 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs @@ -0,0 +1,13 @@ +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DelegatingDataSource : AutoFixtureDataSourceAttribute, IDataSource +{ + public IEnumerable TestData { get; set; } = Array.Empty(); + + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return this.TestData; + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs new file mode 100644 index 0000000..a77d9e1 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs @@ -0,0 +1,90 @@ +using AutoFixture.Dsl; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class DelegatingFixture : IFixture +{ + private readonly List customizations = new(); + private readonly List residueCollectors = new(); + + public IList Behaviors => throw new InvalidOperationException(); + + public IList Customizations => this.customizations; + + public bool OmitAutoProperties { get; set; } + + public int RepeatCount { get; set; } + + public IList ResidueCollectors => this.residueCollectors; + + public void AddManyTo(ICollection collection, Func creator) + { + throw new InvalidOperationException(); + } + + public void AddManyTo(ICollection collection) + { + throw new InvalidOperationException(); + } + + public void AddManyTo(ICollection collection, int repeatCount) + { + throw new InvalidOperationException(); + } + + public ICustomizationComposer Build() + { + throw new InvalidOperationException(); + } + + public IFixture Customize(ICustomization customization) + { + this.OnCustomize?.Invoke(customization); + return this; + } + + public void Customize(Func, ISpecimenBuilder> composerTransformation) + { + throw new InvalidOperationException(); + } + + public void Inject(T item) + { + throw new InvalidOperationException(); + } + + public void Register(Func creator) + { + throw new InvalidOperationException(); + } + + public void Register(Func creator) + { + throw new InvalidOperationException(); + } + + public void Register(Func creator) + { + throw new InvalidOperationException(); + } + + public void Register(Func creator) + { + throw new InvalidOperationException(); + } + + public void Register(Func creator) + { + throw new InvalidOperationException(); + } + + public object Create(object request, ISpecimenContext context) + { + return this.OnCreate(request, context); + } + + internal Func OnCreate { get; set; } = (_, _) => new object(); + + internal Action OnCustomize { get; set; } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs new file mode 100644 index 0000000..06d2058 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs @@ -0,0 +1,13 @@ +using AutoFixture.TUnit.Internal; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DelegatingMemberDataSource : MemberDataSource +{ + public DelegatingMemberDataSource(Type type, string name, params object[] arguments) + : base(type, name, arguments) + { + } + + public DataSource GetSource() => this.Source; +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs new file mode 100644 index 0000000..c5d6e79 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs @@ -0,0 +1,13 @@ +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class DelegatingSpecimenBuilder : ISpecimenBuilder +{ + public object Create(object request, ISpecimenContext context) + { + return this.OnCreate(request, context); + } + + internal Func OnCreate { get; set; } = (_, _) => new object(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs new file mode 100644 index 0000000..b8d688b --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs @@ -0,0 +1,22 @@ +using System.Collections; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DelegatingTestData : IEnumerable +{ + private readonly List data; + + public DelegatingTestData(params object[][] data) + { + this.data = data.ToList(); + } + + public DelegatingTestData(IEnumerable data) + { + this.data = data as List ?? data.ToList(); + } + + public IEnumerator GetEnumerator() => this.data.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs new file mode 100644 index 0000000..d4210e1 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs @@ -0,0 +1,9 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class DerivedArgumentsAutoDataAttribute : ArgumentsAutoDataAttribute +{ + public DerivedArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) + : base(fixtureFactory, values) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs new file mode 100644 index 0000000..47f13c8 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs @@ -0,0 +1,9 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DerivedAutoDataAttribute : AutoDataAttribute +{ + public DerivedAutoDataAttribute(Func fixtureFactory) + : base(fixtureFactory) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs new file mode 100644 index 0000000..4eadeb0 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs @@ -0,0 +1,14 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DerivedClassAutoDataAttribute : ClassAutoDataAttribute +{ + public DerivedClassAutoDataAttribute(Type sourceType) + : base(sourceType) + { + } + + public DerivedClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) + : base(fixtureFactory, sourceType, parameters) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs new file mode 100644 index 0000000..4a91a3a --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs @@ -0,0 +1,14 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class DerivedMemberAutoDataAttribute : MemberAutoDataAttribute +{ + public DerivedMemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) + : base(fixtureFactory, memberName, parameters) + { + } + + public DerivedMemberAutoDataAttribute(Func fixtureFactory, Type memberType, string memberName, params object[] parameters) + : base(fixtureFactory, memberType, memberName, parameters) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs new file mode 100644 index 0000000..b9a8f61 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs @@ -0,0 +1,13 @@ +using System.Collections; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class EmptyClassData : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield break; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ExampleTestClass.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ExampleTestClass.cs new file mode 100644 index 0000000..8f3b637 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ExampleTestClass.cs @@ -0,0 +1,22 @@ +using System.Diagnostics.CodeAnalysis; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class ExampleTestClass +{ + [SuppressMessage("Usage", "xUnit1013:Public method should be marked as test", + Justification = "This test method is used through reflection.")] + public void TestMethod(int a, string b, EnumType c, Tuple d) + { + } +} + +public class ExampleTestClass +{ + [SuppressMessage("Usage", "xUnit1013:Public method should be marked as test", + Justification = "This test method is used through reflection.")] + public void TestMethod(T1 a, T2 b, T3 c, T4 d) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs new file mode 100644 index 0000000..b73580f --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs @@ -0,0 +1,20 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class FakeDataAttribute : AutoFixtureDataSourceAttribute +{ + private readonly MethodInfo expectedMethod; + private readonly IEnumerable output; + + public FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) + { + this.expectedMethod = expectedMethod; + this.output = output; + } + + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return this.output; + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs new file mode 100644 index 0000000..d441ca0 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs @@ -0,0 +1,11 @@ +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class FixedParameterBuilder : FilteringSpecimenBuilder +{ + public FixedParameterBuilder(string name, T value) + : base(new FixedBuilder(value), new ParameterSpecification(typeof(T), name)) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs new file mode 100644 index 0000000..fd208b3 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs @@ -0,0 +1,53 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal abstract class InlineAttributeTestData +{ + protected static DerivedArgumentsAutoDataAttribute CreateAttributeWithFakeFixture( + object[] inlineValues, + params (string ParameterName, object Value)[] parameters) + { + return new DerivedArgumentsAutoDataAttribute( + fixtureFactory: () => new DelegatingFixture { OnCreate = OnCreateParameter }, + values: inlineValues); + + object OnCreateParameter(object request, ISpecimenContext context) + { + if (request is not ParameterInfo parameterInfo) + throw new InvalidOperationException(); + + return parameters + .Where(x => x.ParameterName == parameterInfo.Name) + .Select(x => x.Value).FirstOrDefault(); + } + } + + protected static DerivedArgumentsAutoDataAttribute CreateAttribute( + object[] inlineValues, + params (string ParameterName, object Value)[] parameters) + { + return new DerivedArgumentsAutoDataAttribute( + () => new Fixture().Customize(CreateCustomization()), + inlineValues); + + ICustomization CreateCustomization() + { + var builders = parameters + .Select(x => new FilteringSpecimenBuilder( + builder: new FixedBuilder(x.Value), + specification: new ParameterSpecification( + new ParameterNameCriterion(x.ParameterName)))) + .ToList(); + + return new DelegatingCustomization + { + OnCustomize = f => f.Customizations + .Insert(0, new CompositeSpecimenBuilder(builders)) + }; + } + } + + public abstract IEnumerable GetData(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs new file mode 100644 index 0000000..8a92b3d --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs @@ -0,0 +1,32 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class InlineFrozenValuesTestData : InlineAttributeTestData<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, + object[] expected)> +{ + public override IEnumerable<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, + object[] expected)> GetData() + { + // All values provided by fixture + yield return + ( + CreateAttribute([], ("a", "string_a0"), ("b", "string_b0")), + TestTypeWithMemberDataSource.GetTestWithFrozenParameter(), + ["string_a0", "string_b0", "string_b0"]); + + // First parameter injected; Frozen parameter generated + yield return + ( + CreateAttribute(["string_a1"], ("b", "string_b1")), + TestTypeWithMemberDataSource.GetTestWithFrozenParameter(), + ["string_a1", "string_b1", "string_b1"]); + + // Frozen parameter is injected + yield return + ( + CreateAttribute(["string_a2", "string_b2"]), + TestTypeWithMemberDataSource.GetTestWithFrozenParameter(), + ["string_a2", "string_b2", "string_b2"]); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs new file mode 100644 index 0000000..2c56f77 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs @@ -0,0 +1,32 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class InlinePrimitiveValuesTestData : InlineAttributeTestData<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, + object[] expected)> +{ + public override IEnumerable<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, + object[] expected)> GetData() + { + // All values provided by fixture + yield return + ( + CreateAttributeWithFakeFixture([], ("a", "parameter_a1"), ("b", 31), ("c", 54.38m)), + TestTypeWithMemberDataSource.GetMultipleValueTestMethodInfo(), + ["parameter_a1", 31, 54.38m]); + + // Some parameters injected, some provided by fixture + yield return + ( + CreateAttributeWithFakeFixture(["parameter_a2"], ("b", 22), ("c", 817.218m)), + TestTypeWithMemberDataSource.GetMultipleValueTestMethodInfo(), + ["parameter_a2", 22, 817.218m]); + + // All parameters injected + yield return + ( + CreateAttributeWithFakeFixture(["parameter_a3", 13, 332.009m]), + TestTypeWithMemberDataSource.GetMultipleValueTestMethodInfo(), + ["parameter_a3", 13, 332.009m]); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs new file mode 100644 index 0000000..e6b2243 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs @@ -0,0 +1,18 @@ +using System.Collections; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class MixedTypeClassData : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return []; + yield return [9]; + yield return [12, "test-12"]; + yield return [223, "test-17", EnumType.Third]; + yield return [-95, "test-92", EnumType.Second, new Tuple("myValue", 5)]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/MyClass.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/MyClass.cs new file mode 100644 index 0000000..c955db3 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/MyClass.cs @@ -0,0 +1,6 @@ +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class MyClass +{ + public T Echo(T item) => item; +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs new file mode 100644 index 0000000..18ab5b2 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs @@ -0,0 +1,28 @@ +using System.Reflection; +using AutoFixture.Kernel; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class ParameterNameCriterion : IEquatable +{ + public ParameterNameCriterion(string name) + : this(new Criterion(name, StringComparer.Ordinal)) + { + } + + public ParameterNameCriterion(IEquatable nameCriterion) + { + this.NameCriterion = nameCriterion ?? throw new ArgumentNullException(nameof(nameCriterion)); + } + + /// + /// The name criterion originally passed in via the class' constructor. + /// + public IEquatable NameCriterion { get; } + + public bool Equals(ParameterInfo other) + { + return other is not null + && this.NameCriterion.Equals(other.Name); + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs new file mode 100644 index 0000000..59d2452 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs @@ -0,0 +1,26 @@ +using System.Collections; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class ParameterizedClassData : IEnumerable +{ + private readonly int p1; + private readonly string p2; + private readonly EnumType p3; + + public ParameterizedClassData(int p1, string p2, EnumType p3) + { + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + } + + public IEnumerator GetEnumerator() + { + yield return [this.p1, this.p2, this.p3]; + yield return [this.p1, this.p2, this.p3]; + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/SampleTestType.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/SampleTestType.cs new file mode 100644 index 0000000..7e5ec85 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/SampleTestType.cs @@ -0,0 +1,38 @@ +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class SampleTestType +{ + public void TestMethodWithoutParameters() + { + } + + public void TestMethodWithSingleParameter(string value) + { + } + + public void TestMethodWithMultipleParameters(string a, int b, double c) + { + } + + public void TestMethodWithReferenceTypeParameter(string a, int b, PropertyHolder c) + { + } + + public void TestMethodWithRecordTypeParameter(string a, int b, RecordType c) + { + } + + public void TestMethodWithCollectionParameter(string a, int b, IEnumerable c) + { + } + + public void TestMethodWithCustomizedParameter([Frozen] string a, int b, PropertyHolder c) + { + } + + public void TestMethodWithMultipleCustomizations([Frozen] string a, [Frozen] int b, [Greedy][Frozen] PropertyHolder c) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMemberDataSource.cs new file mode 100644 index 0000000..d2baa40 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMemberDataSource.cs @@ -0,0 +1,37 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class TestTypeWithMemberDataSource +{ + [SuppressMessage("Usage", "xUnit1013:Public method should be marked as test", + Justification = "Test is invoked through reflection.")] + public async Task MultipleValueTest(string a, int b, decimal c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(a).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(a)).IsFalse(); + + await Assert.That(b != 0, "Value should not be default").IsTrue(); + await Assert.That(c != 0, "Value should not be default").IsTrue(); + } + + public async Task TestWithFrozenParameter(string a, [Frozen] string b, string c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(b).IsNotNull(); + await Assert.That(c).IsNotNull(); + + await Assert.That(b).IsNotEqualTo(a); + await Assert.That(c).IsEqualTo(b); + } + + public static MethodInfo GetMultipleValueTestMethodInfo() => + typeof(TestTypeWithMemberDataSource) + .GetMethod(nameof(MultipleValueTest)); + + public static MethodInfo GetTestWithFrozenParameter() => + typeof(TestTypeWithMemberDataSource) + .GetMethod(nameof(TestWithFrozenParameter)); +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs new file mode 100644 index 0000000..5d56037 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs @@ -0,0 +1,159 @@ +using System.Reflection; +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class TestTypeWithMethodData +{ + public IEnumerable NonStaticSource() + { + yield return [new object()]; + yield return [new object()]; + yield return [new object()]; + } + + public static MethodInfo GetNonStaticSourceMethodInfo() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(NonStaticSource)); + } + + public static object NonEnumerableMethod() + { + return new object(); + } + + public static MethodInfo GetNonEnumerableMethodInfo() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(NonEnumerableMethod)); + } + + public static IEnumerable TestDataWithNoValues() + { + yield return []; + yield return []; + yield return []; + } + + public async Task SingleStringValueTest(string value) + { + await Assert.That(value).IsNotNull(); + await Assert.That(value).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(value)).IsFalse(); + } + + public static MethodInfo GetSingleStringValueTestMethodInfo() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(SingleStringValueTest)); + } + + public static IEnumerable GetSingleStringValueTestData() + { + yield return ["value-one"]; + yield return ["value-two"]; + yield return ["value-three"]; + } + + public static IEnumerable GetStringTestsFromArgument(string argument) + { + yield return [argument + "-one"]; + yield return [argument + "-two"]; + yield return [argument + "-three"]; + } + + public static MethodInfo GetStringTestsFromArgumentMethodInfo() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(GetStringTestsFromArgument)); + } + + public async Task MultipleValueTest(string a, int b, decimal c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(a).IsNotEmpty(); + await Assert.That(string.IsNullOrWhiteSpace(a)).IsFalse(); + + await Assert.That(b != 0, "Value should not be default").IsTrue(); + await Assert.That(c != 0, "Value should not be default").IsTrue(); + } + + public static MethodInfo GetMultipleValueTestMethodInfo() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(MultipleValueTest)); + } + + public static IEnumerable GetMultipleValueTestData() + { + yield return ["value-one", 12, 23.3m]; + yield return ["value-two", 38, 12.7m]; + yield return ["value-three", 94, 52.21m]; + } + + public async Task TestWithFrozenParameter(string a, [Frozen] string b, string c) + { + await Assert.That(a).IsNotNull(); + await Assert.That(b).IsNotNull(); + await Assert.That(c).IsNotNull(); + + await Assert.That(b).IsNotEqualTo(a); + await Assert.That(c).IsEqualTo(b); + } + + public static IEnumerable GetDataForTestWithFrozenParameter() + { + yield return ["value-one", "value-two"]; + yield return ["value-two", "value-three"]; + yield return ["value-three", "value-one"]; + } + + public static MethodInfo GetTestWithFrozenParameter() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(TestWithFrozenParameter)); + } + + public async Task TestWithComplexTypes([Frozen] PropertyHolder a, PropertyHolder b) + { + await Assert.That(a).IsNotNull(); + await Assert.That(b).IsNotNull(); + + await Assert.That(b).IsSameReferenceAs(a); + } + + public static IEnumerable GetTestWithComplexTypesData() + { + yield return + [ + new PropertyHolder { Property = "1647400C-9011-4158-BA5A-F841185AF6EF" }, + new PropertyHolder() + ]; + yield return + [ + new PropertyHolder { Property = "E0F5F4F1-4B6B-4B6B-8F4A-7C0F6F4F4F4F" }, + new PropertyHolder { Property = "00000000-0000-0000-0000-000000000000" } + ]; + yield return + [ + new PropertyHolder { Property = "B0B0B0B0-B0B0-B0B0-B0B0-B0B0B0B0B0B0" }, + new PropertyHolder { Property = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" } + ]; + } + + public static MethodInfo GetTestWithComplexTypes() + { + return typeof(TestTypeWithMethodData) + .GetMethod(nameof(TestWithComplexTypes)); + } + + public static IEnumerable GetStringValuesTestData() + { + yield return ["test-one", "test-uno"]; + yield return ["test-two", "test-dos"]; + yield return ["test-three", "test-tres"]; + } + + public static IEnumerable GetEmptyTestData() => []; +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithCustomizationAttributes.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithCustomizationAttributes.cs new file mode 100644 index 0000000..aa2ff5a --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithCustomizationAttributes.cs @@ -0,0 +1,54 @@ +using TestTypeFoundation; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +internal class TypeWithCustomizationAttributes +{ + public void CreateWithFrozenAndFavorArrays([Frozen, FavorArrays] ConcreteType sut) + { + } + + public void CreateWithFavorArraysAndFrozen([FavorArrays, Frozen] ConcreteType sut) + { + } + + public void CreateWithFrozenAndFavorEnumerables([Frozen, FavorEnumerables] ConcreteType sut) + { + } + + public void CreateWithFavorEnumerablesAndFrozen([FavorEnumerables, Frozen] ConcreteType sut) + { + } + + public void CreateWithFrozenAndFavorLists([Frozen, FavorLists] ConcreteType sut) + { + } + + public void CreateWithFavorListsAndFrozen([FavorLists, Frozen] ConcreteType sut) + { + } + + public void CreateWithFrozenAndGreedy([Frozen, Greedy] ConcreteType sut) + { + } + + public void CreateWithGreedyAndFrozen([Greedy, Frozen] ConcreteType sut) + { + } + + public void CreateWithFrozenAndModest([Frozen, Modest] ConcreteType sut) + { + } + + public void CreateWithModestAndFrozen([Modest, Frozen] ConcreteType sut) + { + } + + public void CreateWithFrozenAndNoAutoProperties([Frozen, NoAutoProperties] ConcreteType sut) + { + } + + public void CreateWithNoAutoPropertiesAndFrozen([NoAutoProperties, Frozen] ConcreteType sut) + { + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithIParameterCustomizationSourceUsage.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithIParameterCustomizationSourceUsage.cs new file mode 100644 index 0000000..8099949 --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/TypeWithIParameterCustomizationSourceUsage.cs @@ -0,0 +1,26 @@ +using System.Reflection; + +namespace AutoFixture.TUnit.Tests.TestTypes; + +public class TypeWithIParameterCustomizationSourceUsage +{ + public void DecoratedMethod([CustomizationSource] int arg) + { + } + + [AttributeUsage(AttributeTargets.All)] + public class CustomizationSourceAttribute : Attribute, IParameterCustomizationSource + { + public ICustomization GetCustomization(ParameterInfo parameter) + { + return new Customization(); + } + } + + public class Customization : ICustomization + { + public void Customize(IFixture fixture) + { + } + } +} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/UnitTest1.cs b/tests/AutoFixture.TUnit.Tests/UnitTest1.cs deleted file mode 100644 index 45c769c..0000000 --- a/tests/AutoFixture.TUnit.Tests/UnitTest1.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace AutoFixture.TUnit.Tests; - -public class UnitTest1 -{ - [Test] - public async Task Test1() - { - // Arrange - var sut = new Class1(); - - // Assert - await Assert.That(sut).IsNotNull(); - } -} \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/ValueTaskExtensions.cs b/tests/AutoFixture.TUnit.Tests/ValueTaskExtensions.cs new file mode 100644 index 0000000..da5da6c --- /dev/null +++ b/tests/AutoFixture.TUnit.Tests/ValueTaskExtensions.cs @@ -0,0 +1,20 @@ +namespace AutoFixture.TUnit.Tests; + +internal static class ValueTaskExtensions +{ + /// + /// Wraps the value in a . + /// + /// The value to be wrapped. + /// The generic type of the value task. + /// Returns a completed instance. + public static ValueTask ToValueTask(this T value) => new(value); + + /// + /// Wraps the task in a . + /// + /// The task to be wrapped. + /// The generic type of the value task. + /// Returns a instance. + public static ValueTask ToValueTask(this Task task) => new(task); +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs new file mode 100644 index 0000000..8b46b99 --- /dev/null +++ b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public abstract class AbstractClassWithPublicConstructor + { + public AbstractClassWithPublicConstructor() + { + } + } +} diff --git a/tests/TestTypeFoundation/AbstractGenericType.cs b/tests/TestTypeFoundation/AbstractGenericType.cs new file mode 100644 index 0000000..3da5692 --- /dev/null +++ b/tests/TestTypeFoundation/AbstractGenericType.cs @@ -0,0 +1,12 @@ +namespace TestTypeFoundation +{ + public abstract class AbstractGenericType + { + protected AbstractGenericType(T t) + { + this.Value = t; + } + + public T Value { get; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractType.cs b/tests/TestTypeFoundation/AbstractType.cs new file mode 100644 index 0000000..846da8e --- /dev/null +++ b/tests/TestTypeFoundation/AbstractType.cs @@ -0,0 +1,19 @@ +namespace TestTypeFoundation +{ + public abstract class AbstractType + { + protected AbstractType() + { + } + + public object Property1 { get; set; } + + public object Property2 { get; set; } + + public object Property3 { get; set; } + + public virtual object Property4 { get; set; } + + public object Field1; + } +} diff --git a/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs new file mode 100644 index 0000000..b6ce321 --- /dev/null +++ b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs @@ -0,0 +1,17 @@ +namespace TestTypeFoundation +{ + public abstract class AbstractTypeWithConstructorWithMultipleParameters + { + protected AbstractTypeWithConstructorWithMultipleParameters( + T1 parameter1, + T2 parameter2) + { + this.Property1 = parameter1; + this.Property2 = parameter2; + } + + public T1 Property1 { get; } + + public T2 Property2 { get; } + } +} diff --git a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs new file mode 100644 index 0000000..45fc4d1 --- /dev/null +++ b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs @@ -0,0 +1,17 @@ +namespace TestTypeFoundation +{ + public abstract class AbstractTypeWithNonDefaultConstructor + { + protected AbstractTypeWithNonDefaultConstructor(T value) + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + this.Property = value; + } + + public T Property { get; } + } +} diff --git a/tests/TestTypeFoundation/ActivityScope.cs b/tests/TestTypeFoundation/ActivityScope.cs new file mode 100644 index 0000000..c1896fe --- /dev/null +++ b/tests/TestTypeFoundation/ActivityScope.cs @@ -0,0 +1,46 @@ +namespace TestTypeFoundation +{ + [Flags] + public enum ActivityScope : long + { + /// + /// Undefined scope. + /// + Undefined = 0, + + /// + /// The OnDuty activity has its own special scope. + /// + OnDuty = 0x01, + + /// + /// The OffDuty activity has its own special scope. + /// + OffDuty = 0x02, + + /// + /// A standalone has no parent or children. + /// + Standalone = 0x04, + + /// + /// A parent activity can have one or more child activities.. + /// + Parent = 0x08, + + /// + /// A child activity has a parent activity. + /// + Child = 0x10, + + /// + /// The set of all scopes that are allowed when there is no open Parent activity. + /// + AllInitiatingScopes = Parent | Standalone, + + /// + /// The set all valid scopes. + /// + All = OnDuty | OffDuty | Standalone | Parent | Child, + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/CollectionHolder.cs b/tests/TestTypeFoundation/CollectionHolder.cs new file mode 100644 index 0000000..27bdac4 --- /dev/null +++ b/tests/TestTypeFoundation/CollectionHolder.cs @@ -0,0 +1,12 @@ +namespace TestTypeFoundation +{ + public class CollectionHolder + { + public CollectionHolder() + { + this.Collection = new List(); + } + + public ICollection Collection { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/CompositeType.cs b/tests/TestTypeFoundation/CompositeType.cs new file mode 100644 index 0000000..53ea252 --- /dev/null +++ b/tests/TestTypeFoundation/CompositeType.cs @@ -0,0 +1,22 @@ +namespace TestTypeFoundation +{ + public class CompositeType : AbstractType + { + public CompositeType(IEnumerable types) + : this(types.ToArray()) + { + } + + public CompositeType(params AbstractType[] types) + { + if (types == null) + { + throw new ArgumentNullException(nameof(types)); + } + + this.Types = types; + } + + public IEnumerable Types { get; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ConcreteType.cs b/tests/TestTypeFoundation/ConcreteType.cs new file mode 100644 index 0000000..acae971 --- /dev/null +++ b/tests/TestTypeFoundation/ConcreteType.cs @@ -0,0 +1,39 @@ +namespace TestTypeFoundation +{ + public class ConcreteType : AbstractType + { + public ConcreteType() + { + } + + public ConcreteType(object obj) + { + this.Property1 = obj; + } + + public ConcreteType(object obj1, object obj2) + { + this.Property1 = obj1; + this.Property2 = obj2; + } + + public ConcreteType(object obj1, object obj2, object obj3) + { + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; + } + + public ConcreteType(object obj1, object obj2, object obj3, object obj4) + { + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; + this.Property4 = obj4; + } + + public override object Property4 { get; set; } + + public object Property5 { get; set; } + } +} diff --git a/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs b/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs new file mode 100644 index 0000000..7ca5f15 --- /dev/null +++ b/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs @@ -0,0 +1,13 @@ +namespace TestTypeFoundation +{ + public class ConcreteTypeWithPrivateParameterlessConstructor + { + private ConcreteTypeWithPrivateParameterlessConstructor() + { + } + + public ConcreteTypeWithPrivateParameterlessConstructor(object obj) + { + } + } +} diff --git a/tests/TestTypeFoundation/DoubleFieldHolder.cs b/tests/TestTypeFoundation/DoubleFieldHolder.cs new file mode 100644 index 0000000..421f89d --- /dev/null +++ b/tests/TestTypeFoundation/DoubleFieldHolder.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public class DoubleFieldHolder + { + public T1 Field1; + + public T2 Field2; + } +} diff --git a/tests/TestTypeFoundation/DoubleParameterType.cs b/tests/TestTypeFoundation/DoubleParameterType.cs new file mode 100644 index 0000000..3fa8e12 --- /dev/null +++ b/tests/TestTypeFoundation/DoubleParameterType.cs @@ -0,0 +1,15 @@ +namespace TestTypeFoundation +{ + public class DoubleParameterType + { + public DoubleParameterType(T1 parameter1, T2 parameter2) + { + this.Parameter1 = parameter1; + this.Parameter2 = parameter2; + } + + public T1 Parameter1 { get; private set; } + + public T2 Parameter2 { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/DoublePropertyHolder.cs b/tests/TestTypeFoundation/DoublePropertyHolder.cs new file mode 100644 index 0000000..5b2ca12 --- /dev/null +++ b/tests/TestTypeFoundation/DoublePropertyHolder.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public class DoublePropertyHolder + { + public T1 Property1 { get; set; } + + public T2 Property2 { get; set; } + } +} diff --git a/tests/TestTypeFoundation/EmptyEnum.cs b/tests/TestTypeFoundation/EmptyEnum.cs new file mode 100644 index 0000000..680c38e --- /dev/null +++ b/tests/TestTypeFoundation/EmptyEnum.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public enum EmptyEnum + { + // this must not contain any values + } +} diff --git a/tests/TestTypeFoundation/EnumType.cs b/tests/TestTypeFoundation/EnumType.cs new file mode 100644 index 0000000..d5b041f --- /dev/null +++ b/tests/TestTypeFoundation/EnumType.cs @@ -0,0 +1,58 @@ +namespace TestTypeFoundation +{ + public enum EnumType + { + First = 1, + Second = 2, + Third = 3 + } + + public enum ByteEnumType : byte + { + First = 99, + Second, + Third + } + + public enum SByteEnumType : sbyte + { + First = -98, + Second, + Third + } + + public enum ShortEnumType : short + { + First = 100, + Second, + Third + } + + public enum UShortEnumType : ushort + { + First = 1, + Second, + Third + } + + public enum UIntEnumType : uint + { + First, + Second, + Third + } + + public enum LongEnumType : long + { + First = (long)int.MaxValue + 1, + Second, + Third + } + + public enum ULongEnumType : ulong + { + First = 1, + Second, + Third + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/EqualityResponder.cs b/tests/TestTypeFoundation/EqualityResponder.cs new file mode 100644 index 0000000..c146419 --- /dev/null +++ b/tests/TestTypeFoundation/EqualityResponder.cs @@ -0,0 +1,22 @@ +namespace TestTypeFoundation +{ + public class EqualityResponder + { + private readonly bool equals; + + public EqualityResponder(bool equals) + { + this.equals = equals; + } + + public override bool Equals(object obj) + { + return this.equals; + } + + public override int GetHashCode() + { + return this.equals.GetHashCode(); + } + } +} diff --git a/tests/TestTypeFoundation/FieldHolder.cs b/tests/TestTypeFoundation/FieldHolder.cs new file mode 100644 index 0000000..540369a --- /dev/null +++ b/tests/TestTypeFoundation/FieldHolder.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace TestTypeFoundation +{ + public class FieldHolder + { + public T Field; + + public static FieldInfo GetField() + { + return typeof(FieldHolder) + .GetRuntimeField(nameof(Field)); + } + } +} diff --git a/tests/TestTypeFoundation/GenericType.cs b/tests/TestTypeFoundation/GenericType.cs new file mode 100644 index 0000000..208b49a --- /dev/null +++ b/tests/TestTypeFoundation/GenericType.cs @@ -0,0 +1,18 @@ +namespace TestTypeFoundation +{ + public class GenericType + where T : class + { + public GenericType(T t) + { + if (t == null) + { + throw new ArgumentNullException(nameof(t)); + } + + this.Value = t; + } + + private T Value { get; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedConstructorHost.cs b/tests/TestTypeFoundation/GuardedConstructorHost.cs new file mode 100644 index 0000000..a8e1162 --- /dev/null +++ b/tests/TestTypeFoundation/GuardedConstructorHost.cs @@ -0,0 +1,18 @@ +namespace TestTypeFoundation +{ + public class GuardedConstructorHost + where T : class + { + public GuardedConstructorHost(T item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + this.Item = item; + } + + public T Item { get; } + } +} diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs new file mode 100644 index 0000000..5b8af28 --- /dev/null +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs @@ -0,0 +1,20 @@ +namespace TestTypeFoundation +{ + public class GuardedConstructorHostHoldingStaticReadOnlyField + where TItem : class + { + public static readonly TStaticField Field; + + public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) + { + if (item is null) + { + throw new ArgumentNullException(nameof(item)); + } + + this.Item = item; + } + + public TItem Item { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs new file mode 100644 index 0000000..ace6ba2 --- /dev/null +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs @@ -0,0 +1,25 @@ +namespace TestTypeFoundation +{ + public class GuardedConstructorHostHoldingStaticReadOnlyProperty + where TItem : class + { + static GuardedConstructorHostHoldingStaticReadOnlyProperty() + { + Property = default(TStaticProperty); + } + + public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + this.Item = item; + } + + public static TStaticProperty Property { get; private set; } + + public TItem Item { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/GuardedMethodHost.cs b/tests/TestTypeFoundation/GuardedMethodHost.cs new file mode 100644 index 0000000..8f6ce8c --- /dev/null +++ b/tests/TestTypeFoundation/GuardedMethodHost.cs @@ -0,0 +1,81 @@ +namespace TestTypeFoundation +{ + public class GuardedMethodHost + { + public void ConsumeString(string s) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + } + + public void ConsumeInt32(int i) + { + } + + public void ConsumeGuid(Guid g) + { + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } + + public void ConsumeStringAndInt32(string s, int i) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + } + + public void ConsumeStringAndGuid(string s, Guid g) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } + + public void ConsumeInt32AndGuid(int i, Guid g) + { + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } + + public void ConsumeStringAndInt32AndGuid(string s, int i, Guid g) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } + } +} diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs new file mode 100644 index 0000000..63fbdcf --- /dev/null +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -0,0 +1,26 @@ +namespace TestTypeFoundation +{ + public class GuardedPropertyHolder + where T : class + { + private T property; + + public T Property + { + get + { + return this.property; + } + + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + this.property = value; + } + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs new file mode 100644 index 0000000..f1de106 --- /dev/null +++ b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs @@ -0,0 +1,10 @@ +namespace TestTypeFoundation +{ + public static class GuardedStaticMethodOnStaticTypeHost + { + public static void Method(object argument) + { + if (argument == null) throw new ArgumentNullException(nameof(argument)); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/IInterface.cs b/tests/TestTypeFoundation/IInterface.cs new file mode 100644 index 0000000..e556992 --- /dev/null +++ b/tests/TestTypeFoundation/IInterface.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public interface IInterface + { + object MakeIt(object obj); + } +} diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs new file mode 100644 index 0000000..ae59196 --- /dev/null +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -0,0 +1,32 @@ +namespace TestTypeFoundation +{ + public class IllBehavedPropertyHolder + { + private T propertyIllBehavedSet; + + public T PropertyIllBehavedGet + { + get + { + return default(T); + } + + set + { + } + } + + public T PropertyIllBehavedSet + { + get + { + return this.propertyIllBehavedSet; + } + + set + { + this.propertyIllBehavedSet = default(T); + } + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs new file mode 100644 index 0000000..d575bdc --- /dev/null +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -0,0 +1,18 @@ +namespace TestTypeFoundation +{ + public class IndexedPropertyHolder + { + private readonly List items; + + public IndexedPropertyHolder() + { + this.items = new List(); + } + + public T this[int index] + { + get { return this.items[index]; } + set { this.items[index] = value; } + } + } +} diff --git a/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs new file mode 100644 index 0000000..d540693 --- /dev/null +++ b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs @@ -0,0 +1,12 @@ +namespace TestTypeFoundation +{ + public class InternalGetterPropertyHolder + { + public InternalGetterPropertyHolder(T property) + { + this.Property = property; + } + + public T Property { internal get; set; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ItemContainer.cs b/tests/TestTypeFoundation/ItemContainer.cs new file mode 100644 index 0000000..7dcb854 --- /dev/null +++ b/tests/TestTypeFoundation/ItemContainer.cs @@ -0,0 +1,22 @@ +namespace TestTypeFoundation +{ + public class ItemContainer + { + public ItemContainer(params T[] items) + { + this.Items = items; + } + + public ItemContainer(IEnumerable items) + : this(items.ToArray()) + { + } + + public ItemContainer(IList items) + : this(items.ToArray()) + { + } + + public IEnumerable Items { get; } + } +} diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs new file mode 100644 index 0000000..d522be3 --- /dev/null +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -0,0 +1,61 @@ +namespace TestTypeFoundation +{ + public class ItemHolder + { + public ItemHolder() + { + } + + public ItemHolder(T1 item) + : this(new[] { item }, new T2[0]) + { + } + + public ItemHolder(T2 item) + : this(new T1[0], new[] { item }) + { + } + + private ItemHolder(T1[] t1s, T2[] t2s) + { + this.Item1s = t1s; + this.Item2s = t2s; + } + + public IEnumerable Item1s { get; } + + public IEnumerable Item2s { get; } + } + + /* Note that constructors must be unordered because this class is used to test that + * constructors are correctly ordered by various implementations of IMethodQuery. For that + * reason, please don't be a boy scout and order constructors 'nicely'. */ + public class ItemHolder + { + public ItemHolder(T x, T y, T z) + : this(new[] { x, y, z }) + { + } + + public ItemHolder(T item) + : this(new[] { item }) + { + } + + public ItemHolder() + { + } + + public ItemHolder(T x, T y) + : this(new[] { x, y }) + { + } + + private ItemHolder(T[] items) + { + this.Items = items; + } + + public IEnumerable Items { get; } + } +} diff --git a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs new file mode 100644 index 0000000..86dafb0 --- /dev/null +++ b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs @@ -0,0 +1,48 @@ +namespace TestTypeFoundation +{ + public class MultiUnorderedConstructorType + { + public MultiUnorderedConstructorType(ParameterObject paramObj) + : this(paramObj.Text, paramObj.Number) + { + } + + public MultiUnorderedConstructorType() + : this(string.Empty, 0) + { + } + + public MultiUnorderedConstructorType(string text, int number) + { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + + this.Text = text; + this.Number = number; + } + + public string Text { get; } + + public int Number { get; } + + public class ParameterObject + { + public ParameterObject(string text, int number) + { + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + + this.Text = text; + this.Number = number; + } + + public string Text { get; } + + public int Number { get; } + } + } +} diff --git a/tests/TestTypeFoundation/MutableValueType.cs b/tests/TestTypeFoundation/MutableValueType.cs new file mode 100644 index 0000000..010b4df --- /dev/null +++ b/tests/TestTypeFoundation/MutableValueType.cs @@ -0,0 +1,19 @@ +namespace TestTypeFoundation +{ + public struct MutableValueType + { + public MutableValueType(object property1, object property2, object property3) + : this() + { + this.Property1 = property1; + this.Property2 = property2; + this.Property3 = property3; + } + + public object Property1 { get; set; } + + public object Property2 { get; set; } + + public object Property3 { get; set; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs b/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs new file mode 100644 index 0000000..aec37b7 --- /dev/null +++ b/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs @@ -0,0 +1,8 @@ +namespace TestTypeFoundation +{ + public struct MutableValueTypeWithoutConstructor + { + public object Property1 { get; set; } + public object Property2 { get; set; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs new file mode 100644 index 0000000..339493e --- /dev/null +++ b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs @@ -0,0 +1,12 @@ +namespace TestTypeFoundation +{ + public class NonCompliantCollectionHolder + { + public NonCompliantCollectionHolder() + { + this.Collection = new List(); + } + + public ICollection Collection { get; set; } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/NoopInterfaceImplementer.cs b/tests/TestTypeFoundation/NoopInterfaceImplementer.cs new file mode 100644 index 0000000..1b434ce --- /dev/null +++ b/tests/TestTypeFoundation/NoopInterfaceImplementer.cs @@ -0,0 +1,10 @@ +namespace TestTypeFoundation +{ + public class NoopInterfaceImplementer : IInterface + { + public object MakeIt(object obj) + { + return obj; + } + } +} diff --git a/tests/TestTypeFoundation/Properties/AssemblyInfo.cs b/tests/TestTypeFoundation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1d950fa --- /dev/null +++ b/tests/TestTypeFoundation/Properties/AssemblyInfo.cs @@ -0,0 +1,12 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7ef374e5-5287-4977-a405-2b330be7fd26")] diff --git a/tests/TestTypeFoundation/PropertyHolder.cs b/tests/TestTypeFoundation/PropertyHolder.cs new file mode 100644 index 0000000..0055213 --- /dev/null +++ b/tests/TestTypeFoundation/PropertyHolder.cs @@ -0,0 +1,20 @@ +using System.Reflection; + +namespace TestTypeFoundation +{ + public class PropertyHolder + { + public T Property { get; set; } + + public void SetProperty(T value) + { + this.Property = value; + } + + public static PropertyInfo GetProperty() + { + return typeof(PropertyHolder) + .GetRuntimeProperty(nameof(Property)); + } + } +} diff --git a/tests/TestTypeFoundation/QuadrupleParameterType.cs b/tests/TestTypeFoundation/QuadrupleParameterType.cs new file mode 100644 index 0000000..fba2d70 --- /dev/null +++ b/tests/TestTypeFoundation/QuadrupleParameterType.cs @@ -0,0 +1,21 @@ +namespace TestTypeFoundation +{ + public class QuadrupleParameterType + { + public QuadrupleParameterType(T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) + { + this.Parameter1 = parameter1; + this.Parameter2 = parameter2; + this.Parameter3 = parameter3; + this.Parameter4 = parameter4; + } + + public T1 Parameter1 { get; private set; } + + public T2 Parameter2 { get; private set; } + + public T3 Parameter3 { get; private set; } + + public T4 Parameter4 { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs b/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs new file mode 100644 index 0000000..9b92a27 --- /dev/null +++ b/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public class ReadOnlyFieldHolder + { + public readonly T Field; + } +} diff --git a/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs b/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs new file mode 100644 index 0000000..7717ef5 --- /dev/null +++ b/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public class ReadOnlyPropertyHolder + { + public T Property { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs new file mode 100644 index 0000000..22931a2 --- /dev/null +++ b/tests/TestTypeFoundation/RecordType.cs @@ -0,0 +1,29 @@ +namespace TestTypeFoundation +{ + public class RecordType : IEquatable> + { + public RecordType(T value) + { + this.Value = value; + } + + public T Value { get; } + + public bool Equals(RecordType other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return EqualityComparer.Default.Equals(this.Value, other.Value); + } + + public override bool Equals(object obj) + { + return this.Equals(obj as RecordType); + } + + public override int GetHashCode() + { + return EqualityComparer.Default.GetHashCode(this.Value); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/SingleParameterType.cs b/tests/TestTypeFoundation/SingleParameterType.cs new file mode 100644 index 0000000..0d350ec --- /dev/null +++ b/tests/TestTypeFoundation/SingleParameterType.cs @@ -0,0 +1,12 @@ +namespace TestTypeFoundation +{ + public class SingleParameterType + { + public SingleParameterType(T parameter) + { + this.Parameter = parameter; + } + + public T Parameter { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/StaticFieldHolder.cs b/tests/TestTypeFoundation/StaticFieldHolder.cs new file mode 100644 index 0000000..56c9c54 --- /dev/null +++ b/tests/TestTypeFoundation/StaticFieldHolder.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public class StaticFieldHolder + { + public static T Field; + } +} diff --git a/tests/TestTypeFoundation/StaticPropertyHolder.cs b/tests/TestTypeFoundation/StaticPropertyHolder.cs new file mode 100644 index 0000000..d4904c3 --- /dev/null +++ b/tests/TestTypeFoundation/StaticPropertyHolder.cs @@ -0,0 +1,7 @@ +namespace TestTypeFoundation +{ + public class StaticPropertyHolder + { + public static T Property { get; set; } + } +} diff --git a/tests/TestTypeFoundation/TestTypeFoundation.csproj b/tests/TestTypeFoundation/TestTypeFoundation.csproj new file mode 100644 index 0000000..94b9aa5 --- /dev/null +++ b/tests/TestTypeFoundation/TestTypeFoundation.csproj @@ -0,0 +1,12 @@ + + + + + + net462;netstandard2.0;net5.0;net6.0 + TestTypeFoundation + TestTypeFoundation + + + + diff --git a/tests/TestTypeFoundation/TriState.cs b/tests/TestTypeFoundation/TriState.cs new file mode 100644 index 0000000..8e66094 --- /dev/null +++ b/tests/TestTypeFoundation/TriState.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public enum TriState + { + First = 0, + Second, + Third + } +} diff --git a/tests/TestTypeFoundation/TripleParameterType.cs b/tests/TestTypeFoundation/TripleParameterType.cs new file mode 100644 index 0000000..3a2fb44 --- /dev/null +++ b/tests/TestTypeFoundation/TripleParameterType.cs @@ -0,0 +1,18 @@ +namespace TestTypeFoundation +{ + public class TripleParameterType + { + public TripleParameterType(T1 parameter1, T2 parameter2, T3 parameter3) + { + this.Parameter1 = parameter1; + this.Parameter2 = parameter2; + this.Parameter3 = parameter3; + } + + public T1 Parameter1 { get; private set; } + + public T2 Parameter2 { get; private set; } + + public T3 Parameter3 { get; private set; } + } +} diff --git a/tests/TestTypeFoundation/TriplePropertyHolder.cs b/tests/TestTypeFoundation/TriplePropertyHolder.cs new file mode 100644 index 0000000..7bbaca1 --- /dev/null +++ b/tests/TestTypeFoundation/TriplePropertyHolder.cs @@ -0,0 +1,11 @@ +namespace TestTypeFoundation +{ + public class TriplePropertyHolder + { + public T1 Property1 { get; set; } + + public T2 Property2 { get; set; } + + public T3 Property3 { get; set; } + } +} diff --git a/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs b/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs new file mode 100644 index 0000000..659f7d1 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs @@ -0,0 +1,19 @@ +namespace TestTypeFoundation +{ + public class TypeWithCastOperatorsWithoutPublicConstructor + { + private TypeWithCastOperatorsWithoutPublicConstructor() + { + } + + public static implicit operator TypeWithCastOperatorsWithoutPublicConstructor(int ignored) + { + return new TypeWithCastOperatorsWithoutPublicConstructor(); + } + + public static explicit operator TypeWithCastOperatorsWithoutPublicConstructor(string ignored) + { + return new TypeWithCastOperatorsWithoutPublicConstructor(); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs b/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs new file mode 100644 index 0000000..d30d653 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public class TypeWithConcreteParameterMethod + { + public void DoSomething(ConcreteType param) + { + } + } +} diff --git a/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs b/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs new file mode 100644 index 0000000..869be8c --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public class TypeWithEmptyEnumField + { + public EmptyEnum EmptyEnumField; + + public EmptyEnum EmptyEnumProperty { get; set; } + } +} diff --git a/tests/TestTypeFoundation/TypeWithFactoryMethod.cs b/tests/TestTypeFoundation/TypeWithFactoryMethod.cs new file mode 100644 index 0000000..de0ba1f --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithFactoryMethod.cs @@ -0,0 +1,24 @@ +namespace TestTypeFoundation +{ + public class TypeWithFactoryMethod + { + private TypeWithFactoryMethod() + { + } + + public static TypeWithFactoryMethod Create() + { + return new TypeWithFactoryMethod(); + } + + public static TypeWithFactoryMethod Create(object argument) + { + return new TypeWithFactoryMethod(); + } + + public static TypeWithFactoryMethod Create(IEnumerable arguments) + { + return new TypeWithFactoryMethod(); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithFactoryProperty.cs b/tests/TestTypeFoundation/TypeWithFactoryProperty.cs new file mode 100644 index 0000000..d4a6863 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithFactoryProperty.cs @@ -0,0 +1,17 @@ +namespace TestTypeFoundation +{ + public class TypeWithFactoryProperty + { + private TypeWithFactoryProperty() + { + } + + public static TypeWithFactoryProperty Factory + { + get + { + return new TypeWithFactoryProperty(); + } + } + } +} diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs new file mode 100644 index 0000000..040fd04 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -0,0 +1,24 @@ +namespace TestTypeFoundation +{ + public class TypeWithIndexer + { + private readonly Dictionary dict; + + public TypeWithIndexer() + { + this.dict = new Dictionary(); + } + + public string this[string index] + { + get + { + return this.dict[index]; + } + set + { + this.dict[index] = value; + } + } + } +} diff --git a/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs b/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs new file mode 100644 index 0000000..ff83f4d --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs @@ -0,0 +1,29 @@ +using System.Reflection; + +namespace TestTypeFoundation +{ + public class TypeWithOverloadedMembers + { + public object SomeProperty { get; set; } + + public void DoSomething() + { + } + + public void DoSomething(object obj) + { + } + + public void DoSomething(object x, object y) + { + } + + public void DoSomething(object x, object y, object z) + { + } + + public static MethodInfo GetDoSomethingMethod(params Type[] parameterTypes) => + typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(DoSomething), parameterTypes); + } +} diff --git a/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs b/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs new file mode 100644 index 0000000..84a46c8 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs @@ -0,0 +1,21 @@ +namespace TestTypeFoundation +{ + /// + /// This type contains a method that returns an instance of the same type + /// so that it looks like a Factory Method. In fact, it is not because it + /// receives a parameter of the same type, so using it as a factory inevitably + /// leads to circular dependencies. + /// + public class TypeWithPseudoFactoryMethod + { + private TypeWithPseudoFactoryMethod() + { + } + + public static TypeWithPseudoFactoryMethod DoSomething( + TypeWithPseudoFactoryMethod argument) + { + return new TypeWithPseudoFactoryMethod(); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithRefMethod.cs b/tests/TestTypeFoundation/TypeWithRefMethod.cs new file mode 100644 index 0000000..5312b06 --- /dev/null +++ b/tests/TestTypeFoundation/TypeWithRefMethod.cs @@ -0,0 +1,13 @@ +namespace TestTypeFoundation +{ + public class TypeWithRefMethod + { + public void InvokeIt(T x, ref T y) + { + if (x == null) + throw new ArgumentNullException(nameof(x)); + if (y == null) + throw new ArgumentNullException(nameof(y)); + } + } +} diff --git a/tests/TestTypeFoundation/UnguardedConstructorHost.cs b/tests/TestTypeFoundation/UnguardedConstructorHost.cs new file mode 100644 index 0000000..9e90ee5 --- /dev/null +++ b/tests/TestTypeFoundation/UnguardedConstructorHost.cs @@ -0,0 +1,27 @@ +using System.Reflection; + +namespace TestTypeFoundation +{ + public class UnguardedConstructorHost + { + public UnguardedConstructorHost(T item) + { + this.Item = item; + } + + public T Item { get; } + + private static ConstructorInfo GetConstructor() + { + var typeInfo = typeof(UnguardedConstructorHost) + .GetTypeInfo(); + + return typeInfo.DeclaredConstructors.Single(); + } + + public static ParameterInfo GetParameter() + { + return GetConstructor().GetParameters().Single(); + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedMethodHost.cs b/tests/TestTypeFoundation/UnguardedMethodHost.cs new file mode 100644 index 0000000..ad85751 --- /dev/null +++ b/tests/TestTypeFoundation/UnguardedMethodHost.cs @@ -0,0 +1,17 @@ +namespace TestTypeFoundation +{ + public class UnguardedMethodHost + { + public void ConsumeUnguardedString(string s) + { + } + + public void ConsumeGuardedGuidAndUnguardedString(Guid g, string s) + { + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } + } +} diff --git a/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs b/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs new file mode 100644 index 0000000..66a138c --- /dev/null +++ b/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs @@ -0,0 +1,9 @@ +namespace TestTypeFoundation +{ + public static class UnguardedStaticMethodOnStaticTypeHost + { + public static void Method(object argument) + { + } + } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs b/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs new file mode 100644 index 0000000..ba67c65 --- /dev/null +++ b/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs @@ -0,0 +1,11 @@ +namespace TestTypeFoundation +{ + public static class UnguardedStaticPropertyOnStaticTypeHost + { + public static object Property + { + get; + set; + } + } +} \ No newline at end of file From f471a2bdfe06ea03718f07787dc1f4b8eb83c167 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:49:50 +0100 Subject: [PATCH 2/9] format --- build/Build.cs | 2 +- .../AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs | 4 ++-- tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs | 3 +-- .../Internal/InlineDataSourceTests.cs | 4 ++-- .../Internal/PropertyDataSourceTests.cs | 2 +- .../AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs | 6 ++---- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/build/Build.cs b/build/Build.cs index 763f543..e1d36b8 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -51,7 +51,7 @@ partial class Build : NukeBuild [Parameter("GitHub auth token", Name = "github-token"), Secret] readonly string GitHubToken; [Parameter("Forces the continuous integration build flag")] readonly bool CI; - [Secret] [Parameter("NuGet API Key (secret)", Name = Secrets.NuGetApiKey)] readonly string NuGetApiKey; + [Secret][Parameter("NuGet API Key (secret)", Name = Secrets.NuGetApiKey)] readonly string NuGetApiKey; readonly string NuGetSource = "https://api.nuget.org/v3/index.json"; IEnumerable Excluded => new[] diff --git a/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs index bda77fa..db7a74b 100644 --- a/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs +++ b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs @@ -9,14 +9,14 @@ public static DataGeneratorMetadata CreateDataGeneratorMetadata(Type type, strin { return CreateDataGeneratorMetadata(type.GetMethod(methodName)); } - + public static DataGeneratorMetadata CreateDataGeneratorMetadata(MethodInfo methodInfo) { var parameters = methodInfo.GetParameters(); var type = methodInfo.ReflectedType ?? methodInfo.DeclaringType!; var methodName = methodInfo.Name; var attributes = methodInfo.GetCustomAttributes().ToArray(); - + var sourceGeneratedParameterInformations = parameters?.Select(CreateParameter).ToArray() ?? []; return new DataGeneratorMetadata diff --git a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs index 4678dd3..cfe596d 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs @@ -93,8 +93,7 @@ await Assert.That(actual) .All() .Satisfy( assert => assert.Satisfies(y => y.Length, - y => y.IsBetween(0, 3).WithInclusiveBounds()) - ); + y => y.IsBetween(0, 3).WithInclusiveBounds())); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs index efcee16..9232ad4 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs @@ -59,8 +59,8 @@ public async Task SourceThrowsWhenArgumentCountExceedParameterCount() // Act & Assert await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod)) - .Select(x => x()).ToArray() - ).ThrowsExactly(); + .Select(x => x()).ToArray()) + .ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs index 15d4cb9..635ed8a 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs @@ -74,7 +74,7 @@ public async Task ThrowsWhenSourceIsNotEnumerable() // Act & Assert await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)) - + .ToArray()).ThrowsExactly(); } diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs index 79f2712..94b7f38 100644 --- a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs @@ -109,8 +109,7 @@ public async Task ThrowsWhenMemberNotEnumerable() // Act & Assert var ex = Assert.Throws( - () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray() - ); + () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray()); await Assert.That(ex.Message).Contains(memberName); } @@ -125,8 +124,7 @@ public async Task ThrowsWhenMemberNotStatic() // Act & Assert var ex = Assert.Throws( - () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray() - ); + () => sut.GetData(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method!)).ToArray()); await Assert.That(ex.Message).Contains(memberName); } From 8f3061a03f587e453aea69871c2faa291d30fe26 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:58:03 +0100 Subject: [PATCH 3/9] Style fixes --- .editorconfig | 9 +-- build/Build.cs | 64 +++++++++---------- .../CompositeDataAttribute.cs | 8 +-- src/AutoFixture.TUnit/Internal/Argument.cs | 12 +--- .../Internal/ClassDataSource.cs | 8 +-- .../Internal/FrozenValueCustomization.cs | 15 ++--- .../Internal/InlineDataSource.cs | 10 +-- .../Internal/MemberDataSource.cs | 8 +-- .../Internal/MethodDataSource.cs | 8 +-- .../Internal/ParameterFilter.cs | 6 +- .../Internal/ParameterMatcherBuilder.cs | 30 ++++----- .../Internal/TestParameter.cs | 26 +++----- .../AutoDataAttributeTest.cs | 2 +- .../ClassAutoDataAttributeTests.cs | 10 +-- ...ompositeDataAttributeSufficientDataTest.cs | 56 ++++++++-------- .../CompositeDataAttributeTest.cs | 4 +- .../FavorArraysAttributeTest.cs | 2 +- .../FavorEnumerablesAttributeTest.cs | 2 +- .../FavorListsAttributeTest.cs | 2 +- .../FrozenAttributeTest.cs | 2 +- .../GreedyAttributeTest.cs | 2 +- .../Internal/InlineDataSourceTests.cs | 4 +- .../ModestAttributeTest.cs | 2 +- .../NoAutoPropertiesAttributeTest.cs | 2 +- tests/AutoFixture.TUnit.Tests/Scenario.cs | 33 ++-------- ...CompositeTypeWithOverloadedConstructors.cs | 13 ++-- .../TestTypes/DelegatingCustomizeAttribute.cs | 7 +- .../TestTypes/DelegatingFixture.cs | 8 +-- .../TestTypes/DelegatingMemberDataSource.cs | 8 +-- .../TestTypes/DelegatingTestData.cs | 8 +-- .../DerivedArgumentsAutoDataAttribute.cs | 9 +-- .../TestTypes/DerivedAutoDataAttribute.cs | 8 +-- .../TestTypes/FakeDataAttribute.cs | 13 +--- .../TestTypes/FixedParameterBuilder.cs | 9 +-- .../TestTypes/ParameterNameCriterion.cs | 9 +-- .../TestTypes/ParameterizedClassData.cs | 17 +---- .../TestTypeFoundation/AbstractGenericType.cs | 9 +-- ...peWithConstructorWithMultipleParameters.cs | 16 ++--- tests/TestTypeFoundation/CollectionHolder.cs | 7 +- .../TestTypeFoundation/DoubleParameterType.cs | 12 +--- tests/TestTypeFoundation/EqualityResponder.cs | 13 +--- .../GuardedPropertyHolder.cs | 6 +- .../IllBehavedPropertyHolder.cs | 6 +- .../IndexedPropertyHolder.cs | 11 +--- .../InternalGetterPropertyHolder.cs | 9 +-- tests/TestTypeFoundation/ItemContainer.cs | 9 +-- tests/TestTypeFoundation/ItemHolder.cs | 10 +-- tests/TestTypeFoundation/MutableValueType.cs | 16 ++--- .../NonCompliantCollectionHolder.cs | 7 +- .../QuadrupleParameterType.cs | 18 ++---- tests/TestTypeFoundation/RecordType.cs | 9 +-- .../TestTypeFoundation/SingleParameterType.cs | 9 +-- .../TestTypeFoundation/TripleParameterType.cs | 15 ++--- tests/TestTypeFoundation/TypeWithIndexer.cs | 11 +--- .../UnguardedConstructorHost.cs | 9 +-- 55 files changed, 222 insertions(+), 416 deletions(-) diff --git a/.editorconfig b/.editorconfig index 69ef33e..3298387 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,11 +6,4 @@ indent_style = space [*.{sln,csproj,fsproj,config,xml,props}] indent_size = 2 -indent_style = space - -[*.cs] -# Require "this." keyword qualification in code -dotnet_style_qualification_for_field = true:suggestion -dotnet_style_qualification_for_property = true:suggestion -dotnet_style_qualification_for_method = true:suggestion -dotnet_style_qualification_for_event = true:suggestion +indent_style = space \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index e1d36b8..6def0c0 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -41,31 +41,31 @@ partial class Build : NukeBuild const string ReleaseBranch = "release/*"; [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] - readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + readonly Configuration _configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; - [Solution] readonly Solution Solution; - [GitRepository] readonly GitRepository GitRepository; - [GitVersion] readonly GitVersion GitVersion; - [CI] readonly GitHubActions GitHubActions; + [Solution] readonly Solution _solution; + [GitRepository] readonly GitRepository _gitRepository; + [GitVersion] readonly GitVersion _gitVersion; + [CI] readonly GitHubActions _gitHubActions; - [Parameter("GitHub auth token", Name = "github-token"), Secret] readonly string GitHubToken; - [Parameter("Forces the continuous integration build flag")] readonly bool CI; + [Parameter("GitHub auth token", Name = "github-token"), Secret] readonly string _gitHubToken; + [Parameter("Forces the continuous integration build flag")] readonly bool _ci; - [Secret][Parameter("NuGet API Key (secret)", Name = Secrets.NuGetApiKey)] readonly string NuGetApiKey; - readonly string NuGetSource = "https://api.nuget.org/v3/index.json"; + [Secret][Parameter("NuGet API Key (secret)", Name = Secrets.NuGetApiKey)] readonly string _nuGetApiKey; + readonly string _nuGetSource = "https://api.nuget.org/v3/index.json"; IEnumerable Excluded => new[] { - Solution.GetProject("_build"), - Solution.GetProject("TestTypeFoundation") + _solution.GetProject("_build"), + _solution.GetProject("TestTypeFoundation") }; - IEnumerable TestProjects => Solution.GetAllProjects("*Tests"); - IEnumerable Libraries => Solution.Projects.Except(TestProjects).Except(Excluded); + IEnumerable TestProjects => _solution.GetAllProjects("*Tests"); + IEnumerable Libraries => _solution.Projects.Except(TestProjects).Except(Excluded); IEnumerable CSharpLibraries => Libraries.Where(x => x.Is(ProjectType.CSharpProject)); IEnumerable Packages => PackagesDirectory.GlobFiles("*.nupkg"); - bool IsContinuousIntegration => IsServerBuild || CI; + bool IsContinuousIntegration => IsServerBuild || _ci; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; @@ -87,7 +87,7 @@ partial class Build : NukeBuild Target Restore => _ => _ .Executes(() => { - DotNetRestore(s => s.SetProjectFile(Solution)); + DotNetRestore(s => s.SetProjectFile(_solution)); }); Target Verify => _ => _ @@ -96,7 +96,7 @@ partial class Build : NukeBuild .Executes(() => { DotNetBuild(s => s - .SetProjectFile(Solution) + .SetProjectFile(_solution) .SetConfiguration(Configuration.Verify) .SetNoRestore(FinishedTargets.Contains(Restore)) .SetContinuousIntegrationBuild(IsContinuousIntegration)); @@ -107,14 +107,14 @@ partial class Build : NukeBuild .Executes(() => { DotNetBuild(s => s - .SetProjectFile(Solution) - .SetConfiguration(Configuration) + .SetProjectFile(_solution) + .SetConfiguration(_configuration) .SetDeterministic(IsContinuousIntegration) .SetContinuousIntegrationBuild(IsContinuousIntegration) - .SetVersion(GitVersion.NuGetVersionV2) - .SetAssemblyVersion(GitVersion.AssemblySemVer) - .SetFileVersion(GitVersion.AssemblySemFileVer) - .SetInformationalVersion(GitVersion.InformationalVersion) + .SetVersion(_gitVersion.NuGetVersionV2) + .SetAssemblyVersion(_gitVersion.AssemblySemVer) + .SetFileVersion(_gitVersion.AssemblySemFileVer) + .SetInformationalVersion(_gitVersion.InformationalVersion) .SetNoRestore(FinishedTargets.Contains(Restore))); }); @@ -124,8 +124,8 @@ partial class Build : NukeBuild .Executes(() => { DotNetTest(s => s - .SetProjectFile(Solution) - .SetConfiguration(Configuration) + .SetProjectFile(_solution) + .SetConfiguration(_configuration) .SetResultsDirectory(TestResultsDirectory) .SetNoBuild(FinishedTargets.Contains(Compile)) .When(_ => InvokedTargets.Contains(Cover), _ => _ @@ -166,17 +166,17 @@ partial class Build : NukeBuild .Executes(() => { DotNetPack(s => s - .SetConfiguration(Configuration) + .SetConfiguration(_configuration) .SetNoBuild(FinishedTargets.Contains(Compile)) .SetOutputDirectory(PackagesDirectory) .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) .EnableIncludeSymbols() .SetDeterministic(IsContinuousIntegration) .SetContinuousIntegrationBuild(IsContinuousIntegration) - .SetVersion(GitVersion.NuGetVersionV2) - .SetAssemblyVersion(GitVersion.AssemblySemVer) - .SetFileVersion(GitVersion.AssemblySemFileVer) - .SetInformationalVersion(GitVersion.InformationalVersion) + .SetVersion(_gitVersion.NuGetVersionV2) + .SetAssemblyVersion(_gitVersion.AssemblySemVer) + .SetFileVersion(_gitVersion.AssemblySemFileVer) + .SetInformationalVersion(_gitVersion.InformationalVersion) .CombineWith(CSharpLibraries, (s, p) => s.SetProject(p))); }); @@ -188,10 +188,10 @@ partial class Build : NukeBuild DotNetNuGetPush(s => s .EnableSkipDuplicate() .When( - _ => GitHubActions.IsOnSemVerTag(), + _ => _gitHubActions.IsOnSemVerTag(), v => v - .SetApiKey(NuGetApiKey) - .SetSource(NuGetSource)) + .SetApiKey(_nuGetApiKey) + .SetSource(_nuGetSource)) .CombineWith(Packages, (_, p) => _.SetTargetPath(p))); }); diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index b04d3a1..2df77b3 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -11,7 +11,7 @@ namespace AutoFixture.TUnit Justification = "This attribute is the root of a potential attribute hierarchy.")] public class CompositeDataAttribute : AutoFixtureDataSourceAttribute { - private readonly AutoFixtureDataSourceAttribute[] attributes; + private readonly AutoFixtureDataSourceAttribute[] _attributes; /// /// Initializes a new instance of the class. @@ -28,20 +28,20 @@ public CompositeDataAttribute(IEnumerable attrib /// The attributes representing a data source for a data theory. public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) { - this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); + this._attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); } /// /// Gets the attributes supplied through one of the constructors. /// - public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); + public IReadOnlyList Attributes => Array.AsReadOnly(this._attributes); /// public override IEnumerable GetData(DataGeneratorMetadata metadata) { if (metadata is null) throw new ArgumentNullException(nameof(metadata)); - var results = this.attributes + var results = this._attributes .Select(attr => attr.GenerateDataSources(metadata)) .ToArray(); diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index 4776251..3e79dd8 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -1,16 +1,10 @@ namespace AutoFixture.TUnit.Internal { - internal class Argument + internal class Argument(TestParameter parameter, object value) { - public Argument(TestParameter parameter, object value) - { - this.Parameter = parameter ?? throw new ArgumentNullException(nameof(parameter)); - this.Value = value; - } + public TestParameter Parameter { get; } = parameter ?? throw new ArgumentNullException(nameof(parameter)); - public TestParameter Parameter { get; } - - public object Value { get; } + public object Value { get; } = value; public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); } diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs index 90e0ad5..a7f95ae 100644 --- a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public class ClassDataSource : DataSource { - private readonly object[] parameters; + private readonly object[] _parameters; /// /// Creates an instance of type . @@ -20,7 +20,7 @@ public class ClassDataSource : DataSource public ClassDataSource(Type type, params object[] parameters) { this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + this._parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); } /// @@ -31,12 +31,12 @@ public ClassDataSource(Type type, params object[] parameters) /// /// Gets the constructor parameters for test data source type. /// - public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); + public IReadOnlyList Parameters => Array.AsReadOnly(this._parameters); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); + var instance = Activator.CreateInstance(type: this.Type, args: this._parameters); if (instance is not IEnumerable enumerable) { diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index 098f732..6ab0706 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -3,22 +3,15 @@ namespace AutoFixture.TUnit.Internal { - internal class FrozenValueCustomization : ICustomization + internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization { - private readonly IRequestSpecification specification; - private readonly object? value; - - public FrozenValueCustomization(IRequestSpecification specification, object? value) - { - this.specification = specification ?? throw new ArgumentNullException(nameof(specification)); - this.value = value; - } + private readonly IRequestSpecification _specification = specification ?? throw new ArgumentNullException(nameof(specification)); public void Customize(IFixture fixture) { var builder = new FilteringSpecimenBuilder( - builder: new FixedBuilder(this.value), - specification: this.specification); + builder: new FixedBuilder(value), + specification: this._specification); fixture.Customizations.Insert(0, builder); } diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs index de305ce..3cd0515 100644 --- a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public sealed class InlineDataSource : AutoFixtureDataSourceAttribute { - private readonly object[] values; + private readonly object[] _values; /// /// Creates an instance of type . @@ -20,13 +20,13 @@ public sealed class InlineDataSource : AutoFixtureDataSourceAttribute /// public InlineDataSource(object[] values) { - this.values = values ?? throw new ArgumentNullException(nameof(values)); + this._values = values ?? throw new ArgumentNullException(nameof(values)); } /// /// The collection of inline values. /// - public IReadOnlyList Values => Array.AsReadOnly(this.values); + public IReadOnlyList Values => Array.AsReadOnly(this._values); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) @@ -37,13 +37,13 @@ public override IEnumerable GetData(DataGeneratorMetadata dataGenerato } var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; - if (this.values.Length > membersToGenerate.Length) + if (this._values.Length > membersToGenerate.Length) { throw new InvalidOperationException( "The number of arguments provided exceeds the number of parameters."); } - yield return this.values; + yield return this._values; } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs index bcbcb59..b5cfa5a 100644 --- a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal /// public class MemberDataSource : IDataSource { - private readonly object[] arguments; + private readonly object[] _arguments; /// /// Creates an instance of type . @@ -22,7 +22,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) { this.Type = type ?? throw new ArgumentNullException(nameof(type)); this.Name = name ?? throw new ArgumentNullException(nameof(name)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); this.Source = this.GetTestDataSource(); } @@ -39,7 +39,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) /// /// Gets the arguments provided to the member. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(this._arguments); /// /// Gets the test data source. @@ -76,7 +76,7 @@ private DataSource GetTestDataSource() { FieldInfo fieldInfo => new FieldDataSource(fieldInfo), PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), - MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), + MethodInfo methodInfo => new MethodDataSource(methodInfo, this._arguments), _ => throw new InvalidOperationException("Unsupported member type.") }; } diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs index 973bea1..db57422 100644 --- a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -10,7 +10,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public class MethodDataSource : DataSource { - private readonly object[] arguments; + private readonly object[] _arguments; /// /// Creates an instance of type . @@ -20,7 +20,7 @@ public class MethodDataSource : DataSource public MethodDataSource(MethodInfo methodInfo, params object[] arguments) { this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); } /// @@ -31,12 +31,12 @@ public MethodDataSource(MethodInfo methodInfo, params object[] arguments) /// /// Gets the source method arguments. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(this._arguments); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.MethodInfo.Invoke(null, this.arguments); + var value = this.MethodInfo.Invoke(null, this._arguments); if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index ecd68a8..bda38ad 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -8,7 +8,7 @@ namespace AutoFixture.TUnit.Internal /// internal class ParameterFilter : IRequestSpecification { - private readonly IRequestSpecification matcherSpecification; + private readonly IRequestSpecification _matcherSpecification; /// /// Creates an instance of type . @@ -20,7 +20,7 @@ public ParameterFilter(ParameterInfo parameterInfo, Matching flags) { this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); this.Flags = flags; - this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) + this._matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) .SetFlags(this.Flags).Build(); } @@ -37,7 +37,7 @@ public ParameterFilter(ParameterInfo parameterInfo, Matching flags) /// public bool IsSatisfiedBy(object request) { - return this.matcherSpecification.IsSatisfiedBy(request); + return this._matcherSpecification.IsSatisfiedBy(request); } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index fd5e458..c8e3089 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal /// public class ParameterMatcherBuilder { - private readonly ParameterInfo parameterInfo; + private readonly ParameterInfo _parameterInfo; /// /// Creates an instance of type . @@ -20,7 +20,7 @@ public class ParameterMatcherBuilder /// public ParameterMatcherBuilder(ParameterInfo parameterInfo) { - this.parameterInfo = parameterInfo + this._parameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); } @@ -131,54 +131,54 @@ public IRequestSpecification Build() private IRequestSpecification AsExactRequest() { - return new EqualRequestSpecification(this.parameterInfo); + return new EqualRequestSpecification(this._parameterInfo); } private IRequestSpecification AsExactType() { return new OrRequestSpecification( - new ExactTypeSpecification(this.parameterInfo.ParameterType), - new SeedRequestSpecification(this.parameterInfo.ParameterType)); + new ExactTypeSpecification(this._parameterInfo.ParameterType), + new SeedRequestSpecification(this._parameterInfo.ParameterType)); } private IRequestSpecification AsDirectBaseType() { return new AndRequestSpecification( new InverseRequestSpecification( - new ExactTypeSpecification(this.parameterInfo.ParameterType)), - new DirectBaseTypeSpecification(this.parameterInfo.ParameterType)); + new ExactTypeSpecification(this._parameterInfo.ParameterType)), + new DirectBaseTypeSpecification(this._parameterInfo.ParameterType)); } private IRequestSpecification AsImplementedInterfaces() { return new AndRequestSpecification( new InverseRequestSpecification( - new ExactTypeSpecification(this.parameterInfo.ParameterType)), - new ImplementedInterfaceSpecification(this.parameterInfo.ParameterType)); + new ExactTypeSpecification(this._parameterInfo.ParameterType)), + new ImplementedInterfaceSpecification(this._parameterInfo.ParameterType)); } private IRequestSpecification AsParameter() { return new ParameterSpecification( new ParameterTypeAndNameCriterion( - new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private IRequestSpecification AsProperty() { return new PropertySpecification( new PropertyTypeAndNameCriterion( - new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private IRequestSpecification AsField() { return new FieldSpecification( new FieldTypeAndNameCriterion( - new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private class DerivesFromTypeComparer : IEqualityComparer diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 4dd8e08..6551a56 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -2,29 +2,21 @@ namespace AutoFixture.TUnit.Internal { - internal class TestParameter + internal class TestParameter(ParameterInfo parameterInfo) { - private readonly Lazy lazyCustomization; - private readonly Lazy lazyFrozenAttribute; + private readonly Lazy _lazyCustomization = new( + () => GetCustomization(parameterInfo)); + private readonly Lazy _lazyFrozenAttribute = new( + () => parameterInfo.GetCustomAttributes() + .OfType().FirstOrDefault()); - public TestParameter(ParameterInfo parameterInfo) - { - this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - - this.lazyCustomization = new Lazy( - () => GetCustomization(parameterInfo)); - this.lazyFrozenAttribute = new Lazy( - () => parameterInfo.GetCustomAttributes() - .OfType().FirstOrDefault()); - } - - public ParameterInfo ParameterInfo { get; } + public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - public ICustomization GetCustomization() => this.lazyCustomization.Value; + public ICustomization GetCustomization() => this._lazyCustomization.Value; public ICustomization GetCustomization(object value) { - var frozenAttribute = this.lazyFrozenAttribute.Value; + var frozenAttribute = this._lazyFrozenAttribute.Value; if (frozenAttribute is null) { diff --git a/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs index faa2db0..21fe329 100644 --- a/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs @@ -49,7 +49,7 @@ public async Task InitializeWithNullFixtureFactoryThrows() // Arrange // Act & Assert await Assert.That(() => - new DerivedAutoDataAttribute(null)).ThrowsExactly(); + new DerivedAutoDataAttribute(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs index 66408f5..01371fe 100644 --- a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs @@ -28,14 +28,14 @@ public async Task IsDataAttribute() public async Task ThrowsWhenSourceTypeIsNull() { // Act & Assert - await Assert.That(() => new ClassAutoDataAttribute(null)).ThrowsExactly(); + await Assert.That(() => new ClassAutoDataAttribute(null!)).ThrowsExactly(); } [Test] public async Task TreatsNullParameterValueAsArrayWithNull() { // Arrange & Act - var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData), null); + var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData), null!); // Assert await Assert.That(sut.Parameters).HasSingleItem() @@ -48,7 +48,7 @@ public async Task ThrowsWhenFixtureFactoryIsNull() { // Act & Assert await Assert.That(() => new DerivedClassAutoDataAttribute( - fixtureFactory: null, typeof(MixedTypeClassData))).ThrowsExactly(); + fixtureFactory: null!, typeof(MixedTypeClassData))).ThrowsExactly(); } [Test] @@ -68,7 +68,7 @@ await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.Crea public async Task GetDataThrowsWhenParametersDoNotMatchConstructor() { // Arrange - var sut = new ClassAutoDataAttribute(typeof(MyClass), "myString", 33, null); + var sut = new ClassAutoDataAttribute(typeof(MyClass), "myString", 33, null!); var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); // Act & Assert @@ -172,7 +172,7 @@ await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.Crea public async Task GetDataThrowsForNonMatchingConstructorTypes() { // Arrange - var sut = new ClassAutoDataAttribute(typeof(DelegatingTestData), "myString", 33, null); + var sut = new ClassAutoDataAttribute(typeof(DelegatingTestData), "myString", 33, null!); var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); // Act & Assert diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs index 6ec2a20..96d68cf 100644 --- a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs @@ -7,7 +7,7 @@ namespace AutoFixture.TUnit.Tests; public class CompositeDataAttributeSufficientDataTest { - private readonly MethodInfo method = typeof(TypeWithOverloadedMembers) + private readonly MethodInfo _method = typeof(TypeWithOverloadedMembers) .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object), typeof(object), typeof(object)]); @@ -20,7 +20,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable x()) .ToArray(); @@ -34,7 +34,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable new CompositeDataAttribute(null)).ThrowsExactly(); + await Assert.That(() => new CompositeDataAttribute(null!)).ThrowsExactly(); } [Test] @@ -81,7 +81,7 @@ public async Task GetDataWithNullMethodThrows() // Arrange var sut = new CompositeDataAttribute(); // Act & assert - await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null, null)) + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null, null!)) .Select(x => x()).ToArray()).ThrowsException(); } diff --git a/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs index 51f735b..9931bed 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs @@ -23,7 +23,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new FavorArraysAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs index de94520..753cae4 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs @@ -23,7 +23,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new FavorEnumerablesAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs index 9289cfc..ff216a2 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs @@ -23,7 +23,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new FavorListsAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs index 3357903..bafde0c 100644 --- a/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FrozenAttributeTest.cs @@ -21,6 +21,6 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new FrozenAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs index 118a592..3096daa 100644 --- a/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs @@ -26,7 +26,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new GreedyAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs index 9232ad4..4fe249c 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs @@ -22,7 +22,7 @@ public async Task InitializeWithNullValuesThrows() // Arrange // Act & Assert await Assert.That(() => - new InlineDataSource(null)).ThrowsExactly(); + new InlineDataSource(null!)).ThrowsExactly(); } [Test] @@ -44,7 +44,7 @@ public async Task GetTestDataWithNullMethodThrows() var sut = new InlineDataSource(Array.Empty()); // Act & Assert await Assert.That(() => - sut.GenerateDataSources(null)).ThrowsExactly(); + sut.GenerateDataSources(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs index 4550c8f..b9a6b3b 100644 --- a/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs @@ -22,7 +22,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new ModestAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs index 92791bf..7d94d55 100644 --- a/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/NoAutoPropertiesAttributeTest.cs @@ -22,7 +22,7 @@ public async Task GetCustomizationFromNullParameterThrows() var sut = new NoAutoPropertiesAttribute(); // Act & assert await Assert.That(() => - sut.GetCustomization(null)).ThrowsExactly(); + sut.GetCustomization(null!)).ThrowsExactly(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Scenario.cs b/tests/AutoFixture.TUnit.Tests/Scenario.cs index 855c5be..59111f0 100644 --- a/tests/AutoFixture.TUnit.Tests/Scenario.cs +++ b/tests/AutoFixture.TUnit.Tests/Scenario.cs @@ -82,13 +82,8 @@ public async Task CustomInlineDataSuppliesExtraValues(int x, int y, int z) await Assert.That(z).IsEqualTo(42); } - public class MyCustomArgumentsAutoDataAttribute : ArgumentsAutoDataAttribute - { - public MyCustomArgumentsAutoDataAttribute(params object[] values) - : base(() => new Fixture().Customize(new TheAnswer()), values) - { - } - } + public class MyCustomArgumentsAutoDataAttribute(params object[] values) + : ArgumentsAutoDataAttribute(() => new Fixture().Customize(new TheAnswer()), values); [Test, MemberAutoData(nameof(StringData))] public async Task MemberAutoDataUsesSuppliedDataValues(string s1, string s2) @@ -162,13 +157,8 @@ public static IEnumerable GetParametrizedData(int x, int y, int z) yield return [x, y, z]; } - public class MyCustomMemberAutoDataAttribute : MemberAutoDataAttribute - { - public MyCustomMemberAutoDataAttribute(string memberName, params object[] parameters) - : base(() => new Fixture().Customize(new TheAnswer()), memberName, parameters) - { - } - } + public class MyCustomMemberAutoDataAttribute(string memberName, params object[] parameters) + : MemberAutoDataAttribute(() => new Fixture().Customize(new TheAnswer()), memberName, parameters); private class TheAnswer : ICustomization { @@ -537,22 +527,11 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } - public class ParameterizedDataClass : IEnumerable + public class ParameterizedDataClass(int p1, string p2, double p3) : IEnumerable { - private readonly int p1; - private readonly string p2; - private readonly double p3; - - public ParameterizedDataClass(int p1, string p2, double p3) - { - this.p1 = p1; - this.p2 = p2; - this.p3 = p3; - } - public IEnumerator GetEnumerator() { - yield return [this.p1, this.p2, this.p3]; + yield return [p1, p2, p3]; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs index 886ec48..8545ec3 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/CompositeTypeWithOverloadedConstructors.cs @@ -1,21 +1,16 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class CompositeTypeWithOverloadedConstructors +public class CompositeTypeWithOverloadedConstructors(IEnumerable items) { - public CompositeTypeWithOverloadedConstructors(IEnumerable items) - { - this.Items = items; - } - public CompositeTypeWithOverloadedConstructors(params T[] items) + : this(items.AsEnumerable()) { - this.Items = items; } public CompositeTypeWithOverloadedConstructors(IList items) + : this(items.AsEnumerable()) { - this.Items = items; } - public IEnumerable Items { get; } + public IEnumerable Items { get; } = items; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs index 01b6039..b04bd83 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs @@ -4,15 +4,10 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class DelegatingCustomizeAttribute : CustomizeAttribute { - public DelegatingCustomizeAttribute() - { - this.OnGetCustomization = p => new DelegatingCustomization(); - } - public override ICustomization GetCustomization(ParameterInfo parameter) { return this.OnGetCustomization(parameter); } - public Func OnGetCustomization { get; set; } + public Func OnGetCustomization { get; set; } = p => new DelegatingCustomization(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs index a77d9e1..bace41d 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs @@ -5,18 +5,18 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class DelegatingFixture : IFixture { - private readonly List customizations = new(); - private readonly List residueCollectors = new(); + private readonly List _customizations = new(); + private readonly List _residueCollectors = new(); public IList Behaviors => throw new InvalidOperationException(); - public IList Customizations => this.customizations; + public IList Customizations => this._customizations; public bool OmitAutoProperties { get; set; } public int RepeatCount { get; set; } - public IList ResidueCollectors => this.residueCollectors; + public IList ResidueCollectors => this._residueCollectors; public void AddManyTo(ICollection collection, Func creator) { diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs index 06d2058..ccb5dab 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs @@ -2,12 +2,8 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class DelegatingMemberDataSource : MemberDataSource +public class DelegatingMemberDataSource(Type type, string name, params object[] arguments) + : MemberDataSource(type, name, arguments) { - public DelegatingMemberDataSource(Type type, string name, params object[] arguments) - : base(type, name, arguments) - { - } - public DataSource GetSource() => this.Source; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs index b8d688b..149e017 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs @@ -4,19 +4,19 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class DelegatingTestData : IEnumerable { - private readonly List data; + private readonly List _data; public DelegatingTestData(params object[][] data) { - this.data = data.ToList(); + this._data = data.ToList(); } public DelegatingTestData(IEnumerable data) { - this.data = data as List ?? data.ToList(); + this._data = data as List ?? data.ToList(); } - public IEnumerator GetEnumerator() => this.data.GetEnumerator(); + public IEnumerator GetEnumerator() => this._data.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs index d4210e1..07c6018 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs @@ -1,9 +1,4 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -internal class DerivedArgumentsAutoDataAttribute : ArgumentsAutoDataAttribute -{ - public DerivedArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) - : base(fixtureFactory, values) - { - } -} \ No newline at end of file +internal class DerivedArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) + : ArgumentsAutoDataAttribute(fixtureFactory, values); \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs index 47f13c8..a09828b 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedAutoDataAttribute.cs @@ -1,9 +1,3 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class DerivedAutoDataAttribute : AutoDataAttribute -{ - public DerivedAutoDataAttribute(Func fixtureFactory) - : base(fixtureFactory) - { - } -} \ No newline at end of file +public class DerivedAutoDataAttribute(Func fixtureFactory) : AutoDataAttribute(fixtureFactory); \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs index b73580f..2f3dc9a 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs @@ -2,19 +2,12 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class FakeDataAttribute : AutoFixtureDataSourceAttribute +public class FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) : AutoFixtureDataSourceAttribute { - private readonly MethodInfo expectedMethod; - private readonly IEnumerable output; - - public FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) - { - this.expectedMethod = expectedMethod; - this.output = output; - } + private readonly MethodInfo _expectedMethod = expectedMethod; public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.output; + return output; } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs index d441ca0..bf42058 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FixedParameterBuilder.cs @@ -2,10 +2,5 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -internal class FixedParameterBuilder : FilteringSpecimenBuilder -{ - public FixedParameterBuilder(string name, T value) - : base(new FixedBuilder(value), new ParameterSpecification(typeof(T), name)) - { - } -} \ No newline at end of file +internal class FixedParameterBuilder(string name, T value) + : FilteringSpecimenBuilder(new FixedBuilder(value), new ParameterSpecification(typeof(T), name)); \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs index 18ab5b2..670f5bc 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs @@ -3,22 +3,17 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -internal class ParameterNameCriterion : IEquatable +internal class ParameterNameCriterion(IEquatable nameCriterion) : IEquatable { public ParameterNameCriterion(string name) : this(new Criterion(name, StringComparer.Ordinal)) { } - public ParameterNameCriterion(IEquatable nameCriterion) - { - this.NameCriterion = nameCriterion ?? throw new ArgumentNullException(nameof(nameCriterion)); - } - /// /// The name criterion originally passed in via the class' constructor. /// - public IEquatable NameCriterion { get; } + public IEquatable NameCriterion { get; } = nameCriterion ?? throw new ArgumentNullException(nameof(nameCriterion)); public bool Equals(ParameterInfo other) { diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs index 59d2452..f5965a4 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs @@ -3,23 +3,12 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class ParameterizedClassData : IEnumerable +public class ParameterizedClassData(int p1, string p2, EnumType p3) : IEnumerable { - private readonly int p1; - private readonly string p2; - private readonly EnumType p3; - - public ParameterizedClassData(int p1, string p2, EnumType p3) - { - this.p1 = p1; - this.p2 = p2; - this.p3 = p3; - } - public IEnumerator GetEnumerator() { - yield return [this.p1, this.p2, this.p3]; - yield return [this.p1, this.p2, this.p3]; + yield return [p1, p2, p3]; + yield return [p1, p2, p3]; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); diff --git a/tests/TestTypeFoundation/AbstractGenericType.cs b/tests/TestTypeFoundation/AbstractGenericType.cs index 3da5692..cc6afe5 100644 --- a/tests/TestTypeFoundation/AbstractGenericType.cs +++ b/tests/TestTypeFoundation/AbstractGenericType.cs @@ -1,12 +1,7 @@ namespace TestTypeFoundation { - public abstract class AbstractGenericType + public abstract class AbstractGenericType(T t) { - protected AbstractGenericType(T t) - { - this.Value = t; - } - - public T Value { get; } + public T Value { get; } = t; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs index b6ce321..1878d80 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs @@ -1,17 +1,11 @@ namespace TestTypeFoundation { - public abstract class AbstractTypeWithConstructorWithMultipleParameters + public abstract class AbstractTypeWithConstructorWithMultipleParameters( + T1 parameter1, + T2 parameter2) { - protected AbstractTypeWithConstructorWithMultipleParameters( - T1 parameter1, - T2 parameter2) - { - this.Property1 = parameter1; - this.Property2 = parameter2; - } + public T1 Property1 { get; } = parameter1; - public T1 Property1 { get; } - - public T2 Property2 { get; } + public T2 Property2 { get; } = parameter2; } } diff --git a/tests/TestTypeFoundation/CollectionHolder.cs b/tests/TestTypeFoundation/CollectionHolder.cs index 27bdac4..3e11220 100644 --- a/tests/TestTypeFoundation/CollectionHolder.cs +++ b/tests/TestTypeFoundation/CollectionHolder.cs @@ -2,11 +2,6 @@ { public class CollectionHolder { - public CollectionHolder() - { - this.Collection = new List(); - } - - public ICollection Collection { get; private set; } + public ICollection Collection { get; private set; } = new List(); } } diff --git a/tests/TestTypeFoundation/DoubleParameterType.cs b/tests/TestTypeFoundation/DoubleParameterType.cs index 3fa8e12..4175d64 100644 --- a/tests/TestTypeFoundation/DoubleParameterType.cs +++ b/tests/TestTypeFoundation/DoubleParameterType.cs @@ -1,15 +1,9 @@ namespace TestTypeFoundation { - public class DoubleParameterType + public class DoubleParameterType(T1 parameter1, T2 parameter2) { - public DoubleParameterType(T1 parameter1, T2 parameter2) - { - this.Parameter1 = parameter1; - this.Parameter2 = parameter2; - } + public T1 Parameter1 { get; private set; } = parameter1; - public T1 Parameter1 { get; private set; } - - public T2 Parameter2 { get; private set; } + public T2 Parameter2 { get; private set; } = parameter2; } } diff --git a/tests/TestTypeFoundation/EqualityResponder.cs b/tests/TestTypeFoundation/EqualityResponder.cs index c146419..102cbb0 100644 --- a/tests/TestTypeFoundation/EqualityResponder.cs +++ b/tests/TestTypeFoundation/EqualityResponder.cs @@ -1,22 +1,15 @@ namespace TestTypeFoundation { - public class EqualityResponder + public class EqualityResponder(bool equals) { - private readonly bool equals; - - public EqualityResponder(bool equals) - { - this.equals = equals; - } - public override bool Equals(object obj) { - return this.equals; + return equals; } public override int GetHashCode() { - return this.equals.GetHashCode(); + return equals.GetHashCode(); } } } diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs index 63fbdcf..7e34734 100644 --- a/tests/TestTypeFoundation/GuardedPropertyHolder.cs +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -3,13 +3,13 @@ namespace TestTypeFoundation public class GuardedPropertyHolder where T : class { - private T property; + private T _property; public T Property { get { - return this.property; + return this._property; } set @@ -19,7 +19,7 @@ public T Property throw new ArgumentNullException(nameof(value)); } - this.property = value; + this._property = value; } } } diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs index ae59196..05b6279 100644 --- a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -2,7 +2,7 @@ namespace TestTypeFoundation { public class IllBehavedPropertyHolder { - private T propertyIllBehavedSet; + private T _propertyIllBehavedSet; public T PropertyIllBehavedGet { @@ -20,12 +20,12 @@ public T PropertyIllBehavedSet { get { - return this.propertyIllBehavedSet; + return this._propertyIllBehavedSet; } set { - this.propertyIllBehavedSet = default(T); + this._propertyIllBehavedSet = default(T); } } } diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs index d575bdc..acadeef 100644 --- a/tests/TestTypeFoundation/IndexedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -2,17 +2,12 @@ { public class IndexedPropertyHolder { - private readonly List items; - - public IndexedPropertyHolder() - { - this.items = new List(); - } + private readonly List _items = new(); public T this[int index] { - get { return this.items[index]; } - set { this.items[index] = value; } + get { return this._items[index]; } + set { this._items[index] = value; } } } } diff --git a/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs index d540693..3a153c1 100644 --- a/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs +++ b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs @@ -1,12 +1,7 @@ namespace TestTypeFoundation { - public class InternalGetterPropertyHolder + public class InternalGetterPropertyHolder(T property) { - public InternalGetterPropertyHolder(T property) - { - this.Property = property; - } - - public T Property { internal get; set; } + public T Property { internal get; set; } = property; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/ItemContainer.cs b/tests/TestTypeFoundation/ItemContainer.cs index 7dcb854..56e9204 100644 --- a/tests/TestTypeFoundation/ItemContainer.cs +++ b/tests/TestTypeFoundation/ItemContainer.cs @@ -1,12 +1,7 @@ namespace TestTypeFoundation { - public class ItemContainer + public class ItemContainer(params T[] items) { - public ItemContainer(params T[] items) - { - this.Items = items; - } - public ItemContainer(IEnumerable items) : this(items.ToArray()) { @@ -17,6 +12,6 @@ public ItemContainer(IList items) { } - public IEnumerable Items { get; } + public IEnumerable Items { get; } = items; } } diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs index d522be3..dac108c 100644 --- a/tests/TestTypeFoundation/ItemHolder.cs +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -16,15 +16,15 @@ public ItemHolder(T2 item) { } - private ItemHolder(T1[] t1s, T2[] t2s) + private ItemHolder(T1[] t1S, T2[] t2S) { - this.Item1s = t1s; - this.Item2s = t2s; + this.Item1S = t1S; + this.Item2S = t2S; } - public IEnumerable Item1s { get; } + public IEnumerable Item1S { get; } - public IEnumerable Item2s { get; } + public IEnumerable Item2S { get; } } /* Note that constructors must be unordered because this class is used to test that diff --git a/tests/TestTypeFoundation/MutableValueType.cs b/tests/TestTypeFoundation/MutableValueType.cs index 010b4df..3cd79bc 100644 --- a/tests/TestTypeFoundation/MutableValueType.cs +++ b/tests/TestTypeFoundation/MutableValueType.cs @@ -1,19 +1,11 @@ namespace TestTypeFoundation { - public struct MutableValueType + public struct MutableValueType(object property1, object property2, object property3) { - public MutableValueType(object property1, object property2, object property3) - : this() - { - this.Property1 = property1; - this.Property2 = property2; - this.Property3 = property3; - } + public object Property1 { get; set; } = property1; - public object Property1 { get; set; } + public object Property2 { get; set; } = property2; - public object Property2 { get; set; } - - public object Property3 { get; set; } + public object Property3 { get; set; } = property3; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs index 339493e..7318b69 100644 --- a/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs +++ b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs @@ -2,11 +2,6 @@ { public class NonCompliantCollectionHolder { - public NonCompliantCollectionHolder() - { - this.Collection = new List(); - } - - public ICollection Collection { get; set; } + public ICollection Collection { get; set; } = new List(); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/QuadrupleParameterType.cs b/tests/TestTypeFoundation/QuadrupleParameterType.cs index fba2d70..0ed4724 100644 --- a/tests/TestTypeFoundation/QuadrupleParameterType.cs +++ b/tests/TestTypeFoundation/QuadrupleParameterType.cs @@ -1,21 +1,13 @@ namespace TestTypeFoundation { - public class QuadrupleParameterType + public class QuadrupleParameterType(T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) { - public QuadrupleParameterType(T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - { - this.Parameter1 = parameter1; - this.Parameter2 = parameter2; - this.Parameter3 = parameter3; - this.Parameter4 = parameter4; - } + public T1 Parameter1 { get; private set; } = parameter1; - public T1 Parameter1 { get; private set; } + public T2 Parameter2 { get; private set; } = parameter2; - public T2 Parameter2 { get; private set; } + public T3 Parameter3 { get; private set; } = parameter3; - public T3 Parameter3 { get; private set; } - - public T4 Parameter4 { get; private set; } + public T4 Parameter4 { get; private set; } = parameter4; } } diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs index 22931a2..4c8a72b 100644 --- a/tests/TestTypeFoundation/RecordType.cs +++ b/tests/TestTypeFoundation/RecordType.cs @@ -1,13 +1,8 @@ namespace TestTypeFoundation { - public class RecordType : IEquatable> + public class RecordType(T value) : IEquatable> { - public RecordType(T value) - { - this.Value = value; - } - - public T Value { get; } + public T Value { get; } = value; public bool Equals(RecordType other) { diff --git a/tests/TestTypeFoundation/SingleParameterType.cs b/tests/TestTypeFoundation/SingleParameterType.cs index 0d350ec..13b4017 100644 --- a/tests/TestTypeFoundation/SingleParameterType.cs +++ b/tests/TestTypeFoundation/SingleParameterType.cs @@ -1,12 +1,7 @@ namespace TestTypeFoundation { - public class SingleParameterType + public class SingleParameterType(T parameter) { - public SingleParameterType(T parameter) - { - this.Parameter = parameter; - } - - public T Parameter { get; private set; } + public T Parameter { get; private set; } = parameter; } } diff --git a/tests/TestTypeFoundation/TripleParameterType.cs b/tests/TestTypeFoundation/TripleParameterType.cs index 3a2fb44..aa30de0 100644 --- a/tests/TestTypeFoundation/TripleParameterType.cs +++ b/tests/TestTypeFoundation/TripleParameterType.cs @@ -1,18 +1,11 @@ namespace TestTypeFoundation { - public class TripleParameterType + public class TripleParameterType(T1 parameter1, T2 parameter2, T3 parameter3) { - public TripleParameterType(T1 parameter1, T2 parameter2, T3 parameter3) - { - this.Parameter1 = parameter1; - this.Parameter2 = parameter2; - this.Parameter3 = parameter3; - } + public T1 Parameter1 { get; private set; } = parameter1; - public T1 Parameter1 { get; private set; } + public T2 Parameter2 { get; private set; } = parameter2; - public T2 Parameter2 { get; private set; } - - public T3 Parameter3 { get; private set; } + public T3 Parameter3 { get; private set; } = parameter3; } } diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs index 040fd04..54edded 100644 --- a/tests/TestTypeFoundation/TypeWithIndexer.cs +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -2,22 +2,17 @@ { public class TypeWithIndexer { - private readonly Dictionary dict; - - public TypeWithIndexer() - { - this.dict = new Dictionary(); - } + private readonly Dictionary _dict = new(); public string this[string index] { get { - return this.dict[index]; + return this._dict[index]; } set { - this.dict[index] = value; + this._dict[index] = value; } } } diff --git a/tests/TestTypeFoundation/UnguardedConstructorHost.cs b/tests/TestTypeFoundation/UnguardedConstructorHost.cs index 9e90ee5..c4a4d29 100644 --- a/tests/TestTypeFoundation/UnguardedConstructorHost.cs +++ b/tests/TestTypeFoundation/UnguardedConstructorHost.cs @@ -2,14 +2,9 @@ namespace TestTypeFoundation { - public class UnguardedConstructorHost + public class UnguardedConstructorHost(T item) { - public UnguardedConstructorHost(T item) - { - this.Item = item; - } - - public T Item { get; } + public T Item { get; } = item; private static ConstructorInfo GetConstructor() { From 99fc3f8953aea66644aa5d4c8046fa32c6ead169 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:31:20 +0100 Subject: [PATCH 4/9] Format --- .editorconfig | 14 ++- build/Build.cs | 4 +- .../ArgumentsAutoDataAttribute.cs | 6 +- src/AutoFixture.TUnit/AutoDataAttribute.cs | 4 +- .../AutoFixtureDataSourceAttribute.cs | 6 +- .../ClassAutoDataAttribute.cs | 10 +- .../CompositeDataAttribute.cs | 9 +- src/AutoFixture.TUnit/FrozenAttribute.cs | 4 +- src/AutoFixture.TUnit/Internal/Argument.cs | 2 +- .../Internal/AutoDataSource.cs | 15 ++- .../Internal/ClassDataSource.cs | 8 +- .../Internal/FieldDataSource.cs | 4 +- .../Internal/FrozenValueCustomization.cs | 3 +- src/AutoFixture.TUnit/Internal/IDataSource.cs | 2 +- .../Internal/InlineDataSource.cs | 6 +- .../Internal/MemberDataSource.cs | 19 ++-- .../Internal/MethodDataSource.cs | 6 +- .../Internal/ParameterFilter.cs | 10 +- .../Internal/ParameterMatcherBuilder.cs | 91 ++++++++++++------- .../Internal/PropertyDataSource.cs | 4 +- .../Internal/TestParameter.cs | 7 +- .../MemberAutoDataAttribute.cs | 17 ++-- .../ArgumentsAutoDataAttributeTests.cs | 2 +- .../AutoDataAttributeTest.cs | 6 +- .../ClassAutoDataAttributeTests.cs | 21 +++-- ...ompositeDataAttributeSufficientDataTest.cs | 54 +++++------ .../CompositeDataAttributeTest.cs | 4 +- .../DataGeneratorMetadataHelper.cs | 4 +- .../DependencyConstraintsTests.cs | 2 +- .../EnumerableExtensions.cs | 4 +- .../FavorArraysAttributeTest.cs | 4 +- .../FavorEnumerablesAttributeTest.cs | 4 +- .../FavorListsAttributeTest.cs | 4 +- .../GreedyAttributeTest.cs | 4 +- .../Internal/AutoDataSourceTests.cs | 2 +- .../Internal/ClassDataSourceTests.cs | 12 +-- .../Internal/DataSourceTests.cs | 6 +- .../Internal/MethodDataSourceTests.cs | 8 +- .../Internal/PropertyDataSourceTests.cs | 12 +-- .../MemberAutoDataAttributeTest.cs | 6 +- .../ModestAttributeTest.cs | 4 +- tests/AutoFixture.TUnit.Tests/Scenario.cs | 6 +- .../TestTypes/ClassWithEmptyTestData.cs | 2 +- .../TestTypes/ClassWithNullTestData.cs | 8 +- .../TestTypes/DelegatingCustomization.cs | 4 +- .../TestTypes/DelegatingCustomizeAttribute.cs | 2 +- .../TestTypes/DelegatingDataSource.cs | 2 +- .../TestTypes/DelegatingFixture.cs | 8 +- .../TestTypes/DelegatingMemberDataSource.cs | 2 +- .../TestTypes/DelegatingSpecimenBuilder.cs | 2 +- .../TestTypes/DelegatingTestData.cs | 4 +- .../TestTypes/EmptyClassData.cs | 2 +- .../TestTypes/InlineAttributeTestData.cs | 2 + .../TestTypes/MixedTypeClassData.cs | 2 +- .../TestTypes/ParameterNameCriterion.cs | 3 +- .../TestTypes/ParameterizedClassData.cs | 2 +- .../AbstractClassWithPublicConstructor.cs | 3 - tests/TestTypeFoundation/AbstractType.cs | 4 - .../AbstractTypeWithNonDefaultConstructor.cs | 2 +- tests/TestTypeFoundation/CompositeType.cs | 2 +- tests/TestTypeFoundation/ConcreteType.cs | 20 ++-- tests/TestTypeFoundation/GenericType.cs | 2 +- .../GuardedConstructorHost.cs | 2 +- ...nstructorHostHoldingStaticReadOnlyField.cs | 2 +- ...ructorHostHoldingStaticReadOnlyProperty.cs | 2 +- .../GuardedPropertyHolder.cs | 4 +- .../GuardedStaticMethodOnStaticTypeHost.cs | 5 +- .../IllBehavedPropertyHolder.cs | 4 +- .../IndexedPropertyHolder.cs | 4 +- tests/TestTypeFoundation/ItemHolder.cs | 6 +- .../MultiUnorderedConstructorType.cs | 8 +- tests/TestTypeFoundation/PropertyHolder.cs | 2 +- tests/TestTypeFoundation/RecordType.cs | 22 +++-- tests/TestTypeFoundation/TypeWithIndexer.cs | 4 +- tests/TestTypeFoundation/TypeWithRefMethod.cs | 4 + 75 files changed, 308 insertions(+), 259 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3298387..2e19d1c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,4 +6,16 @@ indent_style = space [*.{sln,csproj,fsproj,config,xml,props}] indent_size = 2 -indent_style = space \ No newline at end of file +indent_style = space + +[*] + +# Microsoft .NET properties +csharp_new_line_before_members_in_object_initializers = false +csharp_preferred_modifier_order = public, private, protected, internal, file, static, new, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion + +# ReSharper properties +resharper_blank_lines_around_auto_property = 1 +resharper_blank_lines_around_field = 1 +resharper_blank_lines_around_property = 1 +resharper_braces_for_ifelse = required diff --git a/build/Build.cs b/build/Build.cs index 6def0c0..546e1ee 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -33,7 +33,7 @@ InvokedTargets = new[] { nameof(Verify), nameof(Cover), nameof(Publish) }, EnableGitHubToken = true, ImportSecrets = new[] { Secrets.NuGetApiKey })] -partial class Build : NukeBuild +class Build : NukeBuild { public static int Main() => Execute(x => x.Compile); @@ -147,7 +147,7 @@ partial class Build : NukeBuild .Executes(() => { ReportGenerator(_ => _ - .SetFramework("net5.0") + .SetFramework("net8.0") .SetAssemblyFilters("-TestTypeFoundation*") .SetReports(TestResultsDirectory / "**" / "coverage.cobertura.xml") .SetTargetDirectory(ReportsDirectory) diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs index 57703a7..9552363 100644 --- a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -29,8 +29,8 @@ public ArgumentsAutoDataAttribute(params object[] values) /// protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.Values = values ?? new object[] { null }; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + Values = values ?? new object[] { null }; } /// @@ -46,7 +46,7 @@ protected ArgumentsAutoDataAttribute(Func fixtureFactory, params objec /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) + return new AutoDataSource(FixtureFactory, new InlineDataSource(Values)) .GenerateDataSources(dataGeneratorMetadata) .Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs index 798d754..5f00a06 100644 --- a/src/AutoFixture.TUnit/AutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -34,7 +34,7 @@ public AutoDataAttribute() /// The fixture factory used to construct the fixture. protected AutoDataAttribute(Func fixtureFactory) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); } /// @@ -45,7 +45,7 @@ protected AutoDataAttribute(Func fixtureFactory) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var source = new AutoDataSource(this.FixtureFactory); + var source = new AutoDataSource(FixtureFactory); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs index ff2c83f..4401906 100644 --- a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs +++ b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs @@ -34,16 +34,20 @@ IEnumerable> GetTestDataEnumerable() yield break; } - var enumerable = this.GetData(dataGeneratorMetadata) + var enumerable = GetData(dataGeneratorMetadata) ?? throw new InvalidOperationException("The source member yielded no test data."); foreach (var testData in enumerable) { if (testData is null) + { throw new InvalidOperationException("The source member yielded a null test data."); + } if (testData.Length > parameters.Length) + { throw new InvalidOperationException("The number of arguments provided exceeds the number of parameters."); + } yield return () => testData; } diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs index 3da73ca..c43b721 100644 --- a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -71,9 +71,9 @@ public ClassAutoDataAttribute(Type sourceType, params object[] parameters) /// protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); - this.Parameters = parameters ?? new object[] { null }; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); + Parameters = parameters ?? new object[] { null }; } /// @@ -95,8 +95,8 @@ protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { var source = new AutoDataSource( - this.FixtureFactory, - new ClassDataSource(this.SourceType, this.Parameters)); + FixtureFactory, + new ClassDataSource(SourceType, Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index 2df77b3..702df1c 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -34,14 +34,17 @@ public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes /// /// Gets the attributes supplied through one of the constructors. /// - public IReadOnlyList Attributes => Array.AsReadOnly(this._attributes); + public IReadOnlyList Attributes => Array.AsReadOnly(_attributes); /// public override IEnumerable GetData(DataGeneratorMetadata metadata) { - if (metadata is null) throw new ArgumentNullException(nameof(metadata)); + if (metadata is null) + { + throw new ArgumentNullException(nameof(metadata)); + } - var results = this._attributes + var results = _attributes .Select(attr => attr.GenerateDataSources(metadata)) .ToArray(); diff --git a/src/AutoFixture.TUnit/FrozenAttribute.cs b/src/AutoFixture.TUnit/FrozenAttribute.cs index aa20907..ed4e2d4 100644 --- a/src/AutoFixture.TUnit/FrozenAttribute.cs +++ b/src/AutoFixture.TUnit/FrozenAttribute.cs @@ -36,7 +36,7 @@ public FrozenAttribute() /// public FrozenAttribute(Matching by) { - this.By = by; + By = by; } /// @@ -65,7 +65,7 @@ public override ICustomization GetCustomization(ParameterInfo parameter) throw new ArgumentNullException(nameof(parameter)); } - var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); + var matcher = new ParameterMatcherBuilder(parameter).SetFlags(By).Build(); return new FreezeOnMatchCustomization(parameter, matcher); } diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index 3e79dd8..959cbde 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -6,6 +6,6 @@ internal class Argument(TestParameter parameter, object value) public object Value { get; } = value; - public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); + public ICustomization GetCustomization() => Parameter.GetCustomization(Value); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs index eb94706..7559bed 100644 --- a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -1,4 +1,3 @@ -#nullable enable using AutoFixture.TUnit.Extensions; namespace AutoFixture.TUnit.Internal @@ -18,8 +17,8 @@ public class AutoDataSource : DataSource /// public AutoDataSource(Func createFixture, IDataSource? source = default) { - this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); - this.Source = source; + CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); + Source = source; } /// @@ -39,15 +38,15 @@ public AutoDataSource(Func createFixture, IDataSource? source = defaul /// Returns a sequence of argument collections. public override IEnumerable GetData(DataGeneratorMetadata metadata) { - return this.Source is null - ? this.GenerateValues(metadata) - : this.CombineValues(metadata, this.Source); + return Source is null + ? GenerateValues(metadata) + : CombineValues(metadata, Source); } private IEnumerable GenerateValues(DataGeneratorMetadata metadata) { var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); - var fixture = this.CreateFixture(); + var fixture = CreateFixture(); yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); } @@ -64,7 +63,7 @@ private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDat .Select(argument => argument.GetCustomization()) .Where(x => x is not NullCustomization); - var fixture = this.CreateFixture(); + var fixture = CreateFixture(); foreach (var customization in customizations) { diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs index a7f95ae..837b6ab 100644 --- a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -19,7 +19,7 @@ public class ClassDataSource : DataSource /// Thrown when arguments are . public ClassDataSource(Type type, params object[] parameters) { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); + Type = type ?? throw new ArgumentNullException(nameof(type)); this._parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); } @@ -31,16 +31,16 @@ public ClassDataSource(Type type, params object[] parameters) /// /// Gets the constructor parameters for test data source type. /// - public IReadOnlyList Parameters => Array.AsReadOnly(this._parameters); + public IReadOnlyList Parameters => Array.AsReadOnly(_parameters); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var instance = Activator.CreateInstance(type: this.Type, args: this._parameters); + var instance = Activator.CreateInstance(type: Type, args: _parameters); if (instance is not IEnumerable enumerable) { - throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); + throw new InvalidOperationException($"Data source type \"{Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); } return enumerable; diff --git a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs index dff73b1..5c50186 100644 --- a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs @@ -19,7 +19,7 @@ public class FieldDataSource : DataSource /// public FieldDataSource(FieldInfo fieldInfo) { - this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); + FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); } /// @@ -36,7 +36,7 @@ public FieldDataSource(FieldInfo fieldInfo) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.FieldInfo.GetValue(null); + var value = FieldInfo.GetValue(null); if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index 6ab0706..52ef9a2 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -1,4 +1,3 @@ -#nullable enable using AutoFixture.Kernel; namespace AutoFixture.TUnit.Internal @@ -11,7 +10,7 @@ public void Customize(IFixture fixture) { var builder = new FilteringSpecimenBuilder( builder: new FixedBuilder(value), - specification: this._specification); + specification: _specification); fixture.Customizations.Insert(0, builder); } diff --git a/src/AutoFixture.TUnit/Internal/IDataSource.cs b/src/AutoFixture.TUnit/Internal/IDataSource.cs index 32ee2ac..3ade698 100644 --- a/src/AutoFixture.TUnit/Internal/IDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/IDataSource.cs @@ -10,6 +10,6 @@ public interface IDataSource /// /// The target method for which to provide the arguments. /// Returns a sequence of argument collections. - IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); + IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs index 3cd0515..16439b8 100644 --- a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -26,7 +26,7 @@ public InlineDataSource(object[] values) /// /// The collection of inline values. /// - public IReadOnlyList Values => Array.AsReadOnly(this._values); + public IReadOnlyList Values => Array.AsReadOnly(_values); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) @@ -37,13 +37,13 @@ public override IEnumerable GetData(DataGeneratorMetadata dataGenerato } var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; - if (this._values.Length > membersToGenerate.Length) + if (_values.Length > membersToGenerate.Length) { throw new InvalidOperationException( "The number of arguments provided exceeds the number of parameters."); } - yield return this._values; + yield return _values; } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs index b5cfa5a..1b4b18f 100644 --- a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Globalization; using System.Reflection; @@ -20,10 +19,10 @@ public class MemberDataSource : IDataSource /// Thrown when arguments are . public MemberDataSource(Type type, string name, params object[] arguments) { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); + Type = type ?? throw new ArgumentNullException(nameof(type)); + Name = name ?? throw new ArgumentNullException(nameof(name)); this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); - this.Source = this.GetTestDataSource(); + Source = GetTestDataSource(); } /// @@ -39,7 +38,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) /// /// Gets the arguments provided to the member. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this._arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); /// /// Gets the test data source. @@ -48,7 +47,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) private DataSource GetTestDataSource() { - var sourceMember = this.Type.GetMember(this.Name, + var sourceMember = Type.GetMember(Name, MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) .FirstOrDefault(); @@ -58,7 +57,7 @@ private DataSource GetTestDataSource() var message = string.Format( CultureInfo.CurrentCulture, "Could not find public static member (property, field, or method) named '{0}' on {1}", - this.Name, this.Type.FullName); + Name, Type.FullName); throw new ArgumentException(message); } @@ -68,7 +67,7 @@ private DataSource GetTestDataSource() var message = string.Format( CultureInfo.CurrentCulture, "Member {0} on {1} does not return IEnumerable", - this.Name, this.Type.FullName); + Name, Type.FullName); throw new ArgumentException(message); } @@ -76,7 +75,7 @@ private DataSource GetTestDataSource() { FieldInfo fieldInfo => new FieldDataSource(fieldInfo), PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), - MethodInfo methodInfo => new MethodDataSource(methodInfo, this._arguments), + MethodInfo methodInfo => new MethodDataSource(methodInfo, _arguments), _ => throw new InvalidOperationException("Unsupported member type.") }; } @@ -84,7 +83,7 @@ private DataSource GetTestDataSource() /// public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + return Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs index db57422..289c5e6 100644 --- a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -19,7 +19,7 @@ public class MethodDataSource : DataSource /// The source method arguments. public MethodDataSource(MethodInfo methodInfo, params object[] arguments) { - this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); + MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); } @@ -31,12 +31,12 @@ public MethodDataSource(MethodInfo methodInfo, params object[] arguments) /// /// Gets the source method arguments. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this._arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.MethodInfo.Invoke(null, this._arguments); + var value = MethodInfo.Invoke(null, _arguments); if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index bda38ad..329288e 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -18,10 +18,10 @@ internal class ParameterFilter : IRequestSpecification /// Thrown when is null. public ParameterFilter(ParameterInfo parameterInfo, Matching flags) { - this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - this.Flags = flags; - this._matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) - .SetFlags(this.Flags).Build(); + ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + Flags = flags; + _matcherSpecification = new ParameterMatcherBuilder(ParameterInfo) + .SetFlags(Flags).Build(); } /// @@ -37,7 +37,7 @@ public ParameterFilter(ParameterInfo parameterInfo, Matching flags) /// public bool IsSatisfiedBy(object request) { - return this._matcherSpecification.IsSatisfiedBy(request); + return _matcherSpecification.IsSatisfiedBy(request); } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index c8e3089..1ac48db 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -71,12 +71,12 @@ public ParameterMatcherBuilder(ParameterInfo parameterInfo) /// The current instance. public ParameterMatcherBuilder SetFlags(Matching flags) { - this.MatchExactType = flags.HasFlag(Matching.ExactType); - this.MatchDirectBaseType = flags.HasFlag(Matching.DirectBaseType); - this.MatchImplementedInterfaces = flags.HasFlag(Matching.ImplementedInterfaces); - this.MatchParameter = flags.HasFlag(Matching.ParameterName); - this.MatchProperty = flags.HasFlag(Matching.PropertyName); - this.MatchField = flags.HasFlag(Matching.FieldName); + MatchExactType = flags.HasFlag(Matching.ExactType); + MatchDirectBaseType = flags.HasFlag(Matching.DirectBaseType); + MatchImplementedInterfaces = flags.HasFlag(Matching.ImplementedInterfaces); + MatchParameter = flags.HasFlag(Matching.ParameterName); + MatchProperty = flags.HasFlag(Matching.PropertyName); + MatchField = flags.HasFlag(Matching.FieldName); return this; } @@ -89,39 +89,39 @@ public ParameterMatcherBuilder SetFlags(Matching flags) public IRequestSpecification Build() { var specifications = new List(7); - if (this.MatchExactRequest) + if (MatchExactRequest) { - specifications.Add(this.AsExactRequest()); + specifications.Add(AsExactRequest()); } - if (this.MatchExactType) + if (MatchExactType) { - specifications.Add(this.AsExactType()); + specifications.Add(AsExactType()); } - if (this.MatchDirectBaseType) + if (MatchDirectBaseType) { - specifications.Add(this.AsDirectBaseType()); + specifications.Add(AsDirectBaseType()); } - if (this.MatchImplementedInterfaces) + if (MatchImplementedInterfaces) { - specifications.Add(this.AsImplementedInterfaces()); + specifications.Add(AsImplementedInterfaces()); } - if (this.MatchProperty) + if (MatchProperty) { - specifications.Add(this.AsProperty()); + specifications.Add(AsProperty()); } - if (this.MatchParameter) + if (MatchParameter) { - specifications.Add(this.AsParameter()); + specifications.Add(AsParameter()); } - if (this.MatchField) + if (MatchField) { - specifications.Add(this.AsField()); + specifications.Add(AsField()); } return specifications.Count == 1 @@ -131,54 +131,79 @@ public IRequestSpecification Build() private IRequestSpecification AsExactRequest() { - return new EqualRequestSpecification(this._parameterInfo); + return new EqualRequestSpecification(_parameterInfo); } private IRequestSpecification AsExactType() { return new OrRequestSpecification( - new ExactTypeSpecification(this._parameterInfo.ParameterType), - new SeedRequestSpecification(this._parameterInfo.ParameterType)); + new ExactTypeSpecification(_parameterInfo.ParameterType), + new SeedRequestSpecification(_parameterInfo.ParameterType)); } private IRequestSpecification AsDirectBaseType() { return new AndRequestSpecification( new InverseRequestSpecification( - new ExactTypeSpecification(this._parameterInfo.ParameterType)), - new DirectBaseTypeSpecification(this._parameterInfo.ParameterType)); + new ExactTypeSpecification(_parameterInfo.ParameterType)), + new DirectBaseTypeSpecification(_parameterInfo.ParameterType)); } private IRequestSpecification AsImplementedInterfaces() { return new AndRequestSpecification( new InverseRequestSpecification( - new ExactTypeSpecification(this._parameterInfo.ParameterType)), - new ImplementedInterfaceSpecification(this._parameterInfo.ParameterType)); + new ExactTypeSpecification(_parameterInfo.ParameterType)), + new ImplementedInterfaceSpecification(_parameterInfo.ParameterType)); } private IRequestSpecification AsParameter() { return new ParameterSpecification( new ParameterTypeAndNameCriterion( - new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + + /* Unmerged change from project 'AutoFixture.TUnit(net8.0)' + Before: + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + After: + new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + */ + new Criterion( +/* Unmerged change from project 'AutoFixture.TUnit(net8.0)' +Before: + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); +After: + new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase); +*/ +_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private IRequestSpecification AsProperty() { return new PropertySpecification( new PropertyTypeAndNameCriterion( - new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))))); } private IRequestSpecification AsField() { return new FieldSpecification( new FieldTypeAndNameCriterion( - new Criterion(this._parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this._parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + + /* Unmerged change from project 'AutoFixture.TUnit(net8.0)' + Before: + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + After: + new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase); + */ + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))))); } private class DerivesFromTypeComparer : IEqualityComparer diff --git a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs index ba5b7f0..8b98db1 100644 --- a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs @@ -17,7 +17,7 @@ public class PropertyDataSource : DataSource /// public PropertyDataSource(PropertyInfo propertyInfo) { - this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); + PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); } /// @@ -28,7 +28,7 @@ public PropertyDataSource(PropertyInfo propertyInfo) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.PropertyInfo.GetValue(null); + var value = PropertyInfo.GetValue(null); if (value is not IEnumerable enumerable) { diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 6551a56..68e29dc 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -6,17 +6,18 @@ internal class TestParameter(ParameterInfo parameterInfo) { private readonly Lazy _lazyCustomization = new( () => GetCustomization(parameterInfo)); + private readonly Lazy _lazyFrozenAttribute = new( () => parameterInfo.GetCustomAttributes() .OfType().FirstOrDefault()); public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - public ICustomization GetCustomization() => this._lazyCustomization.Value; + public ICustomization GetCustomization() => _lazyCustomization.Value; public ICustomization GetCustomization(object value) { - var frozenAttribute = this._lazyFrozenAttribute.Value; + var frozenAttribute = _lazyFrozenAttribute.Value; if (frozenAttribute is null) { @@ -24,7 +25,7 @@ public ICustomization GetCustomization(object value) } return new FrozenValueCustomization( - new ParameterFilter(this.ParameterInfo, frozenAttribute.By), + new ParameterFilter(ParameterInfo, frozenAttribute.By), value); } diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs index c87a941..0a445f5 100644 --- a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using AutoFixture.TUnit.Extensions; using AutoFixture.TUnit.Internal; @@ -60,10 +59,10 @@ protected MemberAutoDataAttribute(Func fixtureFactory, string memberNa /// Thrown when arguments are null. protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); - this.Parameters = parameters ?? new object[] { null! }; - this.MemberType = memberType; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); + Parameters = parameters ?? new object[] { null! }; + MemberType = memberType; } /// @@ -96,12 +95,12 @@ protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberTyp throw new ArgumentNullException(nameof(testMethod)); } - var sourceType = this.MemberType ?? testMethod.DeclaringType + var sourceType = MemberType ?? testMethod.DeclaringType ?? throw new InvalidOperationException("Source type cannot be null."); var source = new AutoDataSource( - createFixture: this.FixtureFactory, - source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); + createFixture: FixtureFactory, + source: new MemberDataSource(sourceType, MemberName, Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs index 5aa8835..e381ea2 100644 --- a/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs @@ -157,7 +157,7 @@ public async Task InlinesAllData(int a, float b, string c, decimal d) [ArgumentsAutoData("\t\r\n")] [ArgumentsAutoData(" ")] [ArgumentsAutoData("")] - [ArgumentsAutoData([null])] + [ArgumentsAutoData([null!])] public async Task InjectsInlineValues([Frozen] object a, [Frozen] PropertyHolder value, PropertyHolder frozen) diff --git a/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs index 21fe329..05a3442 100644 --- a/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/AutoDataAttributeTest.cs @@ -62,7 +62,7 @@ public async Task DoesntActivateFixtureImmediately() _ = new DerivedAutoDataAttribute(() => { wasInvoked = true; - return null; + return null!; }); // Assert @@ -88,8 +88,8 @@ public async Task GetDataReturnsCorrectResult() var parameters = method!.GetParameters(); var expectedResult = new object(); - object actualParameter = null; - ISpecimenContext actualContext = null; + object actualParameter = null!; + ISpecimenContext actualContext = null!; var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => diff --git a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs index 01371fe..a9738fe 100644 --- a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs @@ -1,4 +1,5 @@ -using AutoFixture.Kernel; +using System.Collections; +using AutoFixture.Kernel; using AutoFixture.TUnit.Tests.TestTypes; using TestTypeFoundation; using TUnit.Assertions.AssertConditions.Throws; @@ -104,7 +105,7 @@ await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.Crea } [Test] - public async Task GetDataDoesNotThrow() + public void GetDataDoesNotThrow() { // Arrange var sut = new ClassAutoDataAttribute(typeof(MixedTypeClassData)); @@ -282,9 +283,9 @@ public async Task TestWithNullParametersPasses() .GetMethod(nameof(ExampleTestClass>.TestMethod)); var expected = new[] { - new object[] { null, null, null, null }, - new object[] { string.Empty, null, null, null }, - new object[] { null, " ", null, null }, + new object[] { null!, null!, null!, null! }, + new object[] { string.Empty, null!, null!, null! }, + new object[] { null!, " ", null!, null! }, }; // Act @@ -300,14 +301,14 @@ public class TestDataWithNullValues : IEnumerable { public IEnumerator GetEnumerator() { - yield return [null, null, null, null]; - yield return [string.Empty, null, null, null]; - yield return [null, " ", null, null]; + yield return [null!, null!, null!, null!]; + yield return [string.Empty, null!, null!, null!]; + yield return [null!, " ", null!, null!]; } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs index 96d68cf..492a749 100644 --- a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs @@ -20,7 +20,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable x()) .ToArray(); @@ -34,7 +34,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable( - () => new CompositeDataAttribute((IReadOnlyCollection)null)); + () => new CompositeDataAttribute((IReadOnlyCollection)null!)); } [Test] @@ -81,7 +81,7 @@ public async Task GetDataWithNullMethodThrows() // Arrange var sut = new CompositeDataAttribute(); // Act & assert - await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null, null!)) + await Assert.That(() => sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(null!, null!)) .Select(x => x()).ToArray()).ThrowsException(); } diff --git a/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs index db7a74b..a1921f1 100644 --- a/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs +++ b/tests/AutoFixture.TUnit.Tests/DataGeneratorMetadataHelper.cs @@ -39,14 +39,14 @@ public static DataGeneratorMetadata CreateDataGeneratorMetadata(MethodInfo metho Attributes = type.GetCustomAttributes() .ToArray(), Name = type.Name, - Namespace = null, + Namespace = null!, Parameters = [], Properties = [] }, Parameters = sourceGeneratedParameterInformations, ReturnType = typeof(void), }, - TestClassInstance = null, + TestClassInstance = null!, ClassInstanceArguments = [] }; } diff --git a/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs index 2fe4723..b6b076d 100644 --- a/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs +++ b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs @@ -39,7 +39,7 @@ public async Task AutoFixtureXunit3UnitTestsDoNotReference(string assemblyName) { // Arrange // Act - var references = this.GetType().GetTypeInfo().Assembly.GetReferencedAssemblies(); + var references = GetType().GetTypeInfo().Assembly.GetReferencedAssemblies(); // Assert await Assert.That(references).DoesNotContain(an => an.Name == assemblyName); } diff --git a/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs b/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs index b1ffe1c..9d5a06f 100644 --- a/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs +++ b/tests/AutoFixture.TUnit.Tests/EnumerableExtensions.cs @@ -50,8 +50,6 @@ internal static IEnumerable Collapse(this IEnumerable> sequ /// An that contains elements of the source sequence. public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) { - return source is not null - ? source as IReadOnlyCollection ?? source.ToArray() - : null; + return source as IReadOnlyCollection ?? source.ToArray(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs index 9931bed..f0ee622 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorArraysAttributeTest.cs @@ -38,7 +38,7 @@ public async Task GetCustomizationReturnsCorrectResult() var result = sut.GetCustomization(parameter); // Assert var invoker = await Assert.That(result).IsAssignableTo(); - await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); - await Assert.That(invoker.Query).IsAssignableTo(); + await Assert.That(invoker?.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker?.Query).IsAssignableTo(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs index 753cae4..77838e6 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorEnumerablesAttributeTest.cs @@ -38,7 +38,7 @@ public async Task GetCustomizationReturnsCorrectResult() var result = sut.GetCustomization(parameter); // Assert var invoker = await Assert.That(result).IsAssignableTo(); - await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); - await Assert.That(invoker.Query).IsAssignableTo(); + await Assert.That(invoker?.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker?.Query).IsAssignableTo(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs index ff216a2..906376c 100644 --- a/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/FavorListsAttributeTest.cs @@ -38,7 +38,7 @@ public async Task GetCustomizationReturnsCorrectResult() var result = sut.GetCustomization(parameter); // Assert var invoker = await Assert.That(result).IsAssignableTo(); - await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); - await Assert.That(invoker.Query).IsAssignableTo(); + await Assert.That(invoker?.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker?.Query).IsAssignableTo(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs index 3096daa..1faf29c 100644 --- a/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/GreedyAttributeTest.cs @@ -41,7 +41,7 @@ public async Task GetCustomizationReturnsCorrectResult() var result = sut.GetCustomization(parameter); // Assert var invoker = await Assert.That(result).IsAssignableTo(); - await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); - await Assert.That(invoker.Query).IsAssignableTo(); + await Assert.That(invoker?.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker?.Query).IsAssignableTo(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs index 0fe03fa..c479105 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs @@ -150,7 +150,7 @@ public async Task ReturnsNoTestDataWhenSourceReturnsNoTestData() public async Task ThrowsWhenSourceReturnsNull() { // Arrange - var source = new DelegatingDataSource { TestData = null }; + var source = new DelegatingDataSource { TestData = null! }; var fixture = new DelegatingFixture(); var sut = new AutoDataSource(() => fixture, source); var method = typeof(SampleTestType) diff --git a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs index d58c0bf..127f27a 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs @@ -12,7 +12,7 @@ public class ClassDataSourceTests public async Task SutIsTestDataSource() { // Arrange & Act - var sut = new ClassDataSource(typeof(object), Array.Empty()); + var sut = new ClassDataSource(typeof(object)); // Assert await Assert.That(sut).IsAssignableTo(); @@ -22,7 +22,7 @@ public async Task SutIsTestDataSource() public async Task ConstructorWithNullTypeThrows() { // Act & Assert - await Assert.That(() => _ = new ClassDataSource(null!, Array.Empty())).ThrowsExactly(); + await Assert.That(() => _ = new ClassDataSource(null!)).ThrowsExactly(); } [Test] @@ -37,7 +37,7 @@ public async Task TypeIsCorrect() { // Arrange var expected = typeof(object); - var sut = new ClassDataSource(expected, Array.Empty()); + var sut = new ClassDataSource(expected); // Act var result = sut.Type; @@ -64,7 +64,7 @@ public async Task ParametersIsCorrect() public async Task ThrowsWhenSourceIsNotEnumerable() { // Arrange - var sut = new ClassDataSource(typeof(object), Array.Empty()); + var sut = new ClassDataSource(typeof(object)); var method = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); @@ -82,7 +82,7 @@ public async Task GeneratesTestDatWithPrimitiveValues() new object[] { "foo", 2, new RecordType("bar") }, new object[] { "Han", 3, new RecordType("Solo") } }; - var sut = new ClassDataSource(typeof(TestSourceWithMixedValues), Array.Empty()); + var sut = new ClassDataSource(typeof(TestSourceWithMixedValues)); var method = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); @@ -104,7 +104,7 @@ public IEnumerator GetEnumerator() yield return ["Han", 3, new RecordType("Solo")]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs index cfe596d..25d8684 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs @@ -37,7 +37,7 @@ public async Task ReturnSingleEmptyArrayWhenMethodHasNoParameters() public async Task ThrowsWhenNoDataFoundForMethod() { // Arrange - var sut = new DelegatingDataSource { TestData = null }; + var sut = new DelegatingDataSource { TestData = null! }; var testMethod = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithSingleParameter)); @@ -72,9 +72,9 @@ public async Task ReturnsArgumentsFittingTestParameters() var testData = new[] { new object[] { "hello", 16, 32.86d }, - new object[] { null, -1, -20.22 }, + new object[] { null!, -1, -20.22 }, new object[] { "one", 2 }, - new object[] { null }, + new object[] { null! }, new object[] { }, }; var sut = new DelegatingDataSource { TestData = testData }; diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs index bb6dddc..d806174 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs @@ -19,7 +19,7 @@ public async Task SutIsTestDataSource() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); // Act var sut = new MethodDataSource(methodInfo); @@ -41,7 +41,7 @@ public async Task ThrowsWhenArgumentsIsNull() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); // Act & Assert await Assert.That(() => @@ -53,7 +53,7 @@ public async Task ConstructorSetsProperties() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); var arguments = new[] { new object() }; // Act @@ -75,7 +75,7 @@ public async Task GetTestDataInvokesMethodInfo() new object[] { "Han", 3, new RecordType("Solo") } }; var testDataSource = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.GetTestDataFieldWithMixedValues)); + .GetMethod(nameof(GetTestDataFieldWithMixedValues)); var testData = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); var sut = new MethodDataSource(testDataSource); diff --git a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs index 635ed8a..a7ae04c 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs @@ -116,9 +116,9 @@ public async Task ReturnsNullArguments() // Arrange var expected = new[] { - new object[] { null, 1, null }, - new object[] { null, 2, null }, - new object[] { null, 3, null } + new object[] { null!, 1, null! }, + new object[] { null!, 2, null! }, + new object[] { null!, 3, null! } }; var sourceProperty = typeof(PropertyDataSourceTests) .GetProperty(nameof(TestDataPropertyWithNullValues)); @@ -137,8 +137,8 @@ public async Task ReturnsNullArguments() public static IEnumerable TestDataPropertyWithNullValues => [ - [null, 1, null], - [null, 2, null], - [null, 3, null] + [null!, 1, null!], + [null!, 2, null!], + [null!, 3, null!] ]; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs index 94b7f38..940365b 100644 --- a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs @@ -389,9 +389,9 @@ public static IEnumerable TestDataWithNullValues { get { - yield return [null, null]; - yield return [string.Empty, null]; - yield return [" ", null]; + yield return [null!, null!]; + yield return [string.Empty, null!]; + yield return [" ", null!]; } } diff --git a/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs index b9a6b3b..f0eb7d7 100644 --- a/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/ModestAttributeTest.cs @@ -39,7 +39,7 @@ public async Task GetCustomizationReturnsCorrectResult() // Assert var invoker = await Assert.That(result).IsAssignableTo(); - await Assert.That(invoker.TargetType).IsEqualTo(parameter.ParameterType); - await Assert.That(invoker.Query).IsAssignableTo(); + await Assert.That(invoker?.TargetType).IsEqualTo(parameter.ParameterType); + await Assert.That(invoker?.Query).IsAssignableTo(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Scenario.cs b/tests/AutoFixture.TUnit.Tests/Scenario.cs index 59111f0..b13b0ae 100644 --- a/tests/AutoFixture.TUnit.Tests/Scenario.cs +++ b/tests/AutoFixture.TUnit.Tests/Scenario.cs @@ -512,7 +512,7 @@ public IEnumerator GetEnumerator() yield return ["dim", "sum", "dimsum"]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class MixedDataClass : IEnumerable @@ -524,7 +524,7 @@ public IEnumerator GetEnumerator() yield return [20, "otherValue", new PropertyHolder { Property = "testValue1" }]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class ParameterizedDataClass(int p1, string p2, double p3) : IEnumerable @@ -534,6 +534,6 @@ public IEnumerator GetEnumerator() yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs index 276aca2..77cb353 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs @@ -11,5 +11,5 @@ public IEnumerator GetEnumerator() yield return []; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs index 0180e82..a07d94f 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs @@ -6,10 +6,10 @@ public class ClassWithNullTestData : IEnumerable { public IEnumerator GetEnumerator() { - yield return null; - yield return null; - yield return null; + yield return null!; + yield return null!; + yield return null!; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs index d297a7c..ed47d20 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs @@ -4,12 +4,12 @@ internal class DelegatingCustomization : ICustomization { internal DelegatingCustomization() { - this.OnCustomize = _ => { }; + OnCustomize = _ => { }; } public void Customize(IFixture fixture) { - this.OnCustomize(fixture); + OnCustomize(fixture); } internal Action OnCustomize { get; set; } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs index b04bd83..aedfc51 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs @@ -6,7 +6,7 @@ internal class DelegatingCustomizeAttribute : CustomizeAttribute { public override ICustomization GetCustomization(ParameterInfo parameter) { - return this.OnGetCustomization(parameter); + return OnGetCustomization(parameter); } public Func OnGetCustomization { get; set; } = p => new DelegatingCustomization(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs index 136c159..b9ad742 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs @@ -8,6 +8,6 @@ public class DelegatingDataSource : AutoFixtureDataSourceAttribute, IDataSource public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.TestData; + return TestData; } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs index bace41d..ee60993 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs @@ -10,13 +10,13 @@ internal class DelegatingFixture : IFixture public IList Behaviors => throw new InvalidOperationException(); - public IList Customizations => this._customizations; + public IList Customizations => _customizations; public bool OmitAutoProperties { get; set; } public int RepeatCount { get; set; } - public IList ResidueCollectors => this._residueCollectors; + public IList ResidueCollectors => _residueCollectors; public void AddManyTo(ICollection collection, Func creator) { @@ -40,7 +40,7 @@ public ICustomizationComposer Build() public IFixture Customize(ICustomization customization) { - this.OnCustomize?.Invoke(customization); + OnCustomize?.Invoke(customization); return this; } @@ -81,7 +81,7 @@ public void Register(Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs index ccb5dab..b1b702a 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs @@ -5,5 +5,5 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class DelegatingMemberDataSource(Type type, string name, params object[] arguments) : MemberDataSource(type, name, arguments) { - public DataSource GetSource() => this.Source; + public DataSource GetSource() => Source; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs index c5d6e79..752af7d 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs @@ -6,7 +6,7 @@ internal class DelegatingSpecimenBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - return this.OnCreate(request, context); + return OnCreate(request, context); } internal Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs index 149e017..f96a569 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs @@ -16,7 +16,7 @@ public DelegatingTestData(IEnumerable data) this._data = data as List ?? data.ToList(); } - public IEnumerator GetEnumerator() => this._data.GetEnumerator(); + public IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs index b9a8f61..b35c9df 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs @@ -9,5 +9,5 @@ public IEnumerator GetEnumerator() yield break; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs index fd208b3..3f0a4f1 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs @@ -16,7 +16,9 @@ protected static DerivedArgumentsAutoDataAttribute CreateAttributeWithFakeFixtur object OnCreateParameter(object request, ISpecimenContext context) { if (request is not ParameterInfo parameterInfo) + { throw new InvalidOperationException(); + } return parameters .Where(x => x.ParameterName == parameterInfo.Name) diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs index e6b2243..2ad3978 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs @@ -14,5 +14,5 @@ public IEnumerator GetEnumerator() yield return [-95, "test-92", EnumType.Second, new Tuple("myValue", 5)]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs index 670f5bc..0a53403 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs @@ -17,7 +17,6 @@ public ParameterNameCriterion(string name) public bool Equals(ParameterInfo other) { - return other is not null - && this.NameCriterion.Equals(other.Name); + return NameCriterion.Equals(other.Name); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs index f5965a4..901c477 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs @@ -11,5 +11,5 @@ public IEnumerator GetEnumerator() yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs index 8b46b99..cc9c378 100644 --- a/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs +++ b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs @@ -2,8 +2,5 @@ { public abstract class AbstractClassWithPublicConstructor { - public AbstractClassWithPublicConstructor() - { - } } } diff --git a/tests/TestTypeFoundation/AbstractType.cs b/tests/TestTypeFoundation/AbstractType.cs index 846da8e..f83cc43 100644 --- a/tests/TestTypeFoundation/AbstractType.cs +++ b/tests/TestTypeFoundation/AbstractType.cs @@ -2,10 +2,6 @@ { public abstract class AbstractType { - protected AbstractType() - { - } - public object Property1 { get; set; } public object Property2 { get; set; } diff --git a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs index 45fc4d1..2a33066 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs @@ -9,7 +9,7 @@ protected AbstractTypeWithNonDefaultConstructor(T value) throw new ArgumentNullException(nameof(value)); } - this.Property = value; + Property = value; } public T Property { get; } diff --git a/tests/TestTypeFoundation/CompositeType.cs b/tests/TestTypeFoundation/CompositeType.cs index 53ea252..6c1058b 100644 --- a/tests/TestTypeFoundation/CompositeType.cs +++ b/tests/TestTypeFoundation/CompositeType.cs @@ -14,7 +14,7 @@ public CompositeType(params AbstractType[] types) throw new ArgumentNullException(nameof(types)); } - this.Types = types; + Types = types; } public IEnumerable Types { get; } diff --git a/tests/TestTypeFoundation/ConcreteType.cs b/tests/TestTypeFoundation/ConcreteType.cs index acae971..46f33a2 100644 --- a/tests/TestTypeFoundation/ConcreteType.cs +++ b/tests/TestTypeFoundation/ConcreteType.cs @@ -8,28 +8,28 @@ public ConcreteType() public ConcreteType(object obj) { - this.Property1 = obj; + Property1 = obj; } public ConcreteType(object obj1, object obj2) { - this.Property1 = obj1; - this.Property2 = obj2; + Property1 = obj1; + Property2 = obj2; } public ConcreteType(object obj1, object obj2, object obj3) { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; + Property1 = obj1; + Property2 = obj2; + Property3 = obj3; } public ConcreteType(object obj1, object obj2, object obj3, object obj4) { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; - this.Property4 = obj4; + Property1 = obj1; + Property2 = obj2; + Property3 = obj3; + Property4 = obj4; } public override object Property4 { get; set; } diff --git a/tests/TestTypeFoundation/GenericType.cs b/tests/TestTypeFoundation/GenericType.cs index 208b49a..247eba4 100644 --- a/tests/TestTypeFoundation/GenericType.cs +++ b/tests/TestTypeFoundation/GenericType.cs @@ -10,7 +10,7 @@ public GenericType(T t) throw new ArgumentNullException(nameof(t)); } - this.Value = t; + Value = t; } private T Value { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHost.cs b/tests/TestTypeFoundation/GuardedConstructorHost.cs index a8e1162..5c35859 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHost.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHost.cs @@ -10,7 +10,7 @@ public GuardedConstructorHost(T item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public T Item { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs index 5b8af28..ab1ec1d 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs @@ -12,7 +12,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public TItem Item { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs index ace6ba2..190ba28 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs @@ -15,7 +15,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public static TStaticProperty Property { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs index 7e34734..a4dd201 100644 --- a/tests/TestTypeFoundation/GuardedPropertyHolder.cs +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -9,7 +9,7 @@ public T Property { get { - return this._property; + return _property; } set @@ -19,7 +19,7 @@ public T Property throw new ArgumentNullException(nameof(value)); } - this._property = value; + _property = value; } } } diff --git a/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs index f1de106..8cf8bf8 100644 --- a/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs +++ b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs @@ -4,7 +4,10 @@ public static class GuardedStaticMethodOnStaticTypeHost { public static void Method(object argument) { - if (argument == null) throw new ArgumentNullException(nameof(argument)); + if (argument == null) + { + throw new ArgumentNullException(nameof(argument)); + } } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs index 05b6279..b2e2a95 100644 --- a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -20,12 +20,12 @@ public T PropertyIllBehavedSet { get { - return this._propertyIllBehavedSet; + return _propertyIllBehavedSet; } set { - this._propertyIllBehavedSet = default(T); + _propertyIllBehavedSet = default(T); } } } diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs index acadeef..c767fda 100644 --- a/tests/TestTypeFoundation/IndexedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -6,8 +6,8 @@ public class IndexedPropertyHolder public T this[int index] { - get { return this._items[index]; } - set { this._items[index] = value; } + get { return _items[index]; } + set { _items[index] = value; } } } } diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs index dac108c..710a4d0 100644 --- a/tests/TestTypeFoundation/ItemHolder.cs +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -18,8 +18,8 @@ public ItemHolder(T2 item) private ItemHolder(T1[] t1S, T2[] t2S) { - this.Item1S = t1S; - this.Item2S = t2S; + Item1S = t1S; + Item2S = t2S; } public IEnumerable Item1S { get; } @@ -53,7 +53,7 @@ public ItemHolder(T x, T y) private ItemHolder(T[] items) { - this.Items = items; + Items = items; } public IEnumerable Items { get; } diff --git a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs index 86dafb0..97d7847 100644 --- a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs +++ b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs @@ -19,8 +19,8 @@ public MultiUnorderedConstructorType(string text, int number) throw new ArgumentNullException(nameof(text)); } - this.Text = text; - this.Number = number; + Text = text; + Number = number; } public string Text { get; } @@ -36,8 +36,8 @@ public ParameterObject(string text, int number) throw new ArgumentNullException(nameof(text)); } - this.Text = text; - this.Number = number; + Text = text; + Number = number; } public string Text { get; } diff --git a/tests/TestTypeFoundation/PropertyHolder.cs b/tests/TestTypeFoundation/PropertyHolder.cs index 0055213..01625ca 100644 --- a/tests/TestTypeFoundation/PropertyHolder.cs +++ b/tests/TestTypeFoundation/PropertyHolder.cs @@ -8,7 +8,7 @@ public class PropertyHolder public void SetProperty(T value) { - this.Property = value; + Property = value; } public static PropertyInfo GetProperty() diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs index 4c8a72b..84e724c 100644 --- a/tests/TestTypeFoundation/RecordType.cs +++ b/tests/TestTypeFoundation/RecordType.cs @@ -4,21 +4,29 @@ public class RecordType(T value) : IEquatable> { public T Value { get; } = value; - public bool Equals(RecordType other) + public bool Equals(RecordType? other) { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return EqualityComparer.Default.Equals(this.Value, other.Value); + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return EqualityComparer.Default.Equals(Value, other.Value); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { - return this.Equals(obj as RecordType); + return Equals(obj as RecordType); } public override int GetHashCode() { - return EqualityComparer.Default.GetHashCode(this.Value); + return EqualityComparer.Default.GetHashCode(Value); } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs index 54edded..9f13549 100644 --- a/tests/TestTypeFoundation/TypeWithIndexer.cs +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -8,11 +8,11 @@ public string this[string index] { get { - return this._dict[index]; + return _dict[index]; } set { - this._dict[index] = value; + _dict[index] = value; } } } diff --git a/tests/TestTypeFoundation/TypeWithRefMethod.cs b/tests/TestTypeFoundation/TypeWithRefMethod.cs index 5312b06..36efe98 100644 --- a/tests/TestTypeFoundation/TypeWithRefMethod.cs +++ b/tests/TestTypeFoundation/TypeWithRefMethod.cs @@ -5,9 +5,13 @@ public class TypeWithRefMethod public void InvokeIt(T x, ref T y) { if (x == null) + { throw new ArgumentNullException(nameof(x)); + } if (y == null) + { throw new ArgumentNullException(nameof(y)); + } } } } From 51542fa65cdb6bdf826ffb3c556caa8fe8241186 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:34:52 +0100 Subject: [PATCH 5/9] Format --- .../ArgumentsAutoDataAttribute.cs | 6 +- src/AutoFixture.TUnit/AutoDataAttribute.cs | 4 +- .../AutoFixtureDataSourceAttribute.cs | 4 +- .../ClassAutoDataAttribute.cs | 10 ++-- .../CompositeDataAttribute.cs | 8 +-- src/AutoFixture.TUnit/FrozenAttribute.cs | 4 +- src/AutoFixture.TUnit/Internal/Argument.cs | 2 +- .../Internal/AutoDataSource.cs | 14 ++--- .../Internal/ClassDataSource.cs | 12 ++-- .../Internal/FieldDataSource.cs | 4 +- .../Internal/FrozenValueCustomization.cs | 4 +- .../Internal/InlineDataSource.cs | 10 ++-- .../Internal/MemberDataSource.cs | 22 ++++---- .../Internal/MethodDataSource.cs | 10 ++-- .../Internal/ParameterFilter.cs | 12 ++-- .../Internal/ParameterMatcherBuilder.cs | 29 +--------- .../Internal/PropertyDataSource.cs | 4 +- .../Internal/TestParameter.cs | 10 ++-- .../MemberAutoDataAttribute.cs | 14 ++--- .../ClassAutoDataAttributeTests.cs | 2 +- ...ompositeDataAttributeSufficientDataTest.cs | 56 +++++++++---------- .../DependencyConstraintsTests.cs | 2 +- .../Internal/ClassDataSourceTests.cs | 2 +- .../Internal/MethodDataSourceTests.cs | 6 +- tests/AutoFixture.TUnit.Tests/Scenario.cs | 6 +- .../TestTypes/ClassWithEmptyTestData.cs | 2 +- .../TestTypes/ClassWithNullTestData.cs | 2 +- .../TestTypes/DelegatingCustomization.cs | 4 +- .../TestTypes/DelegatingCustomizeAttribute.cs | 2 +- .../TestTypes/DelegatingDataSource.cs | 2 +- .../TestTypes/DelegatingFixture.cs | 12 ++-- .../TestTypes/DelegatingMemberDataSource.cs | 2 +- .../TestTypes/DelegatingSpecimenBuilder.cs | 2 +- .../TestTypes/DelegatingTestData.cs | 10 ++-- .../TestTypes/EmptyClassData.cs | 2 +- .../TestTypes/FakeDataAttribute.cs | 2 +- .../TestTypes/MixedTypeClassData.cs | 2 +- .../TestTypes/ParameterNameCriterion.cs | 2 +- .../TestTypes/ParameterizedClassData.cs | 2 +- .../AbstractTypeWithNonDefaultConstructor.cs | 2 +- tests/TestTypeFoundation/CompositeType.cs | 2 +- tests/TestTypeFoundation/ConcreteType.cs | 20 +++---- tests/TestTypeFoundation/GenericType.cs | 2 +- .../GuardedConstructorHost.cs | 2 +- ...nstructorHostHoldingStaticReadOnlyField.cs | 2 +- ...ructorHostHoldingStaticReadOnlyProperty.cs | 2 +- .../GuardedPropertyHolder.cs | 6 +- .../IllBehavedPropertyHolder.cs | 6 +- .../IndexedPropertyHolder.cs | 6 +- tests/TestTypeFoundation/ItemHolder.cs | 6 +- .../MultiUnorderedConstructorType.cs | 8 +-- tests/TestTypeFoundation/PropertyHolder.cs | 2 +- tests/TestTypeFoundation/RecordType.cs | 6 +- tests/TestTypeFoundation/TypeWithIndexer.cs | 6 +- 54 files changed, 179 insertions(+), 204 deletions(-) diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs index 9552363..57703a7 100644 --- a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -29,8 +29,8 @@ public ArgumentsAutoDataAttribute(params object[] values) /// protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) { - FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - Values = values ?? new object[] { null }; + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.Values = values ?? new object[] { null }; } /// @@ -46,7 +46,7 @@ protected ArgumentsAutoDataAttribute(Func fixtureFactory, params objec /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return new AutoDataSource(FixtureFactory, new InlineDataSource(Values)) + return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) .GenerateDataSources(dataGeneratorMetadata) .Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs index 5f00a06..798d754 100644 --- a/src/AutoFixture.TUnit/AutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -34,7 +34,7 @@ public AutoDataAttribute() /// The fixture factory used to construct the fixture. protected AutoDataAttribute(Func fixtureFactory) { - FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); } /// @@ -45,7 +45,7 @@ protected AutoDataAttribute(Func fixtureFactory) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var source = new AutoDataSource(FixtureFactory); + var source = new AutoDataSource(this.FixtureFactory); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs index 4401906..115333d 100644 --- a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs +++ b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs @@ -12,7 +12,7 @@ public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGenerat /// /// /// - public abstract IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); + public abstract IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); /// public override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) @@ -34,7 +34,7 @@ IEnumerable> GetTestDataEnumerable() yield break; } - var enumerable = GetData(dataGeneratorMetadata) + var enumerable = this.GetData(dataGeneratorMetadata) ?? throw new InvalidOperationException("The source member yielded no test data."); foreach (var testData in enumerable) diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs index c43b721..3da73ca 100644 --- a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -71,9 +71,9 @@ public ClassAutoDataAttribute(Type sourceType, params object[] parameters) /// protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) { - FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); - Parameters = parameters ?? new object[] { null }; + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); + this.Parameters = parameters ?? new object[] { null }; } /// @@ -95,8 +95,8 @@ protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { var source = new AutoDataSource( - FixtureFactory, - new ClassDataSource(SourceType, Parameters)); + this.FixtureFactory, + new ClassDataSource(this.SourceType, this.Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index 702df1c..6e6c49f 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -11,7 +11,7 @@ namespace AutoFixture.TUnit Justification = "This attribute is the root of a potential attribute hierarchy.")] public class CompositeDataAttribute : AutoFixtureDataSourceAttribute { - private readonly AutoFixtureDataSourceAttribute[] _attributes; + private readonly AutoFixtureDataSourceAttribute[] attributes; /// /// Initializes a new instance of the class. @@ -28,13 +28,13 @@ public CompositeDataAttribute(IEnumerable attrib /// The attributes representing a data source for a data theory. public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) { - this._attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); + this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); } /// /// Gets the attributes supplied through one of the constructors. /// - public IReadOnlyList Attributes => Array.AsReadOnly(_attributes); + public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); /// public override IEnumerable GetData(DataGeneratorMetadata metadata) @@ -44,7 +44,7 @@ public override IEnumerable GetData(DataGeneratorMetadata metadata) throw new ArgumentNullException(nameof(metadata)); } - var results = _attributes + var results = this.attributes .Select(attr => attr.GenerateDataSources(metadata)) .ToArray(); diff --git a/src/AutoFixture.TUnit/FrozenAttribute.cs b/src/AutoFixture.TUnit/FrozenAttribute.cs index ed4e2d4..aa20907 100644 --- a/src/AutoFixture.TUnit/FrozenAttribute.cs +++ b/src/AutoFixture.TUnit/FrozenAttribute.cs @@ -36,7 +36,7 @@ public FrozenAttribute() /// public FrozenAttribute(Matching by) { - By = by; + this.By = by; } /// @@ -65,7 +65,7 @@ public override ICustomization GetCustomization(ParameterInfo parameter) throw new ArgumentNullException(nameof(parameter)); } - var matcher = new ParameterMatcherBuilder(parameter).SetFlags(By).Build(); + var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); return new FreezeOnMatchCustomization(parameter, matcher); } diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index 959cbde..3e79dd8 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -6,6 +6,6 @@ internal class Argument(TestParameter parameter, object value) public object Value { get; } = value; - public ICustomization GetCustomization() => Parameter.GetCustomization(Value); + public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs index 7559bed..2726eb4 100644 --- a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -17,8 +17,8 @@ public class AutoDataSource : DataSource /// public AutoDataSource(Func createFixture, IDataSource? source = default) { - CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); - Source = source; + this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); + this.Source = source; } /// @@ -38,15 +38,15 @@ public AutoDataSource(Func createFixture, IDataSource? source = defaul /// Returns a sequence of argument collections. public override IEnumerable GetData(DataGeneratorMetadata metadata) { - return Source is null - ? GenerateValues(metadata) - : CombineValues(metadata, Source); + return this.Source is null + ? this.GenerateValues(metadata) + : this.CombineValues(metadata, this.Source); } private IEnumerable GenerateValues(DataGeneratorMetadata metadata) { var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); - var fixture = CreateFixture(); + var fixture = this.CreateFixture(); yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); } @@ -63,7 +63,7 @@ private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDat .Select(argument => argument.GetCustomization()) .Where(x => x is not NullCustomization); - var fixture = CreateFixture(); + var fixture = this.CreateFixture(); foreach (var customization in customizations) { diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs index 837b6ab..90e0ad5 100644 --- a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public class ClassDataSource : DataSource { - private readonly object[] _parameters; + private readonly object[] parameters; /// /// Creates an instance of type . @@ -19,8 +19,8 @@ public class ClassDataSource : DataSource /// Thrown when arguments are . public ClassDataSource(Type type, params object[] parameters) { - Type = type ?? throw new ArgumentNullException(nameof(type)); - this._parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); } /// @@ -31,16 +31,16 @@ public ClassDataSource(Type type, params object[] parameters) /// /// Gets the constructor parameters for test data source type. /// - public IReadOnlyList Parameters => Array.AsReadOnly(_parameters); + public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var instance = Activator.CreateInstance(type: Type, args: _parameters); + var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); if (instance is not IEnumerable enumerable) { - throw new InvalidOperationException($"Data source type \"{Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); + throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); } return enumerable; diff --git a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs index 5c50186..dff73b1 100644 --- a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs @@ -19,7 +19,7 @@ public class FieldDataSource : DataSource /// public FieldDataSource(FieldInfo fieldInfo) { - FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); + this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); } /// @@ -36,7 +36,7 @@ public FieldDataSource(FieldInfo fieldInfo) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = FieldInfo.GetValue(null); + var value = this.FieldInfo.GetValue(null); if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index 52ef9a2..a01d3ea 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -4,13 +4,13 @@ namespace AutoFixture.TUnit.Internal { internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization { - private readonly IRequestSpecification _specification = specification ?? throw new ArgumentNullException(nameof(specification)); + private readonly IRequestSpecification specification = specification ?? throw new ArgumentNullException(nameof(specification)); public void Customize(IFixture fixture) { var builder = new FilteringSpecimenBuilder( builder: new FixedBuilder(value), - specification: _specification); + specification: this.specification); fixture.Customizations.Insert(0, builder); } diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs index 16439b8..de305ce 100644 --- a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public sealed class InlineDataSource : AutoFixtureDataSourceAttribute { - private readonly object[] _values; + private readonly object[] values; /// /// Creates an instance of type . @@ -20,13 +20,13 @@ public sealed class InlineDataSource : AutoFixtureDataSourceAttribute /// public InlineDataSource(object[] values) { - this._values = values ?? throw new ArgumentNullException(nameof(values)); + this.values = values ?? throw new ArgumentNullException(nameof(values)); } /// /// The collection of inline values. /// - public IReadOnlyList Values => Array.AsReadOnly(_values); + public IReadOnlyList Values => Array.AsReadOnly(this.values); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) @@ -37,13 +37,13 @@ public override IEnumerable GetData(DataGeneratorMetadata dataGenerato } var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; - if (_values.Length > membersToGenerate.Length) + if (this.values.Length > membersToGenerate.Length) { throw new InvalidOperationException( "The number of arguments provided exceeds the number of parameters."); } - yield return _values; + yield return this.values; } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs index 1b4b18f..5f7dcbc 100644 --- a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -8,7 +8,7 @@ namespace AutoFixture.TUnit.Internal /// public class MemberDataSource : IDataSource { - private readonly object[] _arguments; + private readonly object[] arguments; /// /// Creates an instance of type . @@ -19,10 +19,10 @@ public class MemberDataSource : IDataSource /// Thrown when arguments are . public MemberDataSource(Type type, string name, params object[] arguments) { - Type = type ?? throw new ArgumentNullException(nameof(type)); - Name = name ?? throw new ArgumentNullException(nameof(name)); - this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); - Source = GetTestDataSource(); + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.Name = name ?? throw new ArgumentNullException(nameof(name)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this.Source = this.GetTestDataSource(); } /// @@ -38,7 +38,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) /// /// Gets the arguments provided to the member. /// - public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); /// /// Gets the test data source. @@ -47,7 +47,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) private DataSource GetTestDataSource() { - var sourceMember = Type.GetMember(Name, + var sourceMember = this.Type.GetMember(this.Name, MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) .FirstOrDefault(); @@ -57,7 +57,7 @@ private DataSource GetTestDataSource() var message = string.Format( CultureInfo.CurrentCulture, "Could not find public static member (property, field, or method) named '{0}' on {1}", - Name, Type.FullName); + this.Name, this.Type.FullName); throw new ArgumentException(message); } @@ -67,7 +67,7 @@ private DataSource GetTestDataSource() var message = string.Format( CultureInfo.CurrentCulture, "Member {0} on {1} does not return IEnumerable", - Name, Type.FullName); + this.Name, this.Type.FullName); throw new ArgumentException(message); } @@ -75,7 +75,7 @@ private DataSource GetTestDataSource() { FieldInfo fieldInfo => new FieldDataSource(fieldInfo), PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), - MethodInfo methodInfo => new MethodDataSource(methodInfo, _arguments), + MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), _ => throw new InvalidOperationException("Unsupported member type.") }; } @@ -83,7 +83,7 @@ private DataSource GetTestDataSource() /// public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs index 289c5e6..973bea1 100644 --- a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -10,7 +10,7 @@ namespace AutoFixture.TUnit.Internal Justification = "Type is not a collection.")] public class MethodDataSource : DataSource { - private readonly object[] _arguments; + private readonly object[] arguments; /// /// Creates an instance of type . @@ -19,8 +19,8 @@ public class MethodDataSource : DataSource /// The source method arguments. public MethodDataSource(MethodInfo methodInfo, params object[] arguments) { - MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); - this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); } /// @@ -31,12 +31,12 @@ public MethodDataSource(MethodInfo methodInfo, params object[] arguments) /// /// Gets the source method arguments. /// - public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = MethodInfo.Invoke(null, _arguments); + var value = this.MethodInfo.Invoke(null, this.arguments); if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index 329288e..ecd68a8 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -8,7 +8,7 @@ namespace AutoFixture.TUnit.Internal /// internal class ParameterFilter : IRequestSpecification { - private readonly IRequestSpecification _matcherSpecification; + private readonly IRequestSpecification matcherSpecification; /// /// Creates an instance of type . @@ -18,10 +18,10 @@ internal class ParameterFilter : IRequestSpecification /// Thrown when is null. public ParameterFilter(ParameterInfo parameterInfo, Matching flags) { - ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - Flags = flags; - _matcherSpecification = new ParameterMatcherBuilder(ParameterInfo) - .SetFlags(Flags).Build(); + this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + this.Flags = flags; + this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) + .SetFlags(this.Flags).Build(); } /// @@ -37,7 +37,7 @@ public ParameterFilter(ParameterInfo parameterInfo, Matching flags) /// public bool IsSatisfiedBy(object request) { - return _matcherSpecification.IsSatisfiedBy(request); + return this.matcherSpecification.IsSatisfiedBy(request); } } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index 1ac48db..446cb82 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -161,26 +161,8 @@ private IRequestSpecification AsParameter() { return new ParameterSpecification( new ParameterTypeAndNameCriterion( - - /* Unmerged change from project 'AutoFixture.TUnit(net8.0)' - Before: - new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); - After: - new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); - */ - new Criterion( -/* Unmerged change from project 'AutoFixture.TUnit(net8.0)' -Before: new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); -After: - new Criterion(this.parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase); -*/ -_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private IRequestSpecification AsProperty() @@ -188,7 +170,7 @@ private IRequestSpecification AsProperty() return new PropertySpecification( new PropertyTypeAndNameCriterion( new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))))); + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private IRequestSpecification AsField() @@ -196,14 +178,7 @@ private IRequestSpecification AsField() return new FieldSpecification( new FieldTypeAndNameCriterion( new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - - /* Unmerged change from project 'AutoFixture.TUnit(net8.0)' - Before: - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); - After: - new Criterion(this.parameterInfo.Name, StringComparer.OrdinalIgnoreCase); - */ - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))))); + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } private class DerivesFromTypeComparer : IEqualityComparer diff --git a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs index 8b98db1..ba5b7f0 100644 --- a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs @@ -17,7 +17,7 @@ public class PropertyDataSource : DataSource /// public PropertyDataSource(PropertyInfo propertyInfo) { - PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); + this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); } /// @@ -28,7 +28,7 @@ public PropertyDataSource(PropertyInfo propertyInfo) /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = PropertyInfo.GetValue(null); + var value = this.PropertyInfo.GetValue(null); if (value is not IEnumerable enumerable) { diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 68e29dc..64ca915 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -4,20 +4,20 @@ namespace AutoFixture.TUnit.Internal { internal class TestParameter(ParameterInfo parameterInfo) { - private readonly Lazy _lazyCustomization = new( + private readonly Lazy lazyCustomization = new( () => GetCustomization(parameterInfo)); - private readonly Lazy _lazyFrozenAttribute = new( + private readonly Lazy lazyFrozenAttribute = new( () => parameterInfo.GetCustomAttributes() .OfType().FirstOrDefault()); public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - public ICustomization GetCustomization() => _lazyCustomization.Value; + public ICustomization GetCustomization() => this.lazyCustomization.Value; public ICustomization GetCustomization(object value) { - var frozenAttribute = _lazyFrozenAttribute.Value; + var frozenAttribute = this.lazyFrozenAttribute.Value; if (frozenAttribute is null) { @@ -25,7 +25,7 @@ public ICustomization GetCustomization(object value) } return new FrozenValueCustomization( - new ParameterFilter(ParameterInfo, frozenAttribute.By), + new ParameterFilter(this.ParameterInfo, frozenAttribute.By), value); } diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs index 0a445f5..c467732 100644 --- a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -59,10 +59,10 @@ protected MemberAutoDataAttribute(Func fixtureFactory, string memberNa /// Thrown when arguments are null. protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) { - FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); - Parameters = parameters ?? new object[] { null! }; - MemberType = memberType; + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); + this.Parameters = parameters ?? new object[] { null! }; + this.MemberType = memberType; } /// @@ -95,12 +95,12 @@ protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberTyp throw new ArgumentNullException(nameof(testMethod)); } - var sourceType = MemberType ?? testMethod.DeclaringType + var sourceType = this.MemberType ?? testMethod.DeclaringType ?? throw new InvalidOperationException("Source type cannot be null."); var source = new AutoDataSource( - createFixture: FixtureFactory, - source: new MemberDataSource(sourceType, MemberName, Parameters)); + createFixture: this.FixtureFactory, + source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs index a9738fe..c9ca72c 100644 --- a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs @@ -308,7 +308,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); + return this.GetEnumerator(); } } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs index 492a749..6ec2a20 100644 --- a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs @@ -7,7 +7,7 @@ namespace AutoFixture.TUnit.Tests; public class CompositeDataAttributeSufficientDataTest { - private readonly MethodInfo _method = typeof(TypeWithOverloadedMembers) + private readonly MethodInfo method = typeof(TypeWithOverloadedMembers) .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object), typeof(object), typeof(object)]); @@ -20,7 +20,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable x()) .ToArray(); @@ -34,7 +34,7 @@ public async Task GetDataReturnsCorrectResult(IEnumerable an.Name == assemblyName); } diff --git a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs index 127f27a..5d9a363 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs @@ -104,7 +104,7 @@ public IEnumerator GetEnumerator() yield return ["Han", 3, new RecordType("Solo")]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } [Test] diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs index d806174..42aceb6 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs @@ -19,7 +19,7 @@ public async Task SutIsTestDataSource() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(SutIsTestDataSource)); + .GetMethod(nameof(this.SutIsTestDataSource)); // Act var sut = new MethodDataSource(methodInfo); @@ -41,7 +41,7 @@ public async Task ThrowsWhenArgumentsIsNull() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(SutIsTestDataSource)); + .GetMethod(nameof(this.SutIsTestDataSource)); // Act & Assert await Assert.That(() => @@ -53,7 +53,7 @@ public async Task ConstructorSetsProperties() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(SutIsTestDataSource)); + .GetMethod(nameof(this.SutIsTestDataSource)); var arguments = new[] { new object() }; // Act diff --git a/tests/AutoFixture.TUnit.Tests/Scenario.cs b/tests/AutoFixture.TUnit.Tests/Scenario.cs index b13b0ae..59111f0 100644 --- a/tests/AutoFixture.TUnit.Tests/Scenario.cs +++ b/tests/AutoFixture.TUnit.Tests/Scenario.cs @@ -512,7 +512,7 @@ public IEnumerator GetEnumerator() yield return ["dim", "sum", "dimsum"]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } public class MixedDataClass : IEnumerable @@ -524,7 +524,7 @@ public IEnumerator GetEnumerator() yield return [20, "otherValue", new PropertyHolder { Property = "testValue1" }]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } public class ParameterizedDataClass(int p1, string p2, double p3) : IEnumerable @@ -534,6 +534,6 @@ public IEnumerator GetEnumerator() yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs index 77cb353..276aca2 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs @@ -11,5 +11,5 @@ public IEnumerator GetEnumerator() yield return []; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs index a07d94f..e95410f 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs @@ -11,5 +11,5 @@ public IEnumerator GetEnumerator() yield return null!; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs index ed47d20..d297a7c 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs @@ -4,12 +4,12 @@ internal class DelegatingCustomization : ICustomization { internal DelegatingCustomization() { - OnCustomize = _ => { }; + this.OnCustomize = _ => { }; } public void Customize(IFixture fixture) { - OnCustomize(fixture); + this.OnCustomize(fixture); } internal Action OnCustomize { get; set; } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs index aedfc51..b04bd83 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs @@ -6,7 +6,7 @@ internal class DelegatingCustomizeAttribute : CustomizeAttribute { public override ICustomization GetCustomization(ParameterInfo parameter) { - return OnGetCustomization(parameter); + return this.OnGetCustomization(parameter); } public Func OnGetCustomization { get; set; } = p => new DelegatingCustomization(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs index b9ad742..136c159 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs @@ -8,6 +8,6 @@ public class DelegatingDataSource : AutoFixtureDataSourceAttribute, IDataSource public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return TestData; + return this.TestData; } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs index ee60993..a77d9e1 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs @@ -5,18 +5,18 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class DelegatingFixture : IFixture { - private readonly List _customizations = new(); - private readonly List _residueCollectors = new(); + private readonly List customizations = new(); + private readonly List residueCollectors = new(); public IList Behaviors => throw new InvalidOperationException(); - public IList Customizations => _customizations; + public IList Customizations => this.customizations; public bool OmitAutoProperties { get; set; } public int RepeatCount { get; set; } - public IList ResidueCollectors => _residueCollectors; + public IList ResidueCollectors => this.residueCollectors; public void AddManyTo(ICollection collection, Func creator) { @@ -40,7 +40,7 @@ public ICustomizationComposer Build() public IFixture Customize(ICustomization customization) { - OnCustomize?.Invoke(customization); + this.OnCustomize?.Invoke(customization); return this; } @@ -81,7 +81,7 @@ public void Register(Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs index b1b702a..ccb5dab 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs @@ -5,5 +5,5 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class DelegatingMemberDataSource(Type type, string name, params object[] arguments) : MemberDataSource(type, name, arguments) { - public DataSource GetSource() => Source; + public DataSource GetSource() => this.Source; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs index 752af7d..c5d6e79 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs @@ -6,7 +6,7 @@ internal class DelegatingSpecimenBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - return OnCreate(request, context); + return this.OnCreate(request, context); } internal Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs index f96a569..b8d688b 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs @@ -4,19 +4,19 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class DelegatingTestData : IEnumerable { - private readonly List _data; + private readonly List data; public DelegatingTestData(params object[][] data) { - this._data = data.ToList(); + this.data = data.ToList(); } public DelegatingTestData(IEnumerable data) { - this._data = data as List ?? data.ToList(); + this.data = data as List ?? data.ToList(); } - public IEnumerator GetEnumerator() => _data.GetEnumerator(); + public IEnumerator GetEnumerator() => this.data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs index b35c9df..b9a8f61 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs @@ -9,5 +9,5 @@ public IEnumerator GetEnumerator() yield break; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs index 2f3dc9a..3d604b8 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs @@ -4,7 +4,7 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) : AutoFixtureDataSourceAttribute { - private readonly MethodInfo _expectedMethod = expectedMethod; + private readonly MethodInfo expectedMethod = expectedMethod; public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs index 2ad3978..e6b2243 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs @@ -14,5 +14,5 @@ public IEnumerator GetEnumerator() yield return [-95, "test-92", EnumType.Second, new Tuple("myValue", 5)]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs index 0a53403..d28d3db 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs @@ -17,6 +17,6 @@ public ParameterNameCriterion(string name) public bool Equals(ParameterInfo other) { - return NameCriterion.Equals(other.Name); + return this.NameCriterion.Equals(other.Name); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs index 901c477..f5965a4 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs @@ -11,5 +11,5 @@ public IEnumerator GetEnumerator() yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs index 2a33066..45fc4d1 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs @@ -9,7 +9,7 @@ protected AbstractTypeWithNonDefaultConstructor(T value) throw new ArgumentNullException(nameof(value)); } - Property = value; + this.Property = value; } public T Property { get; } diff --git a/tests/TestTypeFoundation/CompositeType.cs b/tests/TestTypeFoundation/CompositeType.cs index 6c1058b..53ea252 100644 --- a/tests/TestTypeFoundation/CompositeType.cs +++ b/tests/TestTypeFoundation/CompositeType.cs @@ -14,7 +14,7 @@ public CompositeType(params AbstractType[] types) throw new ArgumentNullException(nameof(types)); } - Types = types; + this.Types = types; } public IEnumerable Types { get; } diff --git a/tests/TestTypeFoundation/ConcreteType.cs b/tests/TestTypeFoundation/ConcreteType.cs index 46f33a2..acae971 100644 --- a/tests/TestTypeFoundation/ConcreteType.cs +++ b/tests/TestTypeFoundation/ConcreteType.cs @@ -8,28 +8,28 @@ public ConcreteType() public ConcreteType(object obj) { - Property1 = obj; + this.Property1 = obj; } public ConcreteType(object obj1, object obj2) { - Property1 = obj1; - Property2 = obj2; + this.Property1 = obj1; + this.Property2 = obj2; } public ConcreteType(object obj1, object obj2, object obj3) { - Property1 = obj1; - Property2 = obj2; - Property3 = obj3; + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; } public ConcreteType(object obj1, object obj2, object obj3, object obj4) { - Property1 = obj1; - Property2 = obj2; - Property3 = obj3; - Property4 = obj4; + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; + this.Property4 = obj4; } public override object Property4 { get; set; } diff --git a/tests/TestTypeFoundation/GenericType.cs b/tests/TestTypeFoundation/GenericType.cs index 247eba4..208b49a 100644 --- a/tests/TestTypeFoundation/GenericType.cs +++ b/tests/TestTypeFoundation/GenericType.cs @@ -10,7 +10,7 @@ public GenericType(T t) throw new ArgumentNullException(nameof(t)); } - Value = t; + this.Value = t; } private T Value { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHost.cs b/tests/TestTypeFoundation/GuardedConstructorHost.cs index 5c35859..a8e1162 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHost.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHost.cs @@ -10,7 +10,7 @@ public GuardedConstructorHost(T item) throw new ArgumentNullException(nameof(item)); } - Item = item; + this.Item = item; } public T Item { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs index ab1ec1d..5b8af28 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs @@ -12,7 +12,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) throw new ArgumentNullException(nameof(item)); } - Item = item; + this.Item = item; } public TItem Item { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs index 190ba28..ace6ba2 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs @@ -15,7 +15,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) throw new ArgumentNullException(nameof(item)); } - Item = item; + this.Item = item; } public static TStaticProperty Property { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs index a4dd201..63fbdcf 100644 --- a/tests/TestTypeFoundation/GuardedPropertyHolder.cs +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -3,13 +3,13 @@ namespace TestTypeFoundation public class GuardedPropertyHolder where T : class { - private T _property; + private T property; public T Property { get { - return _property; + return this.property; } set @@ -19,7 +19,7 @@ public T Property throw new ArgumentNullException(nameof(value)); } - _property = value; + this.property = value; } } } diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs index b2e2a95..ae59196 100644 --- a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -2,7 +2,7 @@ namespace TestTypeFoundation { public class IllBehavedPropertyHolder { - private T _propertyIllBehavedSet; + private T propertyIllBehavedSet; public T PropertyIllBehavedGet { @@ -20,12 +20,12 @@ public T PropertyIllBehavedSet { get { - return _propertyIllBehavedSet; + return this.propertyIllBehavedSet; } set { - _propertyIllBehavedSet = default(T); + this.propertyIllBehavedSet = default(T); } } } diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs index c767fda..b799134 100644 --- a/tests/TestTypeFoundation/IndexedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -2,12 +2,12 @@ { public class IndexedPropertyHolder { - private readonly List _items = new(); + private readonly List items = new(); public T this[int index] { - get { return _items[index]; } - set { _items[index] = value; } + get { return this.items[index]; } + set { this.items[index] = value; } } } } diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs index 710a4d0..dac108c 100644 --- a/tests/TestTypeFoundation/ItemHolder.cs +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -18,8 +18,8 @@ public ItemHolder(T2 item) private ItemHolder(T1[] t1S, T2[] t2S) { - Item1S = t1S; - Item2S = t2S; + this.Item1S = t1S; + this.Item2S = t2S; } public IEnumerable Item1S { get; } @@ -53,7 +53,7 @@ public ItemHolder(T x, T y) private ItemHolder(T[] items) { - Items = items; + this.Items = items; } public IEnumerable Items { get; } diff --git a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs index 97d7847..86dafb0 100644 --- a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs +++ b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs @@ -19,8 +19,8 @@ public MultiUnorderedConstructorType(string text, int number) throw new ArgumentNullException(nameof(text)); } - Text = text; - Number = number; + this.Text = text; + this.Number = number; } public string Text { get; } @@ -36,8 +36,8 @@ public ParameterObject(string text, int number) throw new ArgumentNullException(nameof(text)); } - Text = text; - Number = number; + this.Text = text; + this.Number = number; } public string Text { get; } diff --git a/tests/TestTypeFoundation/PropertyHolder.cs b/tests/TestTypeFoundation/PropertyHolder.cs index 01625ca..0055213 100644 --- a/tests/TestTypeFoundation/PropertyHolder.cs +++ b/tests/TestTypeFoundation/PropertyHolder.cs @@ -8,7 +8,7 @@ public class PropertyHolder public void SetProperty(T value) { - Property = value; + this.Property = value; } public static PropertyInfo GetProperty() diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs index 84e724c..1ae671d 100644 --- a/tests/TestTypeFoundation/RecordType.cs +++ b/tests/TestTypeFoundation/RecordType.cs @@ -16,17 +16,17 @@ public bool Equals(RecordType? other) return true; } - return EqualityComparer.Default.Equals(Value, other.Value); + return EqualityComparer.Default.Equals(this.Value, other.Value); } public override bool Equals(object? obj) { - return Equals(obj as RecordType); + return this.Equals(obj as RecordType); } public override int GetHashCode() { - return EqualityComparer.Default.GetHashCode(Value); + return EqualityComparer.Default.GetHashCode(this.Value); } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs index 9f13549..a5628f2 100644 --- a/tests/TestTypeFoundation/TypeWithIndexer.cs +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -2,17 +2,17 @@ { public class TypeWithIndexer { - private readonly Dictionary _dict = new(); + private readonly Dictionary dict = new(); public string this[string index] { get { - return _dict[index]; + return this.dict[index]; } set { - _dict[index] = value; + this.dict[index] = value; } } } From 5639805e00e5b40817378b1783c08dca3d91d982 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:35:10 +0100 Subject: [PATCH 6/9] File scoped namespace --- build/GitHubActionsExtensions.cs | 17 +- .../ArgumentsAutoDataAttribute.cs | 81 +++-- src/AutoFixture.TUnit/AutoDataAttribute.cs | 79 +++-- .../ClassAutoDataAttribute.cs | 179 +++++----- .../CompositeDataAttribute.cs | 85 +++-- src/AutoFixture.TUnit/CustomizeAttribute.cs | 25 +- src/AutoFixture.TUnit/FavorArraysAttribute.cs | 45 ++- .../FavorEnumerablesAttribute.cs | 45 ++- src/AutoFixture.TUnit/FavorListsAttribute.cs | 45 ++- src/AutoFixture.TUnit/FrozenAttribute.cs | 113 ++++--- src/AutoFixture.TUnit/GreedyAttribute.cs | 45 ++- src/AutoFixture.TUnit/Internal/Argument.cs | 13 +- .../Internal/AutoDataSource.cs | 141 ++++---- .../Internal/ClassDataSource.cs | 71 ++-- .../Internal/CustomizationExtensions.cs | 11 +- .../Internal/CustomizeAttributeComparer.cs | 19 +- src/AutoFixture.TUnit/Internal/DataSource.cs | 21 +- .../Internal/EnumerableExtensions.cs | 91 +++-- .../Internal/FieldDataSource.cs | 69 ++-- .../Internal/FrozenValueCustomization.cs | 21 +- src/AutoFixture.TUnit/Internal/IDataSource.cs | 21 +- .../Internal/InlineDataSource.cs | 69 ++-- .../Internal/MemberDataSource.cs | 137 ++++---- .../Internal/MethodDataSource.cs | 67 ++-- .../Internal/NullCustomization.cs | 25 +- .../Internal/ParameterFilter.cs | 61 ++-- .../Internal/ParameterMatcherBuilder.cs | 313 +++++++++--------- .../Internal/PropertyDataSource.cs | 55 ++- .../Internal/ReflectionExtensions.cs | 31 +- .../Internal/TestParameter.cs | 73 ++-- src/AutoFixture.TUnit/Matching.cs | 111 +++---- .../MemberAutoDataAttribute.cs | 171 +++++----- src/AutoFixture.TUnit/ModestAttribute.cs | 45 ++- .../NoAutoPropertiesAttribute.cs | 49 ++- .../AbstractClassWithPublicConstructor.cs | 9 +- .../TestTypeFoundation/AbstractGenericType.cs | 9 +- tests/TestTypeFoundation/AbstractType.cs | 19 +- ...peWithConstructorWithMultipleParameters.cs | 17 +- .../AbstractTypeWithNonDefaultConstructor.cs | 21 +- tests/TestTypeFoundation/ActivityScope.cs | 87 +++-- tests/TestTypeFoundation/CollectionHolder.cs | 11 +- tests/TestTypeFoundation/CompositeType.cs | 27 +- tests/TestTypeFoundation/ConcreteType.cs | 61 ++-- ...TypeWithPrivateParameterlessConstructor.cs | 17 +- tests/TestTypeFoundation/DoubleFieldHolder.cs | 13 +- .../TestTypeFoundation/DoubleParameterType.cs | 13 +- .../DoublePropertyHolder.cs | 13 +- tests/TestTypeFoundation/EmptyEnum.cs | 11 +- tests/TestTypeFoundation/EnumType.cs | 113 ++++--- tests/TestTypeFoundation/EqualityResponder.cs | 21 +- tests/TestTypeFoundation/FieldHolder.cs | 19 +- tests/TestTypeFoundation/GenericType.cs | 21 +- .../GuardedConstructorHost.cs | 23 +- ...nstructorHostHoldingStaticReadOnlyField.cs | 27 +- ...ructorHostHoldingStaticReadOnlyProperty.cs | 35 +- tests/TestTypeFoundation/GuardedMethodHost.cs | 117 ++++--- .../GuardedPropertyHolder.cs | 31 +- .../GuardedStaticMethodOnStaticTypeHost.cs | 13 +- tests/TestTypeFoundation/IInterface.cs | 11 +- .../IllBehavedPropertyHolder.cs | 41 ++- .../IndexedPropertyHolder.cs | 19 +- .../InternalGetterPropertyHolder.cs | 9 +- tests/TestTypeFoundation/ItemContainer.cs | 25 +- tests/TestTypeFoundation/ItemHolder.cs | 93 +++--- .../MultiUnorderedConstructorType.cs | 55 ++- tests/TestTypeFoundation/MutableValueType.cs | 13 +- .../MutableValueTypeWithoutConstructor.cs | 11 +- .../NonCompliantCollectionHolder.cs | 9 +- .../NoopInterfaceImplementer.cs | 13 +- tests/TestTypeFoundation/PropertyHolder.cs | 27 +- .../QuadrupleParameterType.cs | 17 +- .../TestTypeFoundation/ReadOnlyFieldHolder.cs | 11 +- .../ReadOnlyPropertyHolder.cs | 11 +- tests/TestTypeFoundation/RecordType.cs | 43 ++- .../TestTypeFoundation/SingleParameterType.cs | 11 +- tests/TestTypeFoundation/StaticFieldHolder.cs | 11 +- .../StaticPropertyHolder.cs | 11 +- tests/TestTypeFoundation/TriState.cs | 15 +- .../TestTypeFoundation/TripleParameterType.cs | 15 +- .../TriplePropertyHolder.cs | 15 +- ...thCastOperatorsWithoutPublicConstructor.cs | 25 +- .../TypeWithConcreteParameterMethod.cs | 11 +- .../TypeWithEmptyEnumField.cs | 13 +- .../TypeWithFactoryMethod.cs | 33 +- .../TypeWithFactoryProperty.cs | 21 +- tests/TestTypeFoundation/TypeWithIndexer.cs | 27 +- .../TypeWithOverloadedMembers.cs | 41 ++- .../TypeWithPseudoFactoryMethod.cs | 31 +- tests/TestTypeFoundation/TypeWithRefMethod.cs | 23 +- .../UnguardedConstructorHost.cs | 27 +- .../TestTypeFoundation/UnguardedMethodHost.cs | 21 +- .../UnguardedStaticMethodOnStaticTypeHost.cs | 9 +- ...UnguardedStaticPropertyOnStaticTypeHost.cs | 13 +- 93 files changed, 1940 insertions(+), 2033 deletions(-) diff --git a/build/GitHubActionsExtensions.cs b/build/GitHubActionsExtensions.cs index 3c811e3..acc4949 100644 --- a/build/GitHubActionsExtensions.cs +++ b/build/GitHubActionsExtensions.cs @@ -1,15 +1,14 @@ using System.Text.RegularExpressions; -namespace Nuke.Common.CI.GitHubActions +namespace Nuke.Common.CI.GitHubActions; + +public static class GitHubActionsExtensions { - public static class GitHubActionsExtensions - { - private static readonly Regex SemVerRef = new(@"^refs\/tags\/v(?\d+\.\d+\.\d+)", RegexOptions.Compiled); + private static readonly Regex SemVerRef = new(@"^refs\/tags\/v(?\d+\.\d+\.\d+)", RegexOptions.Compiled); - public static bool IsOnSemVerTag(this GitHubActions source) - { - return !string.IsNullOrWhiteSpace(source?.Ref) - && SemVerRef.IsMatch(source.Ref); - } + public static bool IsOnSemVerTag(this GitHubActions source) + { + return !string.IsNullOrWhiteSpace(source?.Ref) + && SemVerRef.IsMatch(source.Ref); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs index 57703a7..3fef5b6 100644 --- a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -1,54 +1,53 @@ using System.Diagnostics.CodeAnalysis; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// Provides a data source for a data theory, with the data coming from inline +/// values combined with auto-generated data specimens generated by AutoFixture. +/// +[CLSCompliant(false)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute { /// - /// Provides a data source for a data theory, with the data coming from inline - /// values combined with auto-generated data specimens generated by AutoFixture. + /// Initializes a new instance of the class. /// - [CLSCompliant(false)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute + /// The data values to pass to the theory. + public ArgumentsAutoDataAttribute(params object[] values) + : this(() => new Fixture(), values) { - /// - /// Initializes a new instance of the class. - /// - /// The data values to pass to the theory. - public ArgumentsAutoDataAttribute(params object[] values) - : this(() => new Fixture(), values) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The fixture factory. - /// The data values to pass to the theory. - /// - protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) - { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.Values = values ?? new object[] { null }; - } + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory. + /// The data values to pass to the theory. + /// + protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.Values = values ?? new object[] { null }; + } - /// - /// Gets the fixture factory. - /// - public Func FixtureFactory { get; } + /// + /// Gets the fixture factory. + /// + public Func FixtureFactory { get; } - /// - /// Gets the data values to pass to the theory. - /// - public object[] Values { get; } + /// + /// Gets the data values to pass to the theory. + /// + public object[] Values { get; } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) - .GenerateDataSources(dataGeneratorMetadata) - .Select(x => x()); - } + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) + .GenerateDataSources(dataGeneratorMetadata) + .Select(x => x()); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs index 798d754..39ae64d 100644 --- a/src/AutoFixture.TUnit/AutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -1,53 +1,52 @@ using System.Diagnostics.CodeAnalysis; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// Provides auto-generated data specimens generated by AutoFixture as an extension to +/// xUnit.net's Theory attribute. +/// +[CLSCompliant(false)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class AutoDataAttribute : AutoFixtureDataSourceAttribute { /// - /// Provides auto-generated data specimens generated by AutoFixture as an extension to - /// xUnit.net's Theory attribute. + /// Initializes a new instance of the class. /// - [CLSCompliant(false)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class AutoDataAttribute : AutoFixtureDataSourceAttribute + /// + /// + /// This constructor overload initializes the to an instance of + /// . + /// + /// + public AutoDataAttribute() + : this(() => new Fixture()) { - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// This constructor overload initializes the to an instance of - /// . - /// - /// - public AutoDataAttribute() - : this(() => new Fixture()) - { - } + } - /// - /// Initializes a new instance of the class - /// with the supplied . Fixture will be created - /// on demand using the provided factory. - /// - /// The fixture factory used to construct the fixture. - protected AutoDataAttribute(Func fixtureFactory) - { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - } + /// + /// Initializes a new instance of the class + /// with the supplied . Fixture will be created + /// on demand using the provided factory. + /// + /// The fixture factory used to construct the fixture. + protected AutoDataAttribute(Func fixtureFactory) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + } - /// - /// Gets the fixture factory. - /// - public Func FixtureFactory { get; } + /// + /// Gets the fixture factory. + /// + public Func FixtureFactory { get; } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - var source = new AutoDataSource(this.FixtureFactory); + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var source = new AutoDataSource(this.FixtureFactory); - return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); - } + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs index 3da73ca..8e532be 100644 --- a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -1,104 +1,103 @@ using System.Diagnostics.CodeAnalysis; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// Provides a data source for a data theory, with the data coming from a class +/// which must implement IEnumerable<object?[]>, +/// combined with auto-generated data specimens generated by AutoFixture. +/// +[CLSCompliant(false)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute { /// - /// Provides a data source for a data theory, with the data coming from a class - /// which must implement IEnumerable<object?[]>, - /// combined with auto-generated data specimens generated by AutoFixture. + /// Initializes a new instance of the class. /// - [CLSCompliant(false)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute + /// The type of the class that provides the data. + /// The parameters passed to the data provider class constructor. + public ClassAutoDataAttribute(Type sourceType, params object[] parameters) + : this(() => new Fixture(), sourceType, parameters) { - /// - /// Initializes a new instance of the class. - /// - /// The type of the class that provides the data. - /// The parameters passed to the data provider class constructor. - public ClassAutoDataAttribute(Type sourceType, params object[] parameters) - : this(() => new Fixture(), sourceType, parameters) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The fixture factory that provides missing data from . - /// The type of the class that provides the data. - /// The parameters passed to the data provider class constructor. - /// - /// This constructor overload exists to enable a derived attribute to - /// supply a custom fixture factory that again may contain custom behavior. - /// - /// - /// In the following example MyTestData is a class that provides test data, - /// that would be complicated or probably impossible to provide using other options. - /// The missing arguments for the test are being supplied from the Fixture instance. - /// - /// [Theory] - /// [CustomAutoClassData(typeof(MyTestData))] - /// public void ClassDataSuppliesExtraValues(int sum, int[] numbers, Person client) - /// { - /// var actual = numbers.Sum(x => x); - /// - /// Assert.Equal(sum, actual); - /// Assert.NotNull(client); - /// } - /// - /// private class CustomAutoClassData : ClassAutoDataAttribute - /// { - /// public CustomAutoClassData(Type sourceType) : - /// base(() => new Fixture(), sourceType) - /// { - /// } - /// } - /// - /// private class MyTestData : IEnumerable<object[]> - /// { - /// public IEnumerator<object[]> GetEnumerator() - /// { - /// yield return new object[] { 0, new int[0] }; - /// yield return new object[] { 4, new int[] { 1, 2, 1} }; - /// yield return new object[] { 23, new int [] { 0, 13, 15, -5 } }; - /// } - /// - /// IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); - /// } - /// - /// - protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) - { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); - this.Parameters = parameters ?? new object[] { null }; - } + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory that provides missing data from . + /// The type of the class that provides the data. + /// The parameters passed to the data provider class constructor. + /// + /// This constructor overload exists to enable a derived attribute to + /// supply a custom fixture factory that again may contain custom behavior. + /// + /// + /// In the following example MyTestData is a class that provides test data, + /// that would be complicated or probably impossible to provide using other options. + /// The missing arguments for the test are being supplied from the Fixture instance. + /// + /// [Theory] + /// [CustomAutoClassData(typeof(MyTestData))] + /// public void ClassDataSuppliesExtraValues(int sum, int[] numbers, Person client) + /// { + /// var actual = numbers.Sum(x => x); + /// + /// Assert.Equal(sum, actual); + /// Assert.NotNull(client); + /// } + /// + /// private class CustomAutoClassData : ClassAutoDataAttribute + /// { + /// public CustomAutoClassData(Type sourceType) : + /// base(() => new Fixture(), sourceType) + /// { + /// } + /// } + /// + /// private class MyTestData : IEnumerable<object[]> + /// { + /// public IEnumerator<object[]> GetEnumerator() + /// { + /// yield return new object[] { 0, new int[0] }; + /// yield return new object[] { 4, new int[] { 1, 2, 1} }; + /// yield return new object[] { 23, new int [] { 0, 13, 15, -5 } }; + /// } + /// + /// IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + /// } + /// + /// + protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); + this.Parameters = parameters ?? new object[] { null }; + } - /// - /// Gets the fixture factory that provides the missing data from . - /// - public Func FixtureFactory { get; } + /// + /// Gets the fixture factory that provides the missing data from . + /// + public Func FixtureFactory { get; } - /// - /// Gets the type of the class that provides the data. - /// - public Type SourceType { get; } + /// + /// Gets the type of the class that provides the data. + /// + public Type SourceType { get; } - /// - /// Gets the constructor parameters for . - /// - public object[] Parameters { get; } + /// + /// Gets the constructor parameters for . + /// + public object[] Parameters { get; } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - var source = new AutoDataSource( - this.FixtureFactory, - new ClassDataSource(this.SourceType, this.Parameters)); + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var source = new AutoDataSource( + this.FixtureFactory, + new ClassDataSource(this.SourceType, this.Parameters)); - return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); - } + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index 6e6c49f..2b1e310 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -1,59 +1,58 @@ using System.Diagnostics.CodeAnalysis; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An implementation of DataAttribute that composes other DataAttribute instances. +/// +[CLSCompliant(false)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class CompositeDataAttribute : AutoFixtureDataSourceAttribute { + private readonly AutoFixtureDataSourceAttribute[] attributes; + /// - /// An implementation of DataAttribute that composes other DataAttribute instances. + /// Initializes a new instance of the class. /// - [CLSCompliant(false)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class CompositeDataAttribute : AutoFixtureDataSourceAttribute + /// The attributes representing a data source for a data theory. + public CompositeDataAttribute(IEnumerable attributes) + : this(attributes as AutoFixtureDataSourceAttribute[] ?? attributes.ToArray()) { - private readonly AutoFixtureDataSourceAttribute[] attributes; - - /// - /// Initializes a new instance of the class. - /// - /// The attributes representing a data source for a data theory. - public CompositeDataAttribute(IEnumerable attributes) - : this(attributes as AutoFixtureDataSourceAttribute[] ?? attributes.ToArray()) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The attributes representing a data source for a data theory. - public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) - { - this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); - } + /// + /// Initializes a new instance of the class. + /// + /// The attributes representing a data source for a data theory. + public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) + { + this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); + } - /// - /// Gets the attributes supplied through one of the constructors. - /// - public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); + /// + /// Gets the attributes supplied through one of the constructors. + /// + public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); - /// - public override IEnumerable GetData(DataGeneratorMetadata metadata) + /// + public override IEnumerable GetData(DataGeneratorMetadata metadata) + { + if (metadata is null) { - if (metadata is null) - { - throw new ArgumentNullException(nameof(metadata)); - } + throw new ArgumentNullException(nameof(metadata)); + } - var results = this.attributes - .Select(attr => attr.GenerateDataSources(metadata)) - .ToArray(); + var results = this.attributes + .Select(attr => attr.GenerateDataSources(metadata)) + .ToArray(); - var theoryRows = results - .Select(x => x.Select(y => y())) - .Zip(dataSets => dataSets.Collapse().ToArray()) - .ToArray(); + var theoryRows = results + .Select(x => x.Select(y => y())) + .Zip(dataSets => dataSets.Collapse().ToArray()) + .ToArray(); - return theoryRows; - } + return theoryRows; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/CustomizeAttribute.cs b/src/AutoFixture.TUnit/CustomizeAttribute.cs index 2e78b63..450faa3 100644 --- a/src/AutoFixture.TUnit/CustomizeAttribute.cs +++ b/src/AutoFixture.TUnit/CustomizeAttribute.cs @@ -1,19 +1,18 @@ using System.Reflection; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// Base class for customizing parameters in methods decorated with +/// . +/// +[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] +public abstract class CustomizeAttribute : Attribute, IParameterCustomizationSource { /// - /// Base class for customizing parameters in methods decorated with - /// . + /// Gets a customization for a parameter. /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] - public abstract class CustomizeAttribute : Attribute, IParameterCustomizationSource - { - /// - /// Gets a customization for a parameter. - /// - /// The parameter for which the customization is requested. - /// A customization for the parameter. - public abstract ICustomization GetCustomization(ParameterInfo parameter); - } + /// The parameter for which the customization is requested. + /// A customization for the parameter. + public abstract ICustomization GetCustomization(ParameterInfo parameter); } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/FavorArraysAttribute.cs b/src/AutoFixture.TUnit/FavorArraysAttribute.cs index bf0173b..8038009 100644 --- a/src/AutoFixture.TUnit/FavorArraysAttribute.cs +++ b/src/AutoFixture.TUnit/FavorArraysAttribute.cs @@ -1,33 +1,32 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be created using a constructor with one +/// or more array arguments, if applicable. +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class FavorArraysAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be created using a constructor with one - /// or more array arguments, if applicable. + /// Gets a customization that associates a with + /// the of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class FavorArraysAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that associates a with - /// the of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that associates a with the - /// of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter is null) { - if (parameter is null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - return new ConstructorCustomization(parameter.ParameterType, new ArrayFavoringConstructorQuery()); + throw new ArgumentNullException(nameof(parameter)); } + + return new ConstructorCustomization(parameter.ParameterType, new ArrayFavoringConstructorQuery()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs b/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs index bf402ae..6564e47 100644 --- a/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs +++ b/src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs @@ -1,33 +1,32 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be created using a constructor with one +/// or more arguments, if applicable. +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class FavorEnumerablesAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be created using a constructor with one - /// or more arguments, if applicable. + /// Gets a customization that associates a + /// with the of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class FavorEnumerablesAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with + /// the of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that associates a - /// with the of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that associates a with - /// the of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter == null) { - if (parameter == null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - return new ConstructorCustomization(parameter.ParameterType, new EnumerableFavoringConstructorQuery()); + throw new ArgumentNullException(nameof(parameter)); } + + return new ConstructorCustomization(parameter.ParameterType, new EnumerableFavoringConstructorQuery()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/FavorListsAttribute.cs b/src/AutoFixture.TUnit/FavorListsAttribute.cs index 1eeb80b..3a9399f 100644 --- a/src/AutoFixture.TUnit/FavorListsAttribute.cs +++ b/src/AutoFixture.TUnit/FavorListsAttribute.cs @@ -1,33 +1,32 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be created using a constructor with one +/// or more arguments, if applicable. +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class FavorListsAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be created using a constructor with one - /// or more arguments, if applicable. + /// Gets a customization that associates a with + /// the of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class FavorListsAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that associates a with - /// the of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that associates a with the - /// of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter == null) { - if (parameter == null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - return new ConstructorCustomization(parameter.ParameterType, new ListFavoringConstructorQuery()); + throw new ArgumentNullException(nameof(parameter)); } + + return new ConstructorCustomization(parameter.ParameterType, new ListFavoringConstructorQuery()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/FrozenAttribute.cs b/src/AutoFixture.TUnit/FrozenAttribute.cs index aa20907..4b50c8f 100644 --- a/src/AutoFixture.TUnit/FrozenAttribute.cs +++ b/src/AutoFixture.TUnit/FrozenAttribute.cs @@ -2,72 +2,71 @@ using System.Reflection; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be frozen so that the same instance is +/// returned every time the creates an instance of that type. +/// +[AttributeUsage(AttributeTargets.Parameter)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class FrozenAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be frozen so that the same instance is - /// returned every time the creates an instance of that type. + /// Initializes a new instance of the class. /// - [AttributeUsage(AttributeTargets.Parameter)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class FrozenAttribute : CustomizeAttribute + /// + /// The criteria used to determine + /// which requests will be satisfied by the frozen parameter value + /// is . + /// + public FrozenAttribute() + : this(Matching.ExactType) { - /// - /// Initializes a new instance of the class. - /// - /// - /// The criteria used to determine - /// which requests will be satisfied by the frozen parameter value - /// is . - /// - public FrozenAttribute() - : this(Matching.ExactType) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// - /// The criteria used to determine - /// which requests will be satisfied by the frozen parameter value. - /// - public FrozenAttribute(Matching by) - { - this.By = by; - } + /// + /// Initializes a new instance of the class. + /// + /// + /// The criteria used to determine + /// which requests will be satisfied by the frozen parameter value. + /// + public FrozenAttribute(Matching by) + { + this.By = by; + } - /// - /// Gets the criteria used to determine - /// which requests will be satisfied by the frozen parameter value. - /// - public Matching By { get; } + /// + /// Gets the criteria used to determine + /// which requests will be satisfied by the frozen parameter value. + /// + public Matching By { get; } - /// - /// Gets a configured - /// to match requests based on the and optionally - /// the name of the parameter. - /// - /// - /// The parameter for which the customization is requested. - /// - /// - /// A configured - /// to match requests based on the and optionally - /// the name of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + /// + /// Gets a configured + /// to match requests based on the and optionally + /// the name of the parameter. + /// + /// + /// The parameter for which the customization is requested. + /// + /// + /// A configured + /// to match requests based on the and optionally + /// the name of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) + { + if (parameter is null) { - if (parameter is null) - { - throw new ArgumentNullException(nameof(parameter)); - } + throw new ArgumentNullException(nameof(parameter)); + } - var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); + var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); - return new FreezeOnMatchCustomization(parameter, matcher); - } + return new FreezeOnMatchCustomization(parameter, matcher); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/GreedyAttribute.cs b/src/AutoFixture.TUnit/GreedyAttribute.cs index bea3562..876420c 100644 --- a/src/AutoFixture.TUnit/GreedyAttribute.cs +++ b/src/AutoFixture.TUnit/GreedyAttribute.cs @@ -1,33 +1,32 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be created using the most greedy +/// constructor that can be satisfied by an . +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class GreedyAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be created using the most greedy - /// constructor that can be satisfied by an . + /// Gets a customization that associates a with the + /// of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class GreedyAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that associates a with the - /// of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that associates a with the - /// of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter is null) { - if (parameter is null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - return new ConstructorCustomization(parameter.ParameterType, new GreedyConstructorQuery()); + throw new ArgumentNullException(nameof(parameter)); } + + return new ConstructorCustomization(parameter.ParameterType, new GreedyConstructorQuery()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index 3e79dd8..0062521 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -1,11 +1,10 @@ -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal class Argument(TestParameter parameter, object value) { - internal class Argument(TestParameter parameter, object value) - { - public TestParameter Parameter { get; } = parameter ?? throw new ArgumentNullException(nameof(parameter)); + public TestParameter Parameter { get; } = parameter ?? throw new ArgumentNullException(nameof(parameter)); - public object Value { get; } = value; + public object Value { get; } = value; - public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); - } + public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs index 2726eb4..9180708 100644 --- a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -1,93 +1,92 @@ using AutoFixture.TUnit.Extensions; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Combines the values from a source with auto-generated values. +/// +public class AutoDataSource : DataSource { /// - /// Combines the values from a source with auto-generated values. + /// Initializes a new instance of the class. /// - public class AutoDataSource : DataSource + /// The factory method for creating a fixture. + /// The source of test data to combine with auto-generated values. + /// + /// Thrown when is . + /// + public AutoDataSource(Func createFixture, IDataSource? source = default) { - /// - /// Initializes a new instance of the class. - /// - /// The factory method for creating a fixture. - /// The source of test data to combine with auto-generated values. - /// - /// Thrown when is . - /// - public AutoDataSource(Func createFixture, IDataSource? source = default) - { - this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); - this.Source = source; - } - - /// - /// Gets the factory method for creating a fixture. - /// - public Func CreateFixture { get; } - - /// - /// Gets the source of test data to combine with auto-generated values. - /// - public IDataSource? Source { get; } - - /// - /// Returns the combined test data provided by the source and auto-generated values. - /// - /// The target method for which to provide the arguments. - /// Returns a sequence of argument collections. - public override IEnumerable GetData(DataGeneratorMetadata metadata) - { - return this.Source is null - ? this.GenerateValues(metadata) - : this.CombineValues(metadata, this.Source); - } - - private IEnumerable GenerateValues(DataGeneratorMetadata metadata) - { - var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); - var fixture = this.CreateFixture(); - yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); - } - - private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDataSource source) - { - var method = metadata.GetMethod(); + this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); + this.Source = source; + } - var parameters = Array.ConvertAll(method.GetParameters(), TestParameter.From); + /// + /// Gets the factory method for creating a fixture. + /// + public Func CreateFixture { get; } - foreach (var testData in source.GetData(metadata)) - { - var customizations = parameters.Take(testData.Length) - .Zip(testData, (parameter, value) => new Argument(parameter, value)) - .Select(argument => argument.GetCustomization()) - .Where(x => x is not NullCustomization); + /// + /// Gets the source of test data to combine with auto-generated values. + /// + public IDataSource? Source { get; } - var fixture = this.CreateFixture(); + /// + /// Returns the combined test data provided by the source and auto-generated values. + /// + /// The target method for which to provide the arguments. + /// Returns a sequence of argument collections. + public override IEnumerable GetData(DataGeneratorMetadata metadata) + { + return this.Source is null + ? this.GenerateValues(metadata) + : this.CombineValues(metadata, this.Source); + } - foreach (var customization in customizations) - { - fixture.Customize(customization); - } + private IEnumerable GenerateValues(DataGeneratorMetadata metadata) + { + var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); + var fixture = this.CreateFixture(); + yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); + } - var missingValues = parameters.Skip(testData.Length) - .Select(parameter => GenerateAutoValue(parameter, fixture)) - .ToArray(); + private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDataSource source) + { + var method = metadata.GetMethod(); - yield return testData.Concat(missingValues).ToArray(); - } - } + var parameters = Array.ConvertAll(method.GetParameters(), TestParameter.From); - private static object GenerateAutoValue(TestParameter parameter, IFixture fixture) + foreach (var testData in source.GetData(metadata)) { - var customization = parameter.GetCustomization(); + var customizations = parameters.Take(testData.Length) + .Zip(testData, (parameter, value) => new Argument(parameter, value)) + .Select(argument => argument.GetCustomization()) + .Where(x => x is not NullCustomization); + + var fixture = this.CreateFixture(); - if (customization is not NullCustomization) + foreach (var customization in customizations) { fixture.Customize(customization); } - return fixture.Resolve(parameter.ParameterInfo); + var missingValues = parameters.Skip(testData.Length) + .Select(parameter => GenerateAutoValue(parameter, fixture)) + .ToArray(); + + yield return testData.Concat(missingValues).ToArray(); } } + + private static object GenerateAutoValue(TestParameter parameter, IFixture fixture) + { + var customization = parameter.GetCustomization(); + + if (customization is not NullCustomization) + { + fixture.Customize(customization); + } + + return fixture.Resolve(parameter.ParameterInfo); + } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs index 90e0ad5..e1f0376 100644 --- a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -1,49 +1,48 @@ using System.Diagnostics.CodeAnalysis; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Encapsulates the access to a test data source type. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] +public class ClassDataSource : DataSource { + private readonly object[] parameters; + /// - /// Encapsulates the access to a test data source type. + /// Creates an instance of type . /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "Type is not a collection.")] - public class ClassDataSource : DataSource + /// The test data source type. + /// Constructor arguments for the source type. + /// Thrown when arguments are . + public ClassDataSource(Type type, params object[] parameters) { - private readonly object[] parameters; - - /// - /// Creates an instance of type . - /// - /// The test data source type. - /// Constructor arguments for the source type. - /// Thrown when arguments are . - public ClassDataSource(Type type, params object[] parameters) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); - } - - /// - /// Gets the test data source type. - /// - public Type Type { get; } + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + } - /// - /// Gets the constructor parameters for test data source type. - /// - public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); + /// + /// Gets the test data source type. + /// + public Type Type { get; } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); + /// + /// Gets the constructor parameters for test data source type. + /// + public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); - if (instance is not IEnumerable enumerable) - { - throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); - } + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); - return enumerable; + if (instance is not IEnumerable enumerable) + { + throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); } + + return enumerable; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs b/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs index ad39704..b447722 100644 --- a/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs +++ b/src/AutoFixture.TUnit/Internal/CustomizationExtensions.cs @@ -1,10 +1,9 @@ using AutoFixture.Kernel; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal static class CustomizationExtensions { - internal static class CustomizationExtensions - { - public static object Resolve(this IFixture source, object request) - => new SpecimenContext(source).Resolve(request); - } + public static object Resolve(this IFixture source, object request) + => new SpecimenContext(source).Resolve(request); } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs index b196f12..42131b9 100644 --- a/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs +++ b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs @@ -1,15 +1,14 @@ -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal class CustomizeAttributeComparer : Comparer { - internal class CustomizeAttributeComparer : Comparer + public override int Compare(IParameterCustomizationSource x, IParameterCustomizationSource y) { - public override int Compare(IParameterCustomizationSource x, IParameterCustomizationSource y) + return (x is FrozenAttribute, y is FrozenAttribute) switch { - return (x is FrozenAttribute, y is FrozenAttribute) switch - { - (true, false) => 1, - (false, true) => -1, - _ => 0 - }; - } + (true, false) => 1, + (false, true) => -1, + _ => 0 + }; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/DataSource.cs b/src/AutoFixture.TUnit/Internal/DataSource.cs index 85efa95..5d9560c 100644 --- a/src/AutoFixture.TUnit/Internal/DataSource.cs +++ b/src/AutoFixture.TUnit/Internal/DataSource.cs @@ -1,13 +1,12 @@ using System.Diagnostics.CodeAnalysis; -namespace AutoFixture.TUnit.Internal -{ - /// - /// The base class for test case sources. - /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "The type is not a collection.")] - [SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", - Justification = "The type is not a collection.")] - public abstract class DataSource : AutoFixtureDataSourceAttribute, IDataSource; -} \ No newline at end of file +namespace AutoFixture.TUnit.Internal; + +/// +/// The base class for test case sources. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "The type is not a collection.")] +[SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", + Justification = "The type is not a collection.")] +public abstract class DataSource : AutoFixtureDataSourceAttribute, IDataSource; \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs index 4d95409..7e893b8 100644 --- a/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs +++ b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs @@ -1,58 +1,57 @@ -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal static class EnumerableExtensions { - internal static class EnumerableExtensions + /// + /// Applies a specified function to the corresponding elements of any number of sequences. + /// + /// The type of the elements of the input sequences. + /// The type of the elements of the result sequence. + /// The input sequences. + /// A function that specifies how to combine the corresponding elements of the sequences. + /// An that contains elements of the input sequences, combined by resultSelector. + internal static IEnumerable Zip(this IEnumerable> sequences, + Func, TResult> resultSelector) { - /// - /// Applies a specified function to the corresponding elements of any number of sequences. - /// - /// The type of the elements of the input sequences. - /// The type of the elements of the result sequence. - /// The input sequences. - /// A function that specifies how to combine the corresponding elements of the sequences. - /// An that contains elements of the input sequences, combined by resultSelector. - internal static IEnumerable Zip(this IEnumerable> sequences, - Func, TResult> resultSelector) + var enumerators = sequences.Select(s => s.GetEnumerator()).ToList(); + while (enumerators.TrueForAll(e => e.MoveNext())) { - var enumerators = sequences.Select(s => s.GetEnumerator()).ToList(); - while (enumerators.TrueForAll(e => e.MoveNext())) - { - yield return resultSelector(enumerators.Select(e => e.Current)); - } + yield return resultSelector(enumerators.Select(e => e.Current)); } + } - /// - /// Collapses a series of sequences down by using items from the first sequence until it finishes, - /// then continuing from the same index through the second sequence, and so on until all sequences - /// have been exhausted. - /// - /// The type of the elements of the input sequences. - /// The input sequences. - /// Items from each sequence in turn, yielding those from the first sequence first. - internal static IEnumerable Collapse(this IEnumerable> sequences) + /// + /// Collapses a series of sequences down by using items from the first sequence until it finishes, + /// then continuing from the same index through the second sequence, and so on until all sequences + /// have been exhausted. + /// + /// The type of the elements of the input sequences. + /// The input sequences. + /// Items from each sequence in turn, yielding those from the first sequence first. + internal static IEnumerable Collapse(this IEnumerable> sequences) + { + var position = 0; + foreach (var sequence in sequences) { - var position = 0; - foreach (var sequence in sequences) + foreach (var item in sequence.Skip(position)) { - foreach (var item in sequence.Skip(position)) - { - position++; - yield return item; - } + position++; + yield return item; } } + } - /// - /// Casts the source sequence to an . - /// Enumerates the source sequence to an array if it is not an enumerated collection. - /// - /// The source sequence. - /// The sequence item type. - /// An that contains elements of the source sequence. - public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) - { - return source is not null - ? source as IReadOnlyCollection ?? source.ToArray() - : null; - } + /// + /// Casts the source sequence to an . + /// Enumerates the source sequence to an array if it is not an enumerated collection. + /// + /// The source sequence. + /// The sequence item type. + /// An that contains elements of the source sequence. + public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) + { + return source is not null + ? source as IReadOnlyCollection ?? source.ToArray() + : null; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs index dff73b1..193f2e9 100644 --- a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs @@ -1,48 +1,47 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Encapsulates access to a field that provides test data. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] +public class FieldDataSource : DataSource { /// - /// Encapsulates access to a field that provides test data. + /// Creates an instance of type . /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "Type is not a collection.")] - public class FieldDataSource : DataSource + /// The source field info. + /// + /// Thrown when is . + /// + public FieldDataSource(FieldInfo fieldInfo) { - /// - /// Creates an instance of type . - /// - /// The source field info. - /// - /// Thrown when is . - /// - public FieldDataSource(FieldInfo fieldInfo) - { - this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); - } + this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); + } - /// - /// Gets the source field. - /// - public FieldInfo FieldInfo { get; } + /// + /// Gets the source field. + /// + public FieldInfo FieldInfo { get; } - /// - /// Gets the test data from the source field. - /// - /// Returns a sequence of argument collections. - /// - /// Thrown when the field does not return an enumerable value. - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + /// + /// Gets the test data from the source field. + /// + /// Returns a sequence of argument collections. + /// + /// Thrown when the field does not return an enumerable value. + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.FieldInfo.GetValue(null); + if (value is not IEnumerable enumerable) { - var value = this.FieldInfo.GetValue(null); - if (value is not IEnumerable enumerable) - { - throw new InvalidCastException("Member does not return an enumerable value."); - } - - return enumerable; + throw new InvalidCastException("Member does not return an enumerable value."); } + + return enumerable; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index a01d3ea..e867d13 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -1,18 +1,17 @@ using AutoFixture.Kernel; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization { - internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization - { - private readonly IRequestSpecification specification = specification ?? throw new ArgumentNullException(nameof(specification)); + private readonly IRequestSpecification specification = specification ?? throw new ArgumentNullException(nameof(specification)); - public void Customize(IFixture fixture) - { - var builder = new FilteringSpecimenBuilder( - builder: new FixedBuilder(value), - specification: this.specification); + public void Customize(IFixture fixture) + { + var builder = new FilteringSpecimenBuilder( + builder: new FixedBuilder(value), + specification: this.specification); - fixture.Customizations.Insert(0, builder); - } + fixture.Customizations.Insert(0, builder); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/IDataSource.cs b/src/AutoFixture.TUnit/Internal/IDataSource.cs index 3ade698..7fa5279 100644 --- a/src/AutoFixture.TUnit/Internal/IDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/IDataSource.cs @@ -1,15 +1,14 @@ -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Exposes the factory method for a sequence of test data. +/// +public interface IDataSource { /// - /// Exposes the factory method for a sequence of test data. + /// Returns the test data provided by the source. /// - public interface IDataSource - { - /// - /// Returns the test data provided by the source. - /// - /// The target method for which to provide the arguments. - /// Returns a sequence of argument collections. - IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); - } + /// The target method for which to provide the arguments. + /// Returns a sequence of argument collections. + IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs index de305ce..e57ba67 100644 --- a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -1,49 +1,48 @@ using System.Diagnostics.CodeAnalysis; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Provides test data from a predefined collection of values. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] +public sealed class InlineDataSource : AutoFixtureDataSourceAttribute { + private readonly object[] values; + /// - /// Provides test data from a predefined collection of values. + /// Creates an instance of type . /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "Type is not a collection.")] - public sealed class InlineDataSource : AutoFixtureDataSourceAttribute + /// The collection of inline values. + /// + /// Thrown when the values collection is . + /// + public InlineDataSource(object[] values) { - private readonly object[] values; + this.values = values ?? throw new ArgumentNullException(nameof(values)); + } + + /// + /// The collection of inline values. + /// + public IReadOnlyList Values => Array.AsReadOnly(this.values); - /// - /// Creates an instance of type . - /// - /// The collection of inline values. - /// - /// Thrown when the values collection is . - /// - public InlineDataSource(object[] values) + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + if (dataGeneratorMetadata is null) { - this.values = values ?? throw new ArgumentNullException(nameof(values)); + throw new ArgumentNullException(nameof(dataGeneratorMetadata)); } - /// - /// The collection of inline values. - /// - public IReadOnlyList Values => Array.AsReadOnly(this.values); - - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; + if (this.values.Length > membersToGenerate.Length) { - if (dataGeneratorMetadata is null) - { - throw new ArgumentNullException(nameof(dataGeneratorMetadata)); - } - - var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; - if (this.values.Length > membersToGenerate.Length) - { - throw new InvalidOperationException( - "The number of arguments provided exceeds the number of parameters."); - } - - yield return this.values; + throw new InvalidOperationException( + "The number of arguments provided exceeds the number of parameters."); } + + yield return this.values; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs index 5f7dcbc..1a9a1d9 100644 --- a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -1,89 +1,88 @@ using System.Globalization; using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Encapsulates access to a member that provides test data. +/// +public class MemberDataSource : IDataSource { + private readonly object[] arguments; + /// - /// Encapsulates access to a member that provides test data. + /// Creates an instance of type . /// - public class MemberDataSource : IDataSource + /// The containing type of the member. + /// The name of the member. + /// The arguments provided to the member. + /// Thrown when arguments are . + public MemberDataSource(Type type, string name, params object[] arguments) { - private readonly object[] arguments; + this.Type = type ?? throw new ArgumentNullException(nameof(type)); + this.Name = name ?? throw new ArgumentNullException(nameof(name)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + this.Source = this.GetTestDataSource(); + } - /// - /// Creates an instance of type . - /// - /// The containing type of the member. - /// The name of the member. - /// The arguments provided to the member. - /// Thrown when arguments are . - public MemberDataSource(Type type, string name, params object[] arguments) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); - this.Source = this.GetTestDataSource(); - } + /// + /// Gets the containing type of the member. + /// + public Type Type { get; } - /// - /// Gets the containing type of the member. - /// - public Type Type { get; } + /// + /// Gets the name of the member. + /// + public string Name { get; } - /// - /// Gets the name of the member. - /// - public string Name { get; } + /// + /// Gets the arguments provided to the member. + /// + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); - /// - /// Gets the arguments provided to the member. - /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + /// + /// Gets the test data source. + /// + protected DataSource Source { get; } - /// - /// Gets the test data source. - /// - protected DataSource Source { get; } + private DataSource GetTestDataSource() + { + var sourceMember = this.Type.GetMember(this.Name, + MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, + BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) + .FirstOrDefault(); - private DataSource GetTestDataSource() + if (sourceMember is null) { - var sourceMember = this.Type.GetMember(this.Name, - MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, - BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) - .FirstOrDefault(); - - if (sourceMember is null) - { - var message = string.Format( - CultureInfo.CurrentCulture, - "Could not find public static member (property, field, or method) named '{0}' on {1}", - this.Name, this.Type.FullName); - throw new ArgumentException(message); - } - - var returnType = sourceMember.GetReturnType(); - if (!typeof(IEnumerable).IsAssignableFrom(returnType)) - { - var message = string.Format( - CultureInfo.CurrentCulture, - "Member {0} on {1} does not return IEnumerable", - this.Name, this.Type.FullName); - throw new ArgumentException(message); - } - - return sourceMember switch - { - FieldInfo fieldInfo => new FieldDataSource(fieldInfo), - PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), - MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), - _ => throw new InvalidOperationException("Unsupported member type.") - }; + var message = string.Format( + CultureInfo.CurrentCulture, + "Could not find public static member (property, field, or method) named '{0}' on {1}", + this.Name, this.Type.FullName); + throw new ArgumentException(message); } - /// - public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + var returnType = sourceMember.GetReturnType(); + if (!typeof(IEnumerable).IsAssignableFrom(returnType)) { - return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + var message = string.Format( + CultureInfo.CurrentCulture, + "Member {0} on {1} does not return IEnumerable", + this.Name, this.Type.FullName); + throw new ArgumentException(message); } + + return sourceMember switch + { + FieldInfo fieldInfo => new FieldDataSource(fieldInfo), + PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), + MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), + _ => throw new InvalidOperationException("Unsupported member type.") + }; + } + + /// + public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs index 973bea1..382b312 100644 --- a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -1,48 +1,47 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Encapsulates access to a method that provides test data. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] +public class MethodDataSource : DataSource { + private readonly object[] arguments; + /// - /// Encapsulates access to a method that provides test data. + /// Creates an instance of type . /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "Type is not a collection.")] - public class MethodDataSource : DataSource + /// The source method. + /// The source method arguments. + public MethodDataSource(MethodInfo methodInfo, params object[] arguments) { - private readonly object[] arguments; - - /// - /// Creates an instance of type . - /// - /// The source method. - /// The source method arguments. - public MethodDataSource(MethodInfo methodInfo, params object[] arguments) - { - this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); - } + this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); + this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + } - /// - /// Gets the source method info. - /// - public MethodInfo MethodInfo { get; } + /// + /// Gets the source method info. + /// + public MethodInfo MethodInfo { get; } - /// - /// Gets the source method arguments. - /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + /// + /// Gets the source method arguments. + /// + public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.MethodInfo.Invoke(null, this.arguments); + if (value is not IEnumerable enumerable) { - var value = this.MethodInfo.Invoke(null, this.arguments); - if (value is not IEnumerable enumerable) - { - throw new InvalidCastException("Member does not return an enumerable value."); - } - - return enumerable; + throw new InvalidCastException("Member does not return an enumerable value."); } + + return enumerable; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/NullCustomization.cs b/src/AutoFixture.TUnit/Internal/NullCustomization.cs index 0d5e1f1..18b2b09 100644 --- a/src/AutoFixture.TUnit/Internal/NullCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/NullCustomization.cs @@ -1,20 +1,19 @@ -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal sealed class NullCustomization : ICustomization { - internal sealed class NullCustomization : ICustomization + private NullCustomization() { - private NullCustomization() - { - // prevent external instantiation - } + // prevent external instantiation + } - private static readonly Lazy LazyInstance = new( - () => new NullCustomization(), isThreadSafe: true); + private static readonly Lazy LazyInstance = new( + () => new NullCustomization(), isThreadSafe: true); - public static NullCustomization Instance => LazyInstance.Value; + public static NullCustomization Instance => LazyInstance.Value; - public void Customize(IFixture fixture) - { - // intentionally left blank - } + public void Customize(IFixture fixture) + { + // intentionally left blank } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index ecd68a8..d6e10db 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -1,43 +1,42 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Specification for identifying requests that match the test parameter by provided criteria. +/// +internal class ParameterFilter : IRequestSpecification { + private readonly IRequestSpecification matcherSpecification; + /// - /// Specification for identifying requests that match the test parameter by provided criteria. + /// Creates an instance of type . /// - internal class ParameterFilter : IRequestSpecification + /// The parameter. + /// The flags specifying the matching criteria. + /// Thrown when is null. + public ParameterFilter(ParameterInfo parameterInfo, Matching flags) { - private readonly IRequestSpecification matcherSpecification; - - /// - /// Creates an instance of type . - /// - /// The parameter. - /// The flags specifying the matching criteria. - /// Thrown when is null. - public ParameterFilter(ParameterInfo parameterInfo, Matching flags) - { - this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - this.Flags = flags; - this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) - .SetFlags(this.Flags).Build(); - } + this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + this.Flags = flags; + this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) + .SetFlags(this.Flags).Build(); + } - /// - /// Gets the source parameter. - /// - public ParameterInfo ParameterInfo { get; } + /// + /// Gets the source parameter. + /// + public ParameterInfo ParameterInfo { get; } - /// - /// Gets the matching flags. - /// - public Matching Flags { get; } + /// + /// Gets the matching flags. + /// + public Matching Flags { get; } - /// - public bool IsSatisfiedBy(object request) - { - return this.matcherSpecification.IsSatisfiedBy(request); - } + /// + public bool IsSatisfiedBy(object request) + { + return this.matcherSpecification.IsSatisfiedBy(request); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index 446cb82..9dc4d65 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -1,199 +1,198 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// A builder type that creates a instance, +/// for a instance, based on the builder's matching configuration. +/// +public class ParameterMatcherBuilder { + private readonly ParameterInfo _parameterInfo; + /// - /// A builder type that creates a instance, - /// for a instance, based on the builder's matching configuration. + /// Creates an instance of type . /// - public class ParameterMatcherBuilder + /// The parameter info. + /// + /// Thrown when is . + /// + public ParameterMatcherBuilder(ParameterInfo parameterInfo) { - private readonly ParameterInfo _parameterInfo; - - /// - /// Creates an instance of type . - /// - /// The parameter info. - /// - /// Thrown when is . - /// - public ParameterMatcherBuilder(ParameterInfo parameterInfo) - { - this._parameterInfo = parameterInfo - ?? throw new ArgumentNullException(nameof(parameterInfo)); - } - - /// - /// Gets or sets a value indicating whether the exact parameter request should be matched. - /// Default is . - /// - public bool MatchExactRequest { get; set; } = true; - - /// - /// Gets or sets a value indicating whether the exact parameter type should be matched. - /// - public bool MatchExactType { get; set; } - - /// - /// Gets or sets a value indicating whether the direct base type should be matched. - /// - public bool MatchDirectBaseType { get; set; } - - /// - /// Gets or sets a value indicating whether the interfaces implemented - /// by the parameter type should be matched. - /// - public bool MatchImplementedInterfaces { get; set; } - - /// - /// Gets or sets a value indicating whether the parameter type and name should be matched. - /// The name comparison is case-insensitive. - /// - public bool MatchParameter { get; set; } - - /// - /// Gets or sets a value indicating whether the property type and name should be matched. - /// The name comparison is case-insensitive. - /// - public bool MatchProperty { get; set; } - - /// - /// Gets or sets a value indicating whether the field type and name should be matched. - /// The name comparison is case-insensitive. - /// - public bool MatchField { get; set; } - - /// - /// Sets the matching flags. - /// - /// The matching flags. - /// The current instance. - public ParameterMatcherBuilder SetFlags(Matching flags) - { - MatchExactType = flags.HasFlag(Matching.ExactType); - MatchDirectBaseType = flags.HasFlag(Matching.DirectBaseType); - MatchImplementedInterfaces = flags.HasFlag(Matching.ImplementedInterfaces); - MatchParameter = flags.HasFlag(Matching.ParameterName); - MatchProperty = flags.HasFlag(Matching.PropertyName); - MatchField = flags.HasFlag(Matching.FieldName); - return this; - } + this._parameterInfo = parameterInfo + ?? throw new ArgumentNullException(nameof(parameterInfo)); + } - /// - /// Builds the instance. - /// - /// - /// A new instance of , matching the configuration. - /// - public IRequestSpecification Build() - { - var specifications = new List(7); - if (MatchExactRequest) - { - specifications.Add(AsExactRequest()); - } + /// + /// Gets or sets a value indicating whether the exact parameter request should be matched. + /// Default is . + /// + public bool MatchExactRequest { get; set; } = true; - if (MatchExactType) - { - specifications.Add(AsExactType()); - } + /// + /// Gets or sets a value indicating whether the exact parameter type should be matched. + /// + public bool MatchExactType { get; set; } - if (MatchDirectBaseType) - { - specifications.Add(AsDirectBaseType()); - } + /// + /// Gets or sets a value indicating whether the direct base type should be matched. + /// + public bool MatchDirectBaseType { get; set; } - if (MatchImplementedInterfaces) - { - specifications.Add(AsImplementedInterfaces()); - } + /// + /// Gets or sets a value indicating whether the interfaces implemented + /// by the parameter type should be matched. + /// + public bool MatchImplementedInterfaces { get; set; } - if (MatchProperty) - { - specifications.Add(AsProperty()); - } + /// + /// Gets or sets a value indicating whether the parameter type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchParameter { get; set; } - if (MatchParameter) - { - specifications.Add(AsParameter()); - } + /// + /// Gets or sets a value indicating whether the property type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchProperty { get; set; } - if (MatchField) - { - specifications.Add(AsField()); - } + /// + /// Gets or sets a value indicating whether the field type and name should be matched. + /// The name comparison is case-insensitive. + /// + public bool MatchField { get; set; } - return specifications.Count == 1 - ? specifications[0] - : new OrRequestSpecification(specifications); - } + /// + /// Sets the matching flags. + /// + /// The matching flags. + /// The current instance. + public ParameterMatcherBuilder SetFlags(Matching flags) + { + MatchExactType = flags.HasFlag(Matching.ExactType); + MatchDirectBaseType = flags.HasFlag(Matching.DirectBaseType); + MatchImplementedInterfaces = flags.HasFlag(Matching.ImplementedInterfaces); + MatchParameter = flags.HasFlag(Matching.ParameterName); + MatchProperty = flags.HasFlag(Matching.PropertyName); + MatchField = flags.HasFlag(Matching.FieldName); + return this; + } - private IRequestSpecification AsExactRequest() + /// + /// Builds the instance. + /// + /// + /// A new instance of , matching the configuration. + /// + public IRequestSpecification Build() + { + var specifications = new List(7); + if (MatchExactRequest) { - return new EqualRequestSpecification(_parameterInfo); + specifications.Add(AsExactRequest()); } - private IRequestSpecification AsExactType() + if (MatchExactType) { - return new OrRequestSpecification( - new ExactTypeSpecification(_parameterInfo.ParameterType), - new SeedRequestSpecification(_parameterInfo.ParameterType)); + specifications.Add(AsExactType()); } - private IRequestSpecification AsDirectBaseType() + if (MatchDirectBaseType) { - return new AndRequestSpecification( - new InverseRequestSpecification( - new ExactTypeSpecification(_parameterInfo.ParameterType)), - new DirectBaseTypeSpecification(_parameterInfo.ParameterType)); + specifications.Add(AsDirectBaseType()); } - private IRequestSpecification AsImplementedInterfaces() + if (MatchImplementedInterfaces) { - return new AndRequestSpecification( - new InverseRequestSpecification( - new ExactTypeSpecification(_parameterInfo.ParameterType)), - new ImplementedInterfaceSpecification(_parameterInfo.ParameterType)); + specifications.Add(AsImplementedInterfaces()); } - private IRequestSpecification AsParameter() + if (MatchProperty) { - return new ParameterSpecification( - new ParameterTypeAndNameCriterion( - new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + specifications.Add(AsProperty()); } - private IRequestSpecification AsProperty() + if (MatchParameter) { - return new PropertySpecification( - new PropertyTypeAndNameCriterion( - new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + specifications.Add(AsParameter()); } - private IRequestSpecification AsField() + if (MatchField) { - return new FieldSpecification( - new FieldTypeAndNameCriterion( - new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), - new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + specifications.Add(AsField()); } - private class DerivesFromTypeComparer : IEqualityComparer + return specifications.Count == 1 + ? specifications[0] + : new OrRequestSpecification(specifications); + } + + private IRequestSpecification AsExactRequest() + { + return new EqualRequestSpecification(_parameterInfo); + } + + private IRequestSpecification AsExactType() + { + return new OrRequestSpecification( + new ExactTypeSpecification(_parameterInfo.ParameterType), + new SeedRequestSpecification(_parameterInfo.ParameterType)); + } + + private IRequestSpecification AsDirectBaseType() + { + return new AndRequestSpecification( + new InverseRequestSpecification( + new ExactTypeSpecification(_parameterInfo.ParameterType)), + new DirectBaseTypeSpecification(_parameterInfo.ParameterType)); + } + + private IRequestSpecification AsImplementedInterfaces() + { + return new AndRequestSpecification( + new InverseRequestSpecification( + new ExactTypeSpecification(_parameterInfo.ParameterType)), + new ImplementedInterfaceSpecification(_parameterInfo.ParameterType)); + } + + private IRequestSpecification AsParameter() + { + return new ParameterSpecification( + new ParameterTypeAndNameCriterion( + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private IRequestSpecification AsProperty() + { + return new PropertySpecification( + new PropertyTypeAndNameCriterion( + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private IRequestSpecification AsField() + { + return new FieldSpecification( + new FieldTypeAndNameCriterion( + new Criterion(_parameterInfo.ParameterType, new DerivesFromTypeComparer()), + new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); + } + + private class DerivesFromTypeComparer : IEqualityComparer + { + public bool Equals(Type x, Type y) { - public bool Equals(Type x, Type y) + return y switch { - return y switch - { - null when x is null => true, - null => false, - _ => y.GetTypeInfo().IsAssignableFrom(x) - }; - } - - public int GetHashCode(Type obj) => 0; + null when x is null => true, + null => false, + _ => y.GetTypeInfo().IsAssignableFrom(x) + }; } + + public int GetHashCode(Type obj) => 0; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs index ba5b7f0..4de76b1 100644 --- a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs @@ -1,41 +1,40 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +/// +/// Encapsulates access to a property that provides test data. +/// +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", + Justification = "Type is not a collection.")] +public class PropertyDataSource : DataSource { /// - /// Encapsulates access to a property that provides test data. + /// Creates an instance of type . /// - [SuppressMessage("Design", "CA1010:Generic interface should also be implemented", - Justification = "Type is not a collection.")] - public class PropertyDataSource : DataSource + /// + /// + public PropertyDataSource(PropertyInfo propertyInfo) { - /// - /// Creates an instance of type . - /// - /// - /// - public PropertyDataSource(PropertyInfo propertyInfo) - { - this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); - } - - /// - /// Gets the source property. - /// - public PropertyInfo PropertyInfo { get; } + this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); + } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - var value = this.PropertyInfo.GetValue(null); + /// + /// Gets the source property. + /// + public PropertyInfo PropertyInfo { get; } - if (value is not IEnumerable enumerable) - { - throw new InvalidCastException("Member does not return an enumerable value."); - } + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var value = this.PropertyInfo.GetValue(null); - return enumerable; + if (value is not IEnumerable enumerable) + { + throw new InvalidCastException("Member does not return an enumerable value."); } + + return enumerable; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs b/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs index fb6436a..213b173 100644 --- a/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs +++ b/src/AutoFixture.TUnit/Internal/ReflectionExtensions.cs @@ -1,23 +1,22 @@ using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal static class ReflectionExtensions { - internal static class ReflectionExtensions + public static Type GetReturnType(this MemberInfo member) { - public static Type GetReturnType(this MemberInfo member) + if (member is null) { - if (member is null) - { - throw new ArgumentNullException(nameof(member)); - } - - return member switch - { - MethodInfo methodInfo => methodInfo.ReturnType, - PropertyInfo propertyInfo => propertyInfo.PropertyType, - FieldInfo fieldInfo => fieldInfo.FieldType, - _ => throw new ArgumentException("Member is not a method, property, or field.", nameof(member)) - }; + throw new ArgumentNullException(nameof(member)); } + + return member switch + { + MethodInfo methodInfo => methodInfo.ReturnType, + PropertyInfo propertyInfo => propertyInfo.PropertyType, + FieldInfo fieldInfo => fieldInfo.FieldType, + _ => throw new ArgumentException("Member is not a method, property, or field.", nameof(member)) + }; } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 64ca915..9cd283a 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -1,50 +1,49 @@ using System.Reflection; -namespace AutoFixture.TUnit.Internal +namespace AutoFixture.TUnit.Internal; + +internal class TestParameter(ParameterInfo parameterInfo) { - internal class TestParameter(ParameterInfo parameterInfo) - { - private readonly Lazy lazyCustomization = new( - () => GetCustomization(parameterInfo)); + private readonly Lazy lazyCustomization = new( + () => GetCustomization(parameterInfo)); + + private readonly Lazy lazyFrozenAttribute = new( + () => parameterInfo.GetCustomAttributes() + .OfType().FirstOrDefault()); - private readonly Lazy lazyFrozenAttribute = new( - () => parameterInfo.GetCustomAttributes() - .OfType().FirstOrDefault()); + public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + public ICustomization GetCustomization() => this.lazyCustomization.Value; - public ICustomization GetCustomization() => this.lazyCustomization.Value; + public ICustomization GetCustomization(object value) + { + var frozenAttribute = this.lazyFrozenAttribute.Value; - public ICustomization GetCustomization(object value) + if (frozenAttribute is null) { - var frozenAttribute = this.lazyFrozenAttribute.Value; + return NullCustomization.Instance; + } - if (frozenAttribute is null) - { - return NullCustomization.Instance; - } + return new FrozenValueCustomization( + new ParameterFilter(this.ParameterInfo, frozenAttribute.By), + value); + } - return new FrozenValueCustomization( - new ParameterFilter(this.ParameterInfo, frozenAttribute.By), - value); - } + private static ICustomization GetCustomization(ParameterInfo parameter) + { + var customizations = parameter.GetCustomAttributes() + .OfType() + .OrderBy(x => x, new CustomizeAttributeComparer()) + .Select(x => x.GetCustomization(parameter)) + .ToArray(); - private static ICustomization GetCustomization(ParameterInfo parameter) + return customizations switch { - var customizations = parameter.GetCustomAttributes() - .OfType() - .OrderBy(x => x, new CustomizeAttributeComparer()) - .Select(x => x.GetCustomization(parameter)) - .ToArray(); - - return customizations switch - { - { Length: 0 } => NullCustomization.Instance, - { Length: 1 } => customizations[0], - _ => new CompositeCustomization(customizations), - }; - } - - public static TestParameter From(ParameterInfo parameterInfo) => new(parameterInfo); + { Length: 0 } => NullCustomization.Instance, + { Length: 1 } => customizations[0], + _ => new CompositeCustomization(customizations), + }; } -} + + public static TestParameter From(ParameterInfo parameterInfo) => new(parameterInfo); +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Matching.cs b/src/AutoFixture.TUnit/Matching.cs index c31bc9d..e284d4a 100644 --- a/src/AutoFixture.TUnit/Matching.cs +++ b/src/AutoFixture.TUnit/Matching.cs @@ -1,62 +1,61 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// The criteria used to determine which requests will be satisfied +/// by the frozen specimen created for a parameter +/// decorated with the attribute. +/// +[SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames", + Justification = "This enumeration is designed to be used together with an attribute and is named to improve readability.")] +[Flags] +public enum Matching { /// - /// The criteria used to determine which requests will be satisfied - /// by the frozen specimen created for a parameter - /// decorated with the attribute. + /// Matches requests for the exact same + /// as the type of the parameter. + /// + ExactType = 1, + + /// + /// Matches requests for a that is + /// a direct base of the type of the parameter. + /// + DirectBaseType = 2, + + /// + /// Matches requests for an interface that is + /// implemented by the type of the parameter. + /// + ImplementedInterfaces = 4, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + ParameterName = 8, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + PropertyName = 16, + + /// + /// Matches requests for a whose + /// is compatible with the type of the parameter + /// and has a specific name. + /// + FieldName = 32, + + /// + /// Matches requests for a parameter, property or field whose + /// is compatible with the type of the parameter + /// and has a specific name. /// - [SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames", - Justification = "This enumeration is designed to be used together with an attribute and is named to improve readability.")] - [Flags] - public enum Matching - { - /// - /// Matches requests for the exact same - /// as the type of the parameter. - /// - ExactType = 1, - - /// - /// Matches requests for a that is - /// a direct base of the type of the parameter. - /// - DirectBaseType = 2, - - /// - /// Matches requests for an interface that is - /// implemented by the type of the parameter. - /// - ImplementedInterfaces = 4, - - /// - /// Matches requests for a whose - /// is compatible with the type of the parameter - /// and has a specific name. - /// - ParameterName = 8, - - /// - /// Matches requests for a whose - /// is compatible with the type of the parameter - /// and has a specific name. - /// - PropertyName = 16, - - /// - /// Matches requests for a whose - /// is compatible with the type of the parameter - /// and has a specific name. - /// - FieldName = 32, - - /// - /// Matches requests for a parameter, property or field whose - /// is compatible with the type of the parameter - /// and has a specific name. - /// - MemberName = ParameterName | PropertyName | FieldName - } -} + MemberName = ParameterName | PropertyName | FieldName +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs index c467732..e29c318 100644 --- a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -2,107 +2,106 @@ using AutoFixture.TUnit.Extensions; using AutoFixture.TUnit.Internal; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// Provides a data source for a data theory, with the data coming from one of the following sources +/// and combined with auto-generated data specimens generated by AutoFixture: +/// 1. A static property +/// 2. A static field +/// 3. A static method (with parameters) +/// The member must return something compatible with IEnumerable<object[]> with the test data. +/// +[CLSCompliant(false)] +[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", + Justification = "This attribute is the root of a potential attribute hierarchy.")] +public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute { /// - /// Provides a data source for a data theory, with the data coming from one of the following sources - /// and combined with auto-generated data specimens generated by AutoFixture: - /// 1. A static property - /// 2. A static field - /// 3. A static method (with parameters) - /// The member must return something compatible with IEnumerable<object[]> with the test data. + /// Initializes a new instance of the class. /// - [CLSCompliant(false)] - [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", - Justification = "This attribute is the root of a potential attribute hierarchy.")] - public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + public MemberAutoDataAttribute(string memberName, params object[] parameters) + : this(() => new Fixture(), memberType: null, memberName, parameters) { - /// - /// Initializes a new instance of the class. - /// - /// The name of the public static member on the test class that will provide the test data. - /// The parameters for the member (only supported for methods; ignored for everything else). - public MemberAutoDataAttribute(string memberName, params object[] parameters) - : this(() => new Fixture(), memberType: null, memberName, parameters) - { - } + } - /// - /// Initializes a new instance of the class. - /// - /// The type declaring the source member. - /// The name of the public static member on the test class that will provide the test data. - /// The parameters for the member (only supported for methods; ignored for everything else). - public MemberAutoDataAttribute(Type? memberType, string memberName, params object[] parameters) - : this(() => new Fixture(), memberType, memberName, parameters) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The type declaring the source member. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + public MemberAutoDataAttribute(Type? memberType, string memberName, params object[] parameters) + : this(() => new Fixture(), memberType, memberName, parameters) + { + } - /// - /// Initializes a new instance of the class. - /// - /// The fixture factory delegate. - /// The name of the public static member on the test class that will provide the test data. - /// The parameters for the member (only supported for methods; ignored for everything else). - protected MemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) - : this(fixtureFactory, memberType: null, memberName, parameters) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory delegate. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + protected MemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) + : this(fixtureFactory, memberType: null, memberName, parameters) + { + } - /// - /// Initializes a new instance of the class. - /// - /// The fixture factory delegate. - /// The type declaring the source member. - /// The name of the public static member on the test class that will provide the test data. - /// The parameters for the member (only supported for methods; ignored for everything else). - /// Thrown when arguments are null. - protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) - { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); - this.Parameters = parameters ?? new object[] { null! }; - this.MemberType = memberType; - } + /// + /// Initializes a new instance of the class. + /// + /// The fixture factory delegate. + /// The type declaring the source member. + /// The name of the public static member on the test class that will provide the test data. + /// The parameters for the member (only supported for methods; ignored for everything else). + /// Thrown when arguments are null. + protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) + { + this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); + this.Parameters = parameters ?? new object[] { null! }; + this.MemberType = memberType; + } - /// - /// Gets the fixture factory that provides the missing data from . - /// - public Func FixtureFactory { get; } + /// + /// Gets the fixture factory that provides the missing data from . + /// + public Func FixtureFactory { get; } - /// - /// Gets the type of the class that provides the data. - /// - public Type? MemberType { get; } + /// + /// Gets the type of the class that provides the data. + /// + public Type? MemberType { get; } - /// - /// Gets the member name. - /// - public string MemberName { get; } + /// + /// Gets the member name. + /// + public string MemberName { get; } - /// - /// Gets the parameters passed to the member. Only supported for static methods. - /// - public object[] Parameters { get; } + /// + /// Gets the parameters passed to the member. Only supported for static methods. + /// + public object[] Parameters { get; } - /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) - { - var testMethod = dataGeneratorMetadata.GetMethod(); + /// + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + { + var testMethod = dataGeneratorMetadata.GetMethod(); - if (testMethod is null) - { - throw new ArgumentNullException(nameof(testMethod)); - } + if (testMethod is null) + { + throw new ArgumentNullException(nameof(testMethod)); + } - var sourceType = this.MemberType ?? testMethod.DeclaringType - ?? throw new InvalidOperationException("Source type cannot be null."); + var sourceType = this.MemberType ?? testMethod.DeclaringType + ?? throw new InvalidOperationException("Source type cannot be null."); - var source = new AutoDataSource( - createFixture: this.FixtureFactory, - source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); + var source = new AutoDataSource( + createFixture: this.FixtureFactory, + source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); - return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); - } + return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/ModestAttribute.cs b/src/AutoFixture.TUnit/ModestAttribute.cs index c7206ce..9606ece 100644 --- a/src/AutoFixture.TUnit/ModestAttribute.cs +++ b/src/AutoFixture.TUnit/ModestAttribute.cs @@ -1,33 +1,32 @@ using System.Reflection; using AutoFixture.Kernel; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should be created using the most modest +/// constructor that can be satisfied by an . +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class ModestAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should be created using the most modest - /// constructor that can be satisfied by an . + /// Gets a customization that associates a with the + /// of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class ModestAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that associates a with the + /// of the parameter. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that associates a with the - /// of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that associates a with the - /// of the parameter. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter is null) { - if (parameter is null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - return new ConstructorCustomization(parameter.ParameterType, new ModestConstructorQuery()); + throw new ArgumentNullException(nameof(parameter)); } + + return new ConstructorCustomization(parameter.ParameterType, new ModestConstructorQuery()); } -} +} \ No newline at end of file diff --git a/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs b/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs index 1906c51..0faa39e 100644 --- a/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs +++ b/src/AutoFixture.TUnit/NoAutoPropertiesAttribute.cs @@ -1,34 +1,33 @@ using System.Reflection; -namespace AutoFixture.TUnit +namespace AutoFixture.TUnit; + +/// +/// An attribute that can be applied to parameters in an -driven +/// Theory to indicate that the parameter value should not have properties auto populated +/// when the creates an instance of that type. +/// +[AttributeUsage(AttributeTargets.Parameter)] +public sealed class NoAutoPropertiesAttribute : CustomizeAttribute { /// - /// An attribute that can be applied to parameters in an -driven - /// Theory to indicate that the parameter value should not have properties auto populated - /// when the creates an instance of that type. + /// Gets a customization that stops auto population of properties for the type of the parameter. /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class NoAutoPropertiesAttribute : CustomizeAttribute + /// The parameter for which the customization is requested. + /// + /// A customization that stops auto population of the of the parameter. + /// + /// + /// is null. + /// + public override ICustomization GetCustomization(ParameterInfo parameter) { - /// - /// Gets a customization that stops auto population of properties for the type of the parameter. - /// - /// The parameter for which the customization is requested. - /// - /// A customization that stops auto population of the of the parameter. - /// - /// - /// is null. - /// - public override ICustomization GetCustomization(ParameterInfo parameter) + if (parameter is null) { - if (parameter is null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - var targetType = parameter.ParameterType; - return new NoAutoPropertiesCustomization(targetType); + throw new ArgumentNullException(nameof(parameter)); } + + var targetType = parameter.ParameterType; + return new NoAutoPropertiesCustomization(targetType); } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs index cc9c378..1e038eb 100644 --- a/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs +++ b/tests/TestTypeFoundation/AbstractClassWithPublicConstructor.cs @@ -1,6 +1,5 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public abstract class AbstractClassWithPublicConstructor { - public abstract class AbstractClassWithPublicConstructor - { - } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractGenericType.cs b/tests/TestTypeFoundation/AbstractGenericType.cs index cc6afe5..7a9b13b 100644 --- a/tests/TestTypeFoundation/AbstractGenericType.cs +++ b/tests/TestTypeFoundation/AbstractGenericType.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public abstract class AbstractGenericType(T t) { - public abstract class AbstractGenericType(T t) - { - public T Value { get; } = t; - } + public T Value { get; } = t; } \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractType.cs b/tests/TestTypeFoundation/AbstractType.cs index f83cc43..ab273cd 100644 --- a/tests/TestTypeFoundation/AbstractType.cs +++ b/tests/TestTypeFoundation/AbstractType.cs @@ -1,15 +1,14 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public abstract class AbstractType { - public abstract class AbstractType - { - public object Property1 { get; set; } + public object Property1 { get; set; } - public object Property2 { get; set; } + public object Property2 { get; set; } - public object Property3 { get; set; } + public object Property3 { get; set; } - public virtual object Property4 { get; set; } + public virtual object Property4 { get; set; } - public object Field1; - } -} + public object Field1; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs index 1878d80..d083f72 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithConstructorWithMultipleParameters.cs @@ -1,11 +1,10 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public abstract class AbstractTypeWithConstructorWithMultipleParameters( + T1 parameter1, + T2 parameter2) { - public abstract class AbstractTypeWithConstructorWithMultipleParameters( - T1 parameter1, - T2 parameter2) - { - public T1 Property1 { get; } = parameter1; + public T1 Property1 { get; } = parameter1; - public T2 Property2 { get; } = parameter2; - } -} + public T2 Property2 { get; } = parameter2; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs index 45fc4d1..6f403a2 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs @@ -1,17 +1,16 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public abstract class AbstractTypeWithNonDefaultConstructor { - public abstract class AbstractTypeWithNonDefaultConstructor + protected AbstractTypeWithNonDefaultConstructor(T value) { - protected AbstractTypeWithNonDefaultConstructor(T value) + if (value == null) { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - this.Property = value; + throw new ArgumentNullException(nameof(value)); } - public T Property { get; } + this.Property = value; } -} + + public T Property { get; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ActivityScope.cs b/tests/TestTypeFoundation/ActivityScope.cs index c1896fe..4f34cc0 100644 --- a/tests/TestTypeFoundation/ActivityScope.cs +++ b/tests/TestTypeFoundation/ActivityScope.cs @@ -1,46 +1,45 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +[Flags] +public enum ActivityScope : long { - [Flags] - public enum ActivityScope : long - { - /// - /// Undefined scope. - /// - Undefined = 0, - - /// - /// The OnDuty activity has its own special scope. - /// - OnDuty = 0x01, - - /// - /// The OffDuty activity has its own special scope. - /// - OffDuty = 0x02, - - /// - /// A standalone has no parent or children. - /// - Standalone = 0x04, - - /// - /// A parent activity can have one or more child activities.. - /// - Parent = 0x08, - - /// - /// A child activity has a parent activity. - /// - Child = 0x10, - - /// - /// The set of all scopes that are allowed when there is no open Parent activity. - /// - AllInitiatingScopes = Parent | Standalone, - - /// - /// The set all valid scopes. - /// - All = OnDuty | OffDuty | Standalone | Parent | Child, - } + /// + /// Undefined scope. + /// + Undefined = 0, + + /// + /// The OnDuty activity has its own special scope. + /// + OnDuty = 0x01, + + /// + /// The OffDuty activity has its own special scope. + /// + OffDuty = 0x02, + + /// + /// A standalone has no parent or children. + /// + Standalone = 0x04, + + /// + /// A parent activity can have one or more child activities.. + /// + Parent = 0x08, + + /// + /// A child activity has a parent activity. + /// + Child = 0x10, + + /// + /// The set of all scopes that are allowed when there is no open Parent activity. + /// + AllInitiatingScopes = Parent | Standalone, + + /// + /// The set all valid scopes. + /// + All = OnDuty | OffDuty | Standalone | Parent | Child, } \ No newline at end of file diff --git a/tests/TestTypeFoundation/CollectionHolder.cs b/tests/TestTypeFoundation/CollectionHolder.cs index 3e11220..b0c5432 100644 --- a/tests/TestTypeFoundation/CollectionHolder.cs +++ b/tests/TestTypeFoundation/CollectionHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class CollectionHolder { - public class CollectionHolder - { - public ICollection Collection { get; private set; } = new List(); - } -} + public ICollection Collection { get; private set; } = new List(); +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/CompositeType.cs b/tests/TestTypeFoundation/CompositeType.cs index 53ea252..55d6cb5 100644 --- a/tests/TestTypeFoundation/CompositeType.cs +++ b/tests/TestTypeFoundation/CompositeType.cs @@ -1,22 +1,21 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class CompositeType : AbstractType { - public class CompositeType : AbstractType + public CompositeType(IEnumerable types) + : this(types.ToArray()) { - public CompositeType(IEnumerable types) - : this(types.ToArray()) - { - } + } - public CompositeType(params AbstractType[] types) + public CompositeType(params AbstractType[] types) + { + if (types == null) { - if (types == null) - { - throw new ArgumentNullException(nameof(types)); - } - - this.Types = types; + throw new ArgumentNullException(nameof(types)); } - public IEnumerable Types { get; } + this.Types = types; } + + public IEnumerable Types { get; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/ConcreteType.cs b/tests/TestTypeFoundation/ConcreteType.cs index acae971..5748a47 100644 --- a/tests/TestTypeFoundation/ConcreteType.cs +++ b/tests/TestTypeFoundation/ConcreteType.cs @@ -1,39 +1,38 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ConcreteType : AbstractType { - public class ConcreteType : AbstractType + public ConcreteType() { - public ConcreteType() - { - } + } - public ConcreteType(object obj) - { - this.Property1 = obj; - } + public ConcreteType(object obj) + { + this.Property1 = obj; + } - public ConcreteType(object obj1, object obj2) - { - this.Property1 = obj1; - this.Property2 = obj2; - } + public ConcreteType(object obj1, object obj2) + { + this.Property1 = obj1; + this.Property2 = obj2; + } - public ConcreteType(object obj1, object obj2, object obj3) - { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; - } + public ConcreteType(object obj1, object obj2, object obj3) + { + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; + } - public ConcreteType(object obj1, object obj2, object obj3, object obj4) - { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; - this.Property4 = obj4; - } + public ConcreteType(object obj1, object obj2, object obj3, object obj4) + { + this.Property1 = obj1; + this.Property2 = obj2; + this.Property3 = obj3; + this.Property4 = obj4; + } - public override object Property4 { get; set; } + public override object Property4 { get; set; } - public object Property5 { get; set; } - } -} + public object Property5 { get; set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs b/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs index 7ca5f15..c9ce80c 100644 --- a/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs +++ b/tests/TestTypeFoundation/ConcreteTypeWithPrivateParameterlessConstructor.cs @@ -1,13 +1,12 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ConcreteTypeWithPrivateParameterlessConstructor { - public class ConcreteTypeWithPrivateParameterlessConstructor + private ConcreteTypeWithPrivateParameterlessConstructor() { - private ConcreteTypeWithPrivateParameterlessConstructor() - { - } + } - public ConcreteTypeWithPrivateParameterlessConstructor(object obj) - { - } + public ConcreteTypeWithPrivateParameterlessConstructor(object obj) + { } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/DoubleFieldHolder.cs b/tests/TestTypeFoundation/DoubleFieldHolder.cs index 421f89d..ed1cb9c 100644 --- a/tests/TestTypeFoundation/DoubleFieldHolder.cs +++ b/tests/TestTypeFoundation/DoubleFieldHolder.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class DoubleFieldHolder { - public class DoubleFieldHolder - { - public T1 Field1; + public T1 Field1; - public T2 Field2; - } -} + public T2 Field2; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/DoubleParameterType.cs b/tests/TestTypeFoundation/DoubleParameterType.cs index 4175d64..2b2cca3 100644 --- a/tests/TestTypeFoundation/DoubleParameterType.cs +++ b/tests/TestTypeFoundation/DoubleParameterType.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class DoubleParameterType(T1 parameter1, T2 parameter2) { - public class DoubleParameterType(T1 parameter1, T2 parameter2) - { - public T1 Parameter1 { get; private set; } = parameter1; + public T1 Parameter1 { get; private set; } = parameter1; - public T2 Parameter2 { get; private set; } = parameter2; - } -} + public T2 Parameter2 { get; private set; } = parameter2; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/DoublePropertyHolder.cs b/tests/TestTypeFoundation/DoublePropertyHolder.cs index 5b2ca12..2087e7f 100644 --- a/tests/TestTypeFoundation/DoublePropertyHolder.cs +++ b/tests/TestTypeFoundation/DoublePropertyHolder.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class DoublePropertyHolder { - public class DoublePropertyHolder - { - public T1 Property1 { get; set; } + public T1 Property1 { get; set; } - public T2 Property2 { get; set; } - } -} + public T2 Property2 { get; set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/EmptyEnum.cs b/tests/TestTypeFoundation/EmptyEnum.cs index 680c38e..224363e 100644 --- a/tests/TestTypeFoundation/EmptyEnum.cs +++ b/tests/TestTypeFoundation/EmptyEnum.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public enum EmptyEnum { - public enum EmptyEnum - { - // this must not contain any values - } -} + // this must not contain any values +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/EnumType.cs b/tests/TestTypeFoundation/EnumType.cs index d5b041f..8c64374 100644 --- a/tests/TestTypeFoundation/EnumType.cs +++ b/tests/TestTypeFoundation/EnumType.cs @@ -1,58 +1,57 @@ -namespace TestTypeFoundation -{ - public enum EnumType - { - First = 1, - Second = 2, - Third = 3 - } - - public enum ByteEnumType : byte - { - First = 99, - Second, - Third - } - - public enum SByteEnumType : sbyte - { - First = -98, - Second, - Third - } - - public enum ShortEnumType : short - { - First = 100, - Second, - Third - } - - public enum UShortEnumType : ushort - { - First = 1, - Second, - Third - } - - public enum UIntEnumType : uint - { - First, - Second, - Third - } - - public enum LongEnumType : long - { - First = (long)int.MaxValue + 1, - Second, - Third - } - - public enum ULongEnumType : ulong - { - First = 1, - Second, - Third - } +namespace TestTypeFoundation; + +public enum EnumType +{ + First = 1, + Second = 2, + Third = 3 +} + +public enum ByteEnumType : byte +{ + First = 99, + Second, + Third +} + +public enum SByteEnumType : sbyte +{ + First = -98, + Second, + Third +} + +public enum ShortEnumType : short +{ + First = 100, + Second, + Third +} + +public enum UShortEnumType : ushort +{ + First = 1, + Second, + Third +} + +public enum UIntEnumType : uint +{ + First, + Second, + Third +} + +public enum LongEnumType : long +{ + First = (long)int.MaxValue + 1, + Second, + Third +} + +public enum ULongEnumType : ulong +{ + First = 1, + Second, + Third } \ No newline at end of file diff --git a/tests/TestTypeFoundation/EqualityResponder.cs b/tests/TestTypeFoundation/EqualityResponder.cs index 102cbb0..d601638 100644 --- a/tests/TestTypeFoundation/EqualityResponder.cs +++ b/tests/TestTypeFoundation/EqualityResponder.cs @@ -1,15 +1,14 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class EqualityResponder(bool equals) { - public class EqualityResponder(bool equals) + public override bool Equals(object obj) { - public override bool Equals(object obj) - { - return equals; - } + return equals; + } - public override int GetHashCode() - { - return equals.GetHashCode(); - } + public override int GetHashCode() + { + return equals.GetHashCode(); } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/FieldHolder.cs b/tests/TestTypeFoundation/FieldHolder.cs index 540369a..c3135eb 100644 --- a/tests/TestTypeFoundation/FieldHolder.cs +++ b/tests/TestTypeFoundation/FieldHolder.cs @@ -1,15 +1,14 @@ using System.Reflection; -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class FieldHolder { - public class FieldHolder - { - public T Field; + public T Field; - public static FieldInfo GetField() - { - return typeof(FieldHolder) - .GetRuntimeField(nameof(Field)); - } + public static FieldInfo GetField() + { + return typeof(FieldHolder) + .GetRuntimeField(nameof(Field)); } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GenericType.cs b/tests/TestTypeFoundation/GenericType.cs index 208b49a..662ddc5 100644 --- a/tests/TestTypeFoundation/GenericType.cs +++ b/tests/TestTypeFoundation/GenericType.cs @@ -1,18 +1,17 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GenericType + where T : class { - public class GenericType - where T : class + public GenericType(T t) { - public GenericType(T t) + if (t == null) { - if (t == null) - { - throw new ArgumentNullException(nameof(t)); - } - - this.Value = t; + throw new ArgumentNullException(nameof(t)); } - private T Value { get; } + this.Value = t; } + + private T Value { get; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedConstructorHost.cs b/tests/TestTypeFoundation/GuardedConstructorHost.cs index a8e1162..2f53c29 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHost.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHost.cs @@ -1,18 +1,17 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GuardedConstructorHost + where T : class { - public class GuardedConstructorHost - where T : class + public GuardedConstructorHost(T item) { - public GuardedConstructorHost(T item) + if (item == null) { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - this.Item = item; + throw new ArgumentNullException(nameof(item)); } - public T Item { get; } + this.Item = item; } -} + + public T Item { get; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs index 5b8af28..df72d37 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs @@ -1,20 +1,19 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GuardedConstructorHostHoldingStaticReadOnlyField + where TItem : class { - public class GuardedConstructorHostHoldingStaticReadOnlyField - where TItem : class - { - public static readonly TStaticField Field; + public static readonly TStaticField Field; - public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) + public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) + { + if (item is null) { - if (item is null) - { - throw new ArgumentNullException(nameof(item)); - } - - this.Item = item; + throw new ArgumentNullException(nameof(item)); } - public TItem Item { get; private set; } + this.Item = item; } -} + + public TItem Item { get; private set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs index ace6ba2..0ae442e 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs @@ -1,25 +1,24 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GuardedConstructorHostHoldingStaticReadOnlyProperty + where TItem : class { - public class GuardedConstructorHostHoldingStaticReadOnlyProperty - where TItem : class + static GuardedConstructorHostHoldingStaticReadOnlyProperty() { - static GuardedConstructorHostHoldingStaticReadOnlyProperty() - { - Property = default(TStaticProperty); - } + Property = default(TStaticProperty); + } - public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) + public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) + { + if (item == null) { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - this.Item = item; + throw new ArgumentNullException(nameof(item)); } - public static TStaticProperty Property { get; private set; } - - public TItem Item { get; private set; } + this.Item = item; } -} + + public static TStaticProperty Property { get; private set; } + + public TItem Item { get; private set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedMethodHost.cs b/tests/TestTypeFoundation/GuardedMethodHost.cs index 8f6ce8c..4c9a1a3 100644 --- a/tests/TestTypeFoundation/GuardedMethodHost.cs +++ b/tests/TestTypeFoundation/GuardedMethodHost.cs @@ -1,81 +1,80 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GuardedMethodHost { - public class GuardedMethodHost + public void ConsumeString(string s) { - public void ConsumeString(string s) + if (s == null) { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } - if (s.Length == 0) - { - throw new ArgumentException("String cannot be empty.", nameof(s)); - } + throw new ArgumentNullException(nameof(s)); } - - public void ConsumeInt32(int i) + if (s.Length == 0) { + throw new ArgumentException("String cannot be empty.", nameof(s)); } + } - public void ConsumeGuid(Guid g) + public void ConsumeInt32(int i) + { + } + + public void ConsumeGuid(Guid g) + { + if (g == Guid.Empty) { - if (g == Guid.Empty) - { - throw new ArgumentException("Guid cannot be empty.", nameof(g)); - } + throw new ArgumentException("Guid cannot be empty.", nameof(g)); } + } - public void ConsumeStringAndInt32(string s, int i) + public void ConsumeStringAndInt32(string s, int i) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } - if (s.Length == 0) - { - throw new ArgumentException("String cannot be empty.", nameof(s)); - } + throw new ArgumentException("String cannot be empty.", nameof(s)); } + } - public void ConsumeStringAndGuid(string s, Guid g) + public void ConsumeStringAndGuid(string s, Guid g) + { + if (s == null) { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } - if (s.Length == 0) - { - throw new ArgumentException("String cannot be empty.", nameof(s)); - } - if (g == Guid.Empty) - { - throw new ArgumentException("Guid cannot be empty.", nameof(g)); - } + throw new ArgumentNullException(nameof(s)); } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + if (g == Guid.Empty) + { + throw new ArgumentException("Guid cannot be empty.", nameof(g)); + } + } - public void ConsumeInt32AndGuid(int i, Guid g) + public void ConsumeInt32AndGuid(int i, Guid g) + { + if (g == Guid.Empty) { - if (g == Guid.Empty) - { - throw new ArgumentException("Guid cannot be empty.", nameof(g)); - } + throw new ArgumentException("Guid cannot be empty.", nameof(g)); } + } - public void ConsumeStringAndInt32AndGuid(string s, int i, Guid g) + public void ConsumeStringAndInt32AndGuid(string s, int i, Guid g) + { + if (s == null) + { + throw new ArgumentNullException(nameof(s)); + } + if (s.Length == 0) + { + throw new ArgumentException("String cannot be empty.", nameof(s)); + } + if (g == Guid.Empty) { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } - if (s.Length == 0) - { - throw new ArgumentException("String cannot be empty.", nameof(s)); - } - if (g == Guid.Empty) - { - throw new ArgumentException("Guid cannot be empty.", nameof(g)); - } + throw new ArgumentException("Guid cannot be empty.", nameof(g)); } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs index 63fbdcf..4a8adc6 100644 --- a/tests/TestTypeFoundation/GuardedPropertyHolder.cs +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -1,26 +1,25 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class GuardedPropertyHolder + where T : class { - public class GuardedPropertyHolder - where T : class + private T property; + + public T Property { - private T property; + get + { + return this.property; + } - public T Property + set { - get + if (value == null) { - return this.property; + throw new ArgumentNullException(nameof(value)); } - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - this.property = value; - } + this.property = value; } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs index 8cf8bf8..258b40b 100644 --- a/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs +++ b/tests/TestTypeFoundation/GuardedStaticMethodOnStaticTypeHost.cs @@ -1,13 +1,12 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public static class GuardedStaticMethodOnStaticTypeHost { - public static class GuardedStaticMethodOnStaticTypeHost + public static void Method(object argument) { - public static void Method(object argument) + if (argument == null) { - if (argument == null) - { - throw new ArgumentNullException(nameof(argument)); - } + throw new ArgumentNullException(nameof(argument)); } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/IInterface.cs b/tests/TestTypeFoundation/IInterface.cs index e556992..e3377b0 100644 --- a/tests/TestTypeFoundation/IInterface.cs +++ b/tests/TestTypeFoundation/IInterface.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public interface IInterface { - public interface IInterface - { - object MakeIt(object obj); - } -} + object MakeIt(object obj); +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs index ae59196..63a9bd2 100644 --- a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -1,32 +1,31 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class IllBehavedPropertyHolder { - public class IllBehavedPropertyHolder - { - private T propertyIllBehavedSet; + private T propertyIllBehavedSet; - public T PropertyIllBehavedGet + public T PropertyIllBehavedGet + { + get { - get - { - return default(T); - } + return default(T); + } - set - { - } + set + { } + } - public T PropertyIllBehavedSet + public T PropertyIllBehavedSet + { + get { - get - { - return this.propertyIllBehavedSet; - } + return this.propertyIllBehavedSet; + } - set - { - this.propertyIllBehavedSet = default(T); - } + set + { + this.propertyIllBehavedSet = default(T); } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs index b799134..406ee71 100644 --- a/tests/TestTypeFoundation/IndexedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -1,13 +1,12 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class IndexedPropertyHolder { - public class IndexedPropertyHolder - { - private readonly List items = new(); + private readonly List items = new(); - public T this[int index] - { - get { return this.items[index]; } - set { this.items[index] = value; } - } + public T this[int index] + { + get { return this.items[index]; } + set { this.items[index] = value; } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs index 3a153c1..4f54c29 100644 --- a/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs +++ b/tests/TestTypeFoundation/InternalGetterPropertyHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class InternalGetterPropertyHolder(T property) { - public class InternalGetterPropertyHolder(T property) - { - public T Property { internal get; set; } = property; - } + public T Property { internal get; set; } = property; } \ No newline at end of file diff --git a/tests/TestTypeFoundation/ItemContainer.cs b/tests/TestTypeFoundation/ItemContainer.cs index 56e9204..d66cd48 100644 --- a/tests/TestTypeFoundation/ItemContainer.cs +++ b/tests/TestTypeFoundation/ItemContainer.cs @@ -1,17 +1,16 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ItemContainer(params T[] items) { - public class ItemContainer(params T[] items) + public ItemContainer(IEnumerable items) + : this(items.ToArray()) { - public ItemContainer(IEnumerable items) - : this(items.ToArray()) - { - } - - public ItemContainer(IList items) - : this(items.ToArray()) - { - } + } - public IEnumerable Items { get; } = items; + public ItemContainer(IList items) + : this(items.ToArray()) + { } -} + + public IEnumerable Items { get; } = items; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs index dac108c..102b1f7 100644 --- a/tests/TestTypeFoundation/ItemHolder.cs +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -1,61 +1,60 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ItemHolder { - public class ItemHolder + public ItemHolder() { - public ItemHolder() - { - } + } - public ItemHolder(T1 item) - : this(new[] { item }, new T2[0]) - { - } + public ItemHolder(T1 item) + : this(new[] { item }, new T2[0]) + { + } - public ItemHolder(T2 item) - : this(new T1[0], new[] { item }) - { - } + public ItemHolder(T2 item) + : this(new T1[0], new[] { item }) + { + } - private ItemHolder(T1[] t1S, T2[] t2S) - { - this.Item1S = t1S; - this.Item2S = t2S; - } + private ItemHolder(T1[] t1S, T2[] t2S) + { + this.Item1S = t1S; + this.Item2S = t2S; + } - public IEnumerable Item1S { get; } + public IEnumerable Item1S { get; } - public IEnumerable Item2S { get; } - } + public IEnumerable Item2S { get; } +} - /* Note that constructors must be unordered because this class is used to test that - * constructors are correctly ordered by various implementations of IMethodQuery. For that - * reason, please don't be a boy scout and order constructors 'nicely'. */ - public class ItemHolder +/* Note that constructors must be unordered because this class is used to test that + * constructors are correctly ordered by various implementations of IMethodQuery. For that + * reason, please don't be a boy scout and order constructors 'nicely'. */ +public class ItemHolder +{ + public ItemHolder(T x, T y, T z) + : this(new[] { x, y, z }) { - public ItemHolder(T x, T y, T z) - : this(new[] { x, y, z }) - { - } - - public ItemHolder(T item) - : this(new[] { item }) - { - } + } - public ItemHolder() - { - } + public ItemHolder(T item) + : this(new[] { item }) + { + } - public ItemHolder(T x, T y) - : this(new[] { x, y }) - { - } + public ItemHolder() + { + } - private ItemHolder(T[] items) - { - this.Items = items; - } + public ItemHolder(T x, T y) + : this(new[] { x, y }) + { + } - public IEnumerable Items { get; } + private ItemHolder(T[] items) + { + this.Items = items; } -} + + public IEnumerable Items { get; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs index 86dafb0..c51e8a2 100644 --- a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs +++ b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs @@ -1,18 +1,35 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class MultiUnorderedConstructorType { - public class MultiUnorderedConstructorType + public MultiUnorderedConstructorType(ParameterObject paramObj) + : this(paramObj.Text, paramObj.Number) { - public MultiUnorderedConstructorType(ParameterObject paramObj) - : this(paramObj.Text, paramObj.Number) - { - } + } - public MultiUnorderedConstructorType() - : this(string.Empty, 0) + public MultiUnorderedConstructorType() + : this(string.Empty, 0) + { + } + + public MultiUnorderedConstructorType(string text, int number) + { + if (text == null) { + throw new ArgumentNullException(nameof(text)); } - public MultiUnorderedConstructorType(string text, int number) + this.Text = text; + this.Number = number; + } + + public string Text { get; } + + public int Number { get; } + + public class ParameterObject + { + public ParameterObject(string text, int number) { if (text == null) { @@ -26,23 +43,5 @@ public MultiUnorderedConstructorType(string text, int number) public string Text { get; } public int Number { get; } - - public class ParameterObject - { - public ParameterObject(string text, int number) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - this.Text = text; - this.Number = number; - } - - public string Text { get; } - - public int Number { get; } - } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/MutableValueType.cs b/tests/TestTypeFoundation/MutableValueType.cs index 3cd79bc..0fbc62a 100644 --- a/tests/TestTypeFoundation/MutableValueType.cs +++ b/tests/TestTypeFoundation/MutableValueType.cs @@ -1,11 +1,10 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public struct MutableValueType(object property1, object property2, object property3) { - public struct MutableValueType(object property1, object property2, object property3) - { - public object Property1 { get; set; } = property1; + public object Property1 { get; set; } = property1; - public object Property2 { get; set; } = property2; + public object Property2 { get; set; } = property2; - public object Property3 { get; set; } = property3; - } + public object Property3 { get; set; } = property3; } \ No newline at end of file diff --git a/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs b/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs index aec37b7..158d1a3 100644 --- a/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs +++ b/tests/TestTypeFoundation/MutableValueTypeWithoutConstructor.cs @@ -1,8 +1,7 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public struct MutableValueTypeWithoutConstructor { - public struct MutableValueTypeWithoutConstructor - { - public object Property1 { get; set; } - public object Property2 { get; set; } - } + public object Property1 { get; set; } + public object Property2 { get; set; } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs index 7318b69..00205a8 100644 --- a/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs +++ b/tests/TestTypeFoundation/NonCompliantCollectionHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class NonCompliantCollectionHolder { - public class NonCompliantCollectionHolder - { - public ICollection Collection { get; set; } = new List(); - } + public ICollection Collection { get; set; } = new List(); } \ No newline at end of file diff --git a/tests/TestTypeFoundation/NoopInterfaceImplementer.cs b/tests/TestTypeFoundation/NoopInterfaceImplementer.cs index 1b434ce..b99cd27 100644 --- a/tests/TestTypeFoundation/NoopInterfaceImplementer.cs +++ b/tests/TestTypeFoundation/NoopInterfaceImplementer.cs @@ -1,10 +1,9 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class NoopInterfaceImplementer : IInterface { - public class NoopInterfaceImplementer : IInterface + public object MakeIt(object obj) { - public object MakeIt(object obj) - { - return obj; - } + return obj; } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/PropertyHolder.cs b/tests/TestTypeFoundation/PropertyHolder.cs index 0055213..b1e471c 100644 --- a/tests/TestTypeFoundation/PropertyHolder.cs +++ b/tests/TestTypeFoundation/PropertyHolder.cs @@ -1,20 +1,19 @@ using System.Reflection; -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class PropertyHolder { - public class PropertyHolder - { - public T Property { get; set; } + public T Property { get; set; } - public void SetProperty(T value) - { - this.Property = value; - } + public void SetProperty(T value) + { + this.Property = value; + } - public static PropertyInfo GetProperty() - { - return typeof(PropertyHolder) - .GetRuntimeProperty(nameof(Property)); - } + public static PropertyInfo GetProperty() + { + return typeof(PropertyHolder) + .GetRuntimeProperty(nameof(Property)); } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/QuadrupleParameterType.cs b/tests/TestTypeFoundation/QuadrupleParameterType.cs index 0ed4724..4df736e 100644 --- a/tests/TestTypeFoundation/QuadrupleParameterType.cs +++ b/tests/TestTypeFoundation/QuadrupleParameterType.cs @@ -1,13 +1,12 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class QuadrupleParameterType(T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) { - public class QuadrupleParameterType(T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - { - public T1 Parameter1 { get; private set; } = parameter1; + public T1 Parameter1 { get; private set; } = parameter1; - public T2 Parameter2 { get; private set; } = parameter2; + public T2 Parameter2 { get; private set; } = parameter2; - public T3 Parameter3 { get; private set; } = parameter3; + public T3 Parameter3 { get; private set; } = parameter3; - public T4 Parameter4 { get; private set; } = parameter4; - } -} + public T4 Parameter4 { get; private set; } = parameter4; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs b/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs index 9b92a27..30250c9 100644 --- a/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs +++ b/tests/TestTypeFoundation/ReadOnlyFieldHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ReadOnlyFieldHolder { - public class ReadOnlyFieldHolder - { - public readonly T Field; - } -} + public readonly T Field; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs b/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs index 7717ef5..392624a 100644 --- a/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs +++ b/tests/TestTypeFoundation/ReadOnlyPropertyHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class ReadOnlyPropertyHolder { - public class ReadOnlyPropertyHolder - { - public T Property { get; private set; } - } -} + public T Property { get; private set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs index 1ae671d..30794e5 100644 --- a/tests/TestTypeFoundation/RecordType.cs +++ b/tests/TestTypeFoundation/RecordType.cs @@ -1,32 +1,31 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class RecordType(T value) : IEquatable> { - public class RecordType(T value) : IEquatable> - { - public T Value { get; } = value; + public T Value { get; } = value; - public bool Equals(RecordType? other) + public bool Equals(RecordType? other) + { + if (ReferenceEquals(null, other)) { - if (ReferenceEquals(null, other)) - { - return false; - } - - if (ReferenceEquals(this, other)) - { - return true; - } - - return EqualityComparer.Default.Equals(this.Value, other.Value); + return false; } - public override bool Equals(object? obj) + if (ReferenceEquals(this, other)) { - return this.Equals(obj as RecordType); + return true; } - public override int GetHashCode() - { - return EqualityComparer.Default.GetHashCode(this.Value); - } + return EqualityComparer.Default.Equals(this.Value, other.Value); + } + + public override bool Equals(object? obj) + { + return this.Equals(obj as RecordType); + } + + public override int GetHashCode() + { + return EqualityComparer.Default.GetHashCode(this.Value); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/SingleParameterType.cs b/tests/TestTypeFoundation/SingleParameterType.cs index 13b4017..ba34642 100644 --- a/tests/TestTypeFoundation/SingleParameterType.cs +++ b/tests/TestTypeFoundation/SingleParameterType.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class SingleParameterType(T parameter) { - public class SingleParameterType(T parameter) - { - public T Parameter { get; private set; } = parameter; - } -} + public T Parameter { get; private set; } = parameter; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/StaticFieldHolder.cs b/tests/TestTypeFoundation/StaticFieldHolder.cs index 56c9c54..738e055 100644 --- a/tests/TestTypeFoundation/StaticFieldHolder.cs +++ b/tests/TestTypeFoundation/StaticFieldHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class StaticFieldHolder { - public class StaticFieldHolder - { - public static T Field; - } -} + public static T Field; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/StaticPropertyHolder.cs b/tests/TestTypeFoundation/StaticPropertyHolder.cs index d4904c3..d95b0f7 100644 --- a/tests/TestTypeFoundation/StaticPropertyHolder.cs +++ b/tests/TestTypeFoundation/StaticPropertyHolder.cs @@ -1,7 +1,6 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class StaticPropertyHolder { - public class StaticPropertyHolder - { - public static T Property { get; set; } - } -} + public static T Property { get; set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TriState.cs b/tests/TestTypeFoundation/TriState.cs index 8e66094..c88423c 100644 --- a/tests/TestTypeFoundation/TriState.cs +++ b/tests/TestTypeFoundation/TriState.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public enum TriState { - public enum TriState - { - First = 0, - Second, - Third - } -} + First = 0, + Second, + Third +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TripleParameterType.cs b/tests/TestTypeFoundation/TripleParameterType.cs index aa30de0..d86f763 100644 --- a/tests/TestTypeFoundation/TripleParameterType.cs +++ b/tests/TestTypeFoundation/TripleParameterType.cs @@ -1,11 +1,10 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TripleParameterType(T1 parameter1, T2 parameter2, T3 parameter3) { - public class TripleParameterType(T1 parameter1, T2 parameter2, T3 parameter3) - { - public T1 Parameter1 { get; private set; } = parameter1; + public T1 Parameter1 { get; private set; } = parameter1; - public T2 Parameter2 { get; private set; } = parameter2; + public T2 Parameter2 { get; private set; } = parameter2; - public T3 Parameter3 { get; private set; } = parameter3; - } -} + public T3 Parameter3 { get; private set; } = parameter3; +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TriplePropertyHolder.cs b/tests/TestTypeFoundation/TriplePropertyHolder.cs index 7bbaca1..f9ec32a 100644 --- a/tests/TestTypeFoundation/TriplePropertyHolder.cs +++ b/tests/TestTypeFoundation/TriplePropertyHolder.cs @@ -1,11 +1,10 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TriplePropertyHolder { - public class TriplePropertyHolder - { - public T1 Property1 { get; set; } + public T1 Property1 { get; set; } - public T2 Property2 { get; set; } + public T2 Property2 { get; set; } - public T3 Property3 { get; set; } - } -} + public T3 Property3 { get; set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs b/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs index 659f7d1..300d37c 100644 --- a/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs +++ b/tests/TestTypeFoundation/TypeWithCastOperatorsWithoutPublicConstructor.cs @@ -1,19 +1,18 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithCastOperatorsWithoutPublicConstructor { - public class TypeWithCastOperatorsWithoutPublicConstructor + private TypeWithCastOperatorsWithoutPublicConstructor() { - private TypeWithCastOperatorsWithoutPublicConstructor() - { - } + } - public static implicit operator TypeWithCastOperatorsWithoutPublicConstructor(int ignored) - { - return new TypeWithCastOperatorsWithoutPublicConstructor(); - } + public static implicit operator TypeWithCastOperatorsWithoutPublicConstructor(int ignored) + { + return new TypeWithCastOperatorsWithoutPublicConstructor(); + } - public static explicit operator TypeWithCastOperatorsWithoutPublicConstructor(string ignored) - { - return new TypeWithCastOperatorsWithoutPublicConstructor(); - } + public static explicit operator TypeWithCastOperatorsWithoutPublicConstructor(string ignored) + { + return new TypeWithCastOperatorsWithoutPublicConstructor(); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs b/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs index d30d653..0007af5 100644 --- a/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs +++ b/tests/TestTypeFoundation/TypeWithConcreteParameterMethod.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithConcreteParameterMethod { - public class TypeWithConcreteParameterMethod + public void DoSomething(ConcreteType param) { - public void DoSomething(ConcreteType param) - { - } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs b/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs index 869be8c..4fcdd3c 100644 --- a/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs +++ b/tests/TestTypeFoundation/TypeWithEmptyEnumField.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithEmptyEnumField { - public class TypeWithEmptyEnumField - { - public EmptyEnum EmptyEnumField; + public EmptyEnum EmptyEnumField; - public EmptyEnum EmptyEnumProperty { get; set; } - } -} + public EmptyEnum EmptyEnumProperty { get; set; } +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithFactoryMethod.cs b/tests/TestTypeFoundation/TypeWithFactoryMethod.cs index de0ba1f..6921237 100644 --- a/tests/TestTypeFoundation/TypeWithFactoryMethod.cs +++ b/tests/TestTypeFoundation/TypeWithFactoryMethod.cs @@ -1,24 +1,23 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithFactoryMethod { - public class TypeWithFactoryMethod + private TypeWithFactoryMethod() { - private TypeWithFactoryMethod() - { - } + } - public static TypeWithFactoryMethod Create() - { - return new TypeWithFactoryMethod(); - } + public static TypeWithFactoryMethod Create() + { + return new TypeWithFactoryMethod(); + } - public static TypeWithFactoryMethod Create(object argument) - { - return new TypeWithFactoryMethod(); - } + public static TypeWithFactoryMethod Create(object argument) + { + return new TypeWithFactoryMethod(); + } - public static TypeWithFactoryMethod Create(IEnumerable arguments) - { - return new TypeWithFactoryMethod(); - } + public static TypeWithFactoryMethod Create(IEnumerable arguments) + { + return new TypeWithFactoryMethod(); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithFactoryProperty.cs b/tests/TestTypeFoundation/TypeWithFactoryProperty.cs index d4a6863..8355290 100644 --- a/tests/TestTypeFoundation/TypeWithFactoryProperty.cs +++ b/tests/TestTypeFoundation/TypeWithFactoryProperty.cs @@ -1,17 +1,16 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithFactoryProperty { - public class TypeWithFactoryProperty + private TypeWithFactoryProperty() { - private TypeWithFactoryProperty() - { - } + } - public static TypeWithFactoryProperty Factory + public static TypeWithFactoryProperty Factory + { + get { - get - { - return new TypeWithFactoryProperty(); - } + return new TypeWithFactoryProperty(); } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs index a5628f2..e5b7c0f 100644 --- a/tests/TestTypeFoundation/TypeWithIndexer.cs +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -1,19 +1,18 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithIndexer { - public class TypeWithIndexer - { - private readonly Dictionary dict = new(); + private readonly Dictionary dict = new(); - public string this[string index] + public string this[string index] + { + get + { + return this.dict[index]; + } + set { - get - { - return this.dict[index]; - } - set - { - this.dict[index] = value; - } + this.dict[index] = value; } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs b/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs index ff83f4d..7751e05 100644 --- a/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs +++ b/tests/TestTypeFoundation/TypeWithOverloadedMembers.cs @@ -1,29 +1,28 @@ using System.Reflection; -namespace TestTypeFoundation -{ - public class TypeWithOverloadedMembers - { - public object SomeProperty { get; set; } +namespace TestTypeFoundation; - public void DoSomething() - { - } +public class TypeWithOverloadedMembers +{ + public object SomeProperty { get; set; } - public void DoSomething(object obj) - { - } + public void DoSomething() + { + } - public void DoSomething(object x, object y) - { - } + public void DoSomething(object obj) + { + } - public void DoSomething(object x, object y, object z) - { - } + public void DoSomething(object x, object y) + { + } - public static MethodInfo GetDoSomethingMethod(params Type[] parameterTypes) => - typeof(TypeWithOverloadedMembers) - .GetMethod(nameof(DoSomething), parameterTypes); + public void DoSomething(object x, object y, object z) + { } -} + + public static MethodInfo GetDoSomethingMethod(params Type[] parameterTypes) => + typeof(TypeWithOverloadedMembers) + .GetMethod(nameof(DoSomething), parameterTypes); +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs b/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs index 84a46c8..695353f 100644 --- a/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs +++ b/tests/TestTypeFoundation/TypeWithPseudoFactoryMethod.cs @@ -1,21 +1,20 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +/// +/// This type contains a method that returns an instance of the same type +/// so that it looks like a Factory Method. In fact, it is not because it +/// receives a parameter of the same type, so using it as a factory inevitably +/// leads to circular dependencies. +/// +public class TypeWithPseudoFactoryMethod { - /// - /// This type contains a method that returns an instance of the same type - /// so that it looks like a Factory Method. In fact, it is not because it - /// receives a parameter of the same type, so using it as a factory inevitably - /// leads to circular dependencies. - /// - public class TypeWithPseudoFactoryMethod + private TypeWithPseudoFactoryMethod() { - private TypeWithPseudoFactoryMethod() - { - } + } - public static TypeWithPseudoFactoryMethod DoSomething( - TypeWithPseudoFactoryMethod argument) - { - return new TypeWithPseudoFactoryMethod(); - } + public static TypeWithPseudoFactoryMethod DoSomething( + TypeWithPseudoFactoryMethod argument) + { + return new TypeWithPseudoFactoryMethod(); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithRefMethod.cs b/tests/TestTypeFoundation/TypeWithRefMethod.cs index 36efe98..fb54c33 100644 --- a/tests/TestTypeFoundation/TypeWithRefMethod.cs +++ b/tests/TestTypeFoundation/TypeWithRefMethod.cs @@ -1,17 +1,16 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class TypeWithRefMethod { - public class TypeWithRefMethod + public void InvokeIt(T x, ref T y) { - public void InvokeIt(T x, ref T y) + if (x == null) { - if (x == null) - { - throw new ArgumentNullException(nameof(x)); - } - if (y == null) - { - throw new ArgumentNullException(nameof(y)); - } + throw new ArgumentNullException(nameof(x)); + } + if (y == null) + { + throw new ArgumentNullException(nameof(y)); } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedConstructorHost.cs b/tests/TestTypeFoundation/UnguardedConstructorHost.cs index c4a4d29..6e64938 100644 --- a/tests/TestTypeFoundation/UnguardedConstructorHost.cs +++ b/tests/TestTypeFoundation/UnguardedConstructorHost.cs @@ -1,22 +1,21 @@ using System.Reflection; -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class UnguardedConstructorHost(T item) { - public class UnguardedConstructorHost(T item) - { - public T Item { get; } = item; + public T Item { get; } = item; - private static ConstructorInfo GetConstructor() - { - var typeInfo = typeof(UnguardedConstructorHost) - .GetTypeInfo(); + private static ConstructorInfo GetConstructor() + { + var typeInfo = typeof(UnguardedConstructorHost) + .GetTypeInfo(); - return typeInfo.DeclaredConstructors.Single(); - } + return typeInfo.DeclaredConstructors.Single(); + } - public static ParameterInfo GetParameter() - { - return GetConstructor().GetParameters().Single(); - } + public static ParameterInfo GetParameter() + { + return GetConstructor().GetParameters().Single(); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedMethodHost.cs b/tests/TestTypeFoundation/UnguardedMethodHost.cs index ad85751..6e06bb3 100644 --- a/tests/TestTypeFoundation/UnguardedMethodHost.cs +++ b/tests/TestTypeFoundation/UnguardedMethodHost.cs @@ -1,17 +1,16 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public class UnguardedMethodHost { - public class UnguardedMethodHost + public void ConsumeUnguardedString(string s) { - public void ConsumeUnguardedString(string s) - { - } + } - public void ConsumeGuardedGuidAndUnguardedString(Guid g, string s) + public void ConsumeGuardedGuidAndUnguardedString(Guid g, string s) + { + if (g == Guid.Empty) { - if (g == Guid.Empty) - { - throw new ArgumentException("Guid cannot be empty.", nameof(g)); - } + throw new ArgumentException("Guid cannot be empty.", nameof(g)); } } -} +} \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs b/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs index 66a138c..338390c 100644 --- a/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs +++ b/tests/TestTypeFoundation/UnguardedStaticMethodOnStaticTypeHost.cs @@ -1,9 +1,8 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public static class UnguardedStaticMethodOnStaticTypeHost { - public static class UnguardedStaticMethodOnStaticTypeHost + public static void Method(object argument) { - public static void Method(object argument) - { - } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs b/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs index ba67c65..92c1dfe 100644 --- a/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs +++ b/tests/TestTypeFoundation/UnguardedStaticPropertyOnStaticTypeHost.cs @@ -1,11 +1,10 @@ -namespace TestTypeFoundation +namespace TestTypeFoundation; + +public static class UnguardedStaticPropertyOnStaticTypeHost { - public static class UnguardedStaticPropertyOnStaticTypeHost + public static object Property { - public static object Property - { - get; - set; - } + get; + set; } } \ No newline at end of file From 7555521052245fb811b1cdde65f553e19c780181 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:47:51 +0100 Subject: [PATCH 7/9] Style fixes --- .nuke/build.schema.json | 12 ++-- AutoFixture.globalconfig | 2 + build/Build.cs | 18 ++--- .../ArgumentsAutoDataAttribute.cs | 14 ++-- src/AutoFixture.TUnit/AutoDataAttribute.cs | 6 +- .../AutoFixtureDataSourceAttribute.cs | 6 +- .../ClassAutoDataAttribute.cs | 28 ++++---- .../CompositeDataAttribute.cs | 16 ++--- src/AutoFixture.TUnit/FrozenAttribute.cs | 4 +- src/AutoFixture.TUnit/Internal/Argument.cs | 6 +- .../Internal/AutoDataSource.cs | 22 +++--- .../Internal/ClassDataSource.cs | 18 ++--- .../Internal/EnumerableExtensions.cs | 14 ---- .../Internal/FieldDataSource.cs | 8 +-- .../Internal/FrozenValueCustomization.cs | 4 +- .../Internal/InlineDataSource.cs | 14 ++-- .../Internal/MemberDataSource.cs | 28 ++++---- .../Internal/MethodDataSource.cs | 16 ++--- .../Internal/ParameterFilter.cs | 12 ++-- .../Internal/ParameterMatcherBuilder.cs | 2 +- .../Internal/PropertyDataSource.cs | 8 +-- .../Internal/TestParameter.cs | 12 ++-- .../MemberAutoDataAttribute.cs | 28 ++++---- .../ArgumentsAutoDataAttributeTests.cs | 2 +- .../ClassAutoDataAttributeTests.cs | 16 ++--- ...ompositeDataAttributeSufficientDataTest.cs | 70 +++++++++---------- .../DependencyConstraintsTests.cs | 2 +- .../Internal/AutoDataSourceTests.cs | 14 ++-- .../Internal/ClassDataSourceTests.cs | 18 ++--- .../Internal/DataSourceTests.cs | 12 ++-- .../Internal/FieldDataSourceTests.cs | 10 +-- .../Internal/InlineDataSourceTests.cs | 12 ++-- .../Internal/MemberDataSourceTests.cs | 6 +- .../Internal/MethodDataSourceTests.cs | 14 ++-- .../Internal/PropertyDataSourceTests.cs | 18 ++--- .../MemberAutoDataAttributeScenarioTests.cs | 6 +- .../MemberAutoDataAttributeTest.cs | 36 +++++----- tests/AutoFixture.TUnit.Tests/Scenario.cs | 32 ++++----- .../TestTypes/ClassWithEmptyTestData.cs | 6 +- .../TestTypes/ClassWithNullTestData.cs | 6 +- .../TestTypes/DelegatingCustomization.cs | 4 +- .../TestTypes/DelegatingCustomizeAttribute.cs | 2 +- .../TestTypes/DelegatingDataSource.cs | 6 +- .../TestTypes/DelegatingFixture.cs | 16 +++-- .../TestTypes/DelegatingMemberDataSource.cs | 4 +- .../TestTypes/DelegatingSpecimenBuilder.cs | 2 +- .../TestTypes/DelegatingTestData.cs | 16 ++--- .../DerivedArgumentsAutoDataAttribute.cs | 2 +- .../DerivedClassAutoDataAttribute.cs | 2 +- .../DerivedMemberAutoDataAttribute.cs | 4 +- .../TestTypes/EmptyClassData.cs | 6 +- .../TestTypes/FakeDataAttribute.cs | 6 +- .../TestTypes/InlineAttributeTestData.cs | 4 +- .../TestTypes/InlineFrozenValuesTestData.cs | 4 +- .../InlinePrimitiveValuesTestData.cs | 4 +- .../TestTypes/MixedTypeClassData.cs | 6 +- .../TestTypes/ParameterNameCriterion.cs | 2 +- .../TestTypes/ParameterizedClassData.cs | 6 +- .../TestTypes/TestTypeWithMethodData.cs | 18 ++--- .../AbstractTypeWithNonDefaultConstructor.cs | 2 +- tests/TestTypeFoundation/CompositeType.cs | 2 +- tests/TestTypeFoundation/ConcreteType.cs | 20 +++--- tests/TestTypeFoundation/GenericType.cs | 2 +- .../GuardedConstructorHost.cs | 2 +- ...nstructorHostHoldingStaticReadOnlyField.cs | 2 +- ...ructorHostHoldingStaticReadOnlyProperty.cs | 2 +- .../GuardedPropertyHolder.cs | 6 +- .../IllBehavedPropertyHolder.cs | 6 +- .../IndexedPropertyHolder.cs | 8 ++- tests/TestTypeFoundation/ItemHolder.cs | 18 ++--- .../MultiUnorderedConstructorType.cs | 8 +-- tests/TestTypeFoundation/PropertyHolder.cs | 2 +- tests/TestTypeFoundation/RecordType.cs | 6 +- tests/TestTypeFoundation/TypeWithIndexer.cs | 6 +- 74 files changed, 391 insertions(+), 393 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 75d776d..b96acab 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -105,11 +105,11 @@ "allOf": [ { "properties": { - "CI": { + "_ci": { "type": "boolean", "description": "Forces the continuous integration build flag" }, - "Configuration": { + "_configuration": { "type": "string", "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", "enum": [ @@ -118,6 +118,10 @@ "Verify" ] }, + "_solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded. Default is AutoFixture.TUnit.sln" + }, "github-token": { "type": "string", "description": "GitHub auth token", @@ -127,10 +131,6 @@ "type": "string", "description": "NuGet API Key (secret)", "default": "Secrets must be entered via 'nuke :secrets [profile]'" - }, - "Solution": { - "type": "string", - "description": "Path to a solution file that is automatically loaded" } } }, diff --git a/AutoFixture.globalconfig b/AutoFixture.globalconfig index 297b7df..3f911a7 100644 --- a/AutoFixture.globalconfig +++ b/AutoFixture.globalconfig @@ -26,6 +26,7 @@ dotnet_diagnostic.CA5394.severity = none # CA5394: Do not use insecure randomnes ## StyleCop Analyzers ## +dotnet_diagnostic.SA1101.severity = none # SA1101: Prefix local calls with this. dotnet_diagnostic.SA1116.severity = none # SA1116: The parameters should begin on the line after the declaration, whenever the parameter span across multiple line dotnet_diagnostic.SA1117.severity = none # SA1117: The parameters should all be placed on the same line or each parameter should be placed on its own line. dotnet_diagnostic.SA1118.severity = none # SA1118: The parameter spans multiple lines @@ -35,6 +36,7 @@ dotnet_diagnostic.SA1202.severity = none # SA1202: 'public' members should come dotnet_diagnostic.SA1203.severity = none # SA1203: Constant fields should appear before non-constant fields dotnet_diagnostic.SA1204.severity = none # SA1204: Static members should appear before non-static members dotnet_diagnostic.SA1214.severity = none # SA1214: Readonly fields should appear before non-readonly fields +dotnet_diagnostic.SA1309.severity = none # SA1309: Field names should not begin with an underscore dotnet_diagnostic.SA1413.severity = none # SA1413: Use trailing comma in multi-line initializers dotnet_diagnostic.SA1501.severity = none # SA1501: Statement should not be on a single line dotnet_diagnostic.SA1503.severity = none # SA1503: Braces should not be omitted diff --git a/build/Build.cs b/build/Build.cs index 546e1ee..9ce5c61 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -20,19 +20,19 @@ "continuous", GitHubActionsImage.WindowsLatest, AutoGenerate = false, - OnPullRequestBranches = new[] { MasterBranch, ReleaseBranch }, + OnPullRequestBranches = [MasterBranch, ReleaseBranch], PublishArtifacts = false, - InvokedTargets = new[] { nameof(Verify), nameof(Cover), nameof(Pack) }, + InvokedTargets = [nameof(Verify), nameof(Cover), nameof(Pack)], EnableGitHubToken = true)] [GitHubActions( "release", GitHubActionsImage.WindowsLatest, AutoGenerate = false, - OnPushTags = new[] { "v*" }, + OnPushTags = ["v*"], PublishArtifacts = true, - InvokedTargets = new[] { nameof(Verify), nameof(Cover), nameof(Publish) }, + InvokedTargets = [nameof(Verify), nameof(Cover), nameof(Publish)], EnableGitHubToken = true, - ImportSecrets = new[] { Secrets.NuGetApiKey })] + ImportSecrets = [Secrets.NuGetApiKey])] class Build : NukeBuild { public static int Main() => Execute(x => x.Compile); @@ -43,7 +43,7 @@ class Build : NukeBuild [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration _configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; - [Solution] readonly Solution _solution; + [Solution("AutoFixture.TUnit.sln")] readonly Solution _solution; [GitRepository] readonly GitRepository _gitRepository; [GitVersion] readonly GitVersion _gitVersion; [CI] readonly GitHubActions _gitHubActions; @@ -54,11 +54,11 @@ class Build : NukeBuild [Secret][Parameter("NuGet API Key (secret)", Name = Secrets.NuGetApiKey)] readonly string _nuGetApiKey; readonly string _nuGetSource = "https://api.nuget.org/v3/index.json"; - IEnumerable Excluded => new[] - { + IEnumerable Excluded => + [ _solution.GetProject("_build"), _solution.GetProject("TestTypeFoundation") - }; + ]; IEnumerable TestProjects => _solution.GetAllProjects("*Tests"); IEnumerable Libraries => _solution.Projects.Except(TestProjects).Except(Excluded); diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs index 3fef5b6..5d5c20e 100644 --- a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -16,7 +16,7 @@ public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute /// Initializes a new instance of the class. /// /// The data values to pass to the theory. - public ArgumentsAutoDataAttribute(params object[] values) + public ArgumentsAutoDataAttribute(params object?[] values) : this(() => new Fixture(), values) { } @@ -27,10 +27,10 @@ public ArgumentsAutoDataAttribute(params object[] values) /// The fixture factory. /// The data values to pass to the theory. /// - protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) + protected ArgumentsAutoDataAttribute(Func fixtureFactory, params object?[]? values) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.Values = values ?? new object[] { null }; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + Values = values ?? [null]; } /// @@ -41,12 +41,12 @@ protected ArgumentsAutoDataAttribute(Func fixtureFactory, params objec /// /// Gets the data values to pass to the theory. /// - public object[] Values { get; } + public object?[] Values { get; } /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) + return new AutoDataSource(FixtureFactory, new InlineDataSource(Values)) .GenerateDataSources(dataGeneratorMetadata) .Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs index 39ae64d..3ef8bb1 100644 --- a/src/AutoFixture.TUnit/AutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -34,7 +34,7 @@ public AutoDataAttribute() /// The fixture factory used to construct the fixture. protected AutoDataAttribute(Func fixtureFactory) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); } /// @@ -43,9 +43,9 @@ protected AutoDataAttribute(Func fixtureFactory) public Func FixtureFactory { get; } /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var source = new AutoDataSource(this.FixtureFactory); + var source = new AutoDataSource(FixtureFactory); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs index 115333d..beb578c 100644 --- a/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs +++ b/src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs @@ -15,7 +15,7 @@ public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGenerat public abstract IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata); /// - public override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) { if (dataGeneratorMetadata is null) { @@ -24,7 +24,7 @@ public override IEnumerable> GenerateDataSources(DataGeneratorMet return GetTestDataEnumerable(); - IEnumerable> GetTestDataEnumerable() + IEnumerable> GetTestDataEnumerable() { var parameters = dataGeneratorMetadata.MembersToGenerate; if (parameters.Length == 0) @@ -34,7 +34,7 @@ IEnumerable> GetTestDataEnumerable() yield break; } - var enumerable = this.GetData(dataGeneratorMetadata) + var enumerable = GetData(dataGeneratorMetadata) ?? throw new InvalidOperationException("The source member yielded no test data."); foreach (var testData in enumerable) diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs index 8e532be..eca3ceb 100644 --- a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -18,7 +18,7 @@ public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute /// /// The type of the class that provides the data. /// The parameters passed to the data provider class constructor. - public ClassAutoDataAttribute(Type sourceType, params object[] parameters) + public ClassAutoDataAttribute(Type sourceType, params object?[] parameters) : this(() => new Fixture(), sourceType, parameters) { } @@ -56,24 +56,24 @@ public ClassAutoDataAttribute(Type sourceType, params object[] parameters) /// } /// } /// - /// private class MyTestData : IEnumerable<object[]> + /// private class MyTestData : IEnumerable<object?[]> /// { - /// public IEnumerator<object[]> GetEnumerator() + /// public IEnumerator<object?[]> GetEnumerator() /// { - /// yield return new object[] { 0, new int[0] }; - /// yield return new object[] { 4, new int[] { 1, 2, 1} }; - /// yield return new object[] { 23, new int [] { 0, 13, 15, -5 } }; + /// yield return new object?[] { 0, new int[0] }; + /// yield return new object?[] { 4, new int[] { 1, 2, 1} }; + /// yield return new object?[] { 23, new int [] { 0, 13, 15, -5 } }; /// } /// /// IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); /// } /// /// - protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) + protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object?[] parameters) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); - this.Parameters = parameters ?? new object[] { null }; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); + Parameters = parameters ?? [null]; } /// @@ -89,14 +89,14 @@ protected ClassAutoDataAttribute(Func fixtureFactory, Type sourceType, /// /// Gets the constructor parameters for . /// - public object[] Parameters { get; } + public object?[] Parameters { get; } /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { var source = new AutoDataSource( - this.FixtureFactory, - new ClassDataSource(this.SourceType, this.Parameters)); + FixtureFactory, + new ClassDataSource(SourceType, Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index 2b1e310..641d765 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -11,7 +11,7 @@ namespace AutoFixture.TUnit; Justification = "This attribute is the root of a potential attribute hierarchy.")] public class CompositeDataAttribute : AutoFixtureDataSourceAttribute { - private readonly AutoFixtureDataSourceAttribute[] attributes; + private readonly AutoFixtureDataSourceAttribute[] _attributes; /// /// Initializes a new instance of the class. @@ -28,24 +28,24 @@ public CompositeDataAttribute(IEnumerable attrib /// The attributes representing a data source for a data theory. public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes) { - this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); + this._attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); } /// /// Gets the attributes supplied through one of the constructors. /// - public IReadOnlyList Attributes => Array.AsReadOnly(this.attributes); + public IReadOnlyList Attributes => Array.AsReadOnly(_attributes); /// - public override IEnumerable GetData(DataGeneratorMetadata metadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - if (metadata is null) + if (dataGeneratorMetadata is null) { - throw new ArgumentNullException(nameof(metadata)); + throw new ArgumentNullException(nameof(dataGeneratorMetadata)); } - var results = this.attributes - .Select(attr => attr.GenerateDataSources(metadata)) + var results = _attributes + .Select(attr => attr.GenerateDataSources(dataGeneratorMetadata)) .ToArray(); var theoryRows = results diff --git a/src/AutoFixture.TUnit/FrozenAttribute.cs b/src/AutoFixture.TUnit/FrozenAttribute.cs index 4b50c8f..2112d18 100644 --- a/src/AutoFixture.TUnit/FrozenAttribute.cs +++ b/src/AutoFixture.TUnit/FrozenAttribute.cs @@ -36,7 +36,7 @@ public FrozenAttribute() /// public FrozenAttribute(Matching by) { - this.By = by; + By = by; } /// @@ -65,7 +65,7 @@ public override ICustomization GetCustomization(ParameterInfo parameter) throw new ArgumentNullException(nameof(parameter)); } - var matcher = new ParameterMatcherBuilder(parameter).SetFlags(this.By).Build(); + var matcher = new ParameterMatcherBuilder(parameter).SetFlags(By).Build(); return new FreezeOnMatchCustomization(parameter, matcher); } diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index 0062521..c194698 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -1,10 +1,10 @@ namespace AutoFixture.TUnit.Internal; -internal class Argument(TestParameter parameter, object value) +internal class Argument(TestParameter parameter, object? value) { public TestParameter Parameter { get; } = parameter ?? throw new ArgumentNullException(nameof(parameter)); - public object Value { get; } = value; + public object? Value { get; } = value; - public ICustomization GetCustomization() => this.Parameter.GetCustomization(this.Value); + public ICustomization GetCustomization() => Parameter.GetCustomization(Value); } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs index 9180708..b247860 100644 --- a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -17,8 +17,8 @@ public class AutoDataSource : DataSource /// public AutoDataSource(Func createFixture, IDataSource? source = default) { - this.CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); - this.Source = source; + CreateFixture = createFixture ?? throw new ArgumentNullException(nameof(createFixture)); + Source = source; } /// @@ -36,21 +36,21 @@ public AutoDataSource(Func createFixture, IDataSource? source = defaul /// /// The target method for which to provide the arguments. /// Returns a sequence of argument collections. - public override IEnumerable GetData(DataGeneratorMetadata metadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.Source is null - ? this.GenerateValues(metadata) - : this.CombineValues(metadata, this.Source); + return Source is null + ? GenerateValues(dataGeneratorMetadata) + : CombineValues(dataGeneratorMetadata, Source); } - private IEnumerable GenerateValues(DataGeneratorMetadata metadata) + private IEnumerable GenerateValues(DataGeneratorMetadata metadata) { var parameters = Array.ConvertAll(metadata.GetMethod().GetParameters(), TestParameter.From); - var fixture = this.CreateFixture(); + var fixture = CreateFixture(); yield return Array.ConvertAll(parameters, parameter => GenerateAutoValue(parameter, fixture)); } - private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDataSource source) + private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDataSource source) { var method = metadata.GetMethod(); @@ -58,12 +58,12 @@ private IEnumerable CombineValues(DataGeneratorMetadata metadata, IDat foreach (var testData in source.GetData(metadata)) { - var customizations = parameters.Take(testData.Length) + var customizations = parameters.Take(testData!.Length) .Zip(testData, (parameter, value) => new Argument(parameter, value)) .Select(argument => argument.GetCustomization()) .Where(x => x is not NullCustomization); - var fixture = this.CreateFixture(); + var fixture = CreateFixture(); foreach (var customization in customizations) { diff --git a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs index e1f0376..7b8ed69 100644 --- a/src/AutoFixture.TUnit/Internal/ClassDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/ClassDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal; Justification = "Type is not a collection.")] public class ClassDataSource : DataSource { - private readonly object[] parameters; + private readonly object?[] _parameters; /// /// Creates an instance of type . @@ -17,10 +17,10 @@ public class ClassDataSource : DataSource /// The test data source type. /// Constructor arguments for the source type. /// Thrown when arguments are . - public ClassDataSource(Type type, params object[] parameters) + public ClassDataSource(Type type, params object?[] parameters) { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + Type = type ?? throw new ArgumentNullException(nameof(type)); + this._parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); } /// @@ -31,16 +31,16 @@ public ClassDataSource(Type type, params object[] parameters) /// /// Gets the constructor parameters for test data source type. /// - public IReadOnlyList Parameters => Array.AsReadOnly(this.parameters); + public IReadOnlyList Parameters => Array.AsReadOnly(_parameters); /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var instance = Activator.CreateInstance(type: this.Type, args: this.parameters); + var instance = Activator.CreateInstance(type: Type, args: _parameters); - if (instance is not IEnumerable enumerable) + if (instance is not IEnumerable enumerable) { - throw new InvalidOperationException($"Data source type \"{this.Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); + throw new InvalidOperationException($"Data source type \"{Type}\" should implement the \"{typeof(IEnumerable)}\" interface."); } return enumerable; diff --git a/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs index 7e893b8..f05c768 100644 --- a/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs +++ b/src/AutoFixture.TUnit/Internal/EnumerableExtensions.cs @@ -40,18 +40,4 @@ internal static IEnumerable Collapse(this IEnumerable> sequ } } } - - /// - /// Casts the source sequence to an . - /// Enumerates the source sequence to an array if it is not an enumerated collection. - /// - /// The source sequence. - /// The sequence item type. - /// An that contains elements of the source sequence. - public static IReadOnlyCollection AsReadOnlyCollection(this IEnumerable source) - { - return source is not null - ? source as IReadOnlyCollection ?? source.ToArray() - : null; - } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs index 193f2e9..53fbba0 100644 --- a/src/AutoFixture.TUnit/Internal/FieldDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/FieldDataSource.cs @@ -19,7 +19,7 @@ public class FieldDataSource : DataSource /// public FieldDataSource(FieldInfo fieldInfo) { - this.FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); + FieldInfo = fieldInfo ?? throw new ArgumentNullException(nameof(fieldInfo)); } /// @@ -34,10 +34,10 @@ public FieldDataSource(FieldInfo fieldInfo) /// /// Thrown when the field does not return an enumerable value. /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.FieldInfo.GetValue(null); - if (value is not IEnumerable enumerable) + var value = FieldInfo.GetValue(null); + if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); } diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index e867d13..7ae8b08 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -4,13 +4,13 @@ namespace AutoFixture.TUnit.Internal; internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization { - private readonly IRequestSpecification specification = specification ?? throw new ArgumentNullException(nameof(specification)); + private readonly IRequestSpecification _specification = specification ?? throw new ArgumentNullException(nameof(specification)); public void Customize(IFixture fixture) { var builder = new FilteringSpecimenBuilder( builder: new FixedBuilder(value), - specification: this.specification); + specification: _specification); fixture.Customizations.Insert(0, builder); } diff --git a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs index e57ba67..be0f78d 100644 --- a/src/AutoFixture.TUnit/Internal/InlineDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/InlineDataSource.cs @@ -9,7 +9,7 @@ namespace AutoFixture.TUnit.Internal; Justification = "Type is not a collection.")] public sealed class InlineDataSource : AutoFixtureDataSourceAttribute { - private readonly object[] values; + private readonly object?[] _values; /// /// Creates an instance of type . @@ -18,18 +18,18 @@ public sealed class InlineDataSource : AutoFixtureDataSourceAttribute /// /// Thrown when the values collection is . /// - public InlineDataSource(object[] values) + public InlineDataSource(object?[] values) { - this.values = values ?? throw new ArgumentNullException(nameof(values)); + this._values = values ?? throw new ArgumentNullException(nameof(values)); } /// /// The collection of inline values. /// - public IReadOnlyList Values => Array.AsReadOnly(this.values); + public IReadOnlyList Values => Array.AsReadOnly(_values); /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { if (dataGeneratorMetadata is null) { @@ -37,12 +37,12 @@ public override IEnumerable GetData(DataGeneratorMetadata dataGenerato } var membersToGenerate = dataGeneratorMetadata.MembersToGenerate; - if (this.values.Length > membersToGenerate.Length) + if (_values.Length > membersToGenerate.Length) { throw new InvalidOperationException( "The number of arguments provided exceeds the number of parameters."); } - yield return this.values; + yield return _values; } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs index 1a9a1d9..051b500 100644 --- a/src/AutoFixture.TUnit/Internal/MemberDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MemberDataSource.cs @@ -8,7 +8,7 @@ namespace AutoFixture.TUnit.Internal; /// public class MemberDataSource : IDataSource { - private readonly object[] arguments; + private readonly object?[] _arguments; /// /// Creates an instance of type . @@ -17,12 +17,12 @@ public class MemberDataSource : IDataSource /// The name of the member. /// The arguments provided to the member. /// Thrown when arguments are . - public MemberDataSource(Type type, string name, params object[] arguments) + public MemberDataSource(Type type, string name, params object?[] arguments) { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); - this.Source = this.GetTestDataSource(); + Type = type ?? throw new ArgumentNullException(nameof(type)); + Name = name ?? throw new ArgumentNullException(nameof(name)); + this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + Source = GetTestDataSource(); } /// @@ -38,7 +38,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) /// /// Gets the arguments provided to the member. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); /// /// Gets the test data source. @@ -47,7 +47,7 @@ public MemberDataSource(Type type, string name, params object[] arguments) private DataSource GetTestDataSource() { - var sourceMember = this.Type.GetMember(this.Name, + var sourceMember = Type.GetMember(Name, MemberTypes.Method | MemberTypes.Field | MemberTypes.Property, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy) .FirstOrDefault(); @@ -57,17 +57,17 @@ private DataSource GetTestDataSource() var message = string.Format( CultureInfo.CurrentCulture, "Could not find public static member (property, field, or method) named '{0}' on {1}", - this.Name, this.Type.FullName); + Name, Type.FullName); throw new ArgumentException(message); } var returnType = sourceMember.GetReturnType(); - if (!typeof(IEnumerable).IsAssignableFrom(returnType)) + if (!typeof(IEnumerable).IsAssignableFrom(returnType)) { var message = string.Format( CultureInfo.CurrentCulture, - "Member {0} on {1} does not return IEnumerable", - this.Name, this.Type.FullName); + "Member {0} on {1} does not return IEnumerable", + Name, Type.FullName); throw new ArgumentException(message); } @@ -75,7 +75,7 @@ private DataSource GetTestDataSource() { FieldInfo fieldInfo => new FieldDataSource(fieldInfo), PropertyInfo propertyInfo => new PropertyDataSource(propertyInfo), - MethodInfo methodInfo => new MethodDataSource(methodInfo, this.arguments), + MethodInfo methodInfo => new MethodDataSource(methodInfo, _arguments), _ => throw new InvalidOperationException("Unsupported member type.") }; } @@ -83,6 +83,6 @@ private DataSource GetTestDataSource() /// public IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); + return Source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs index 382b312..4c27946 100644 --- a/src/AutoFixture.TUnit/Internal/MethodDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/MethodDataSource.cs @@ -10,17 +10,17 @@ namespace AutoFixture.TUnit.Internal; Justification = "Type is not a collection.")] public class MethodDataSource : DataSource { - private readonly object[] arguments; + private readonly object?[] _arguments; /// /// Creates an instance of type . /// /// The source method. /// The source method arguments. - public MethodDataSource(MethodInfo methodInfo, params object[] arguments) + public MethodDataSource(MethodInfo methodInfo, params object?[] arguments) { - this.MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); - this.arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo)); + this._arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); } /// @@ -31,13 +31,13 @@ public MethodDataSource(MethodInfo methodInfo, params object[] arguments) /// /// Gets the source method arguments. /// - public IReadOnlyList Arguments => Array.AsReadOnly(this.arguments); + public IReadOnlyList Arguments => Array.AsReadOnly(_arguments); /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.MethodInfo.Invoke(null, this.arguments); - if (value is not IEnumerable enumerable) + var value = MethodInfo.Invoke(null, _arguments); + if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); } diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index d6e10db..a03d907 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -8,7 +8,7 @@ namespace AutoFixture.TUnit.Internal; /// internal class ParameterFilter : IRequestSpecification { - private readonly IRequestSpecification matcherSpecification; + private readonly IRequestSpecification _matcherSpecification; /// /// Creates an instance of type . @@ -18,10 +18,10 @@ internal class ParameterFilter : IRequestSpecification /// Thrown when is null. public ParameterFilter(ParameterInfo parameterInfo, Matching flags) { - this.ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - this.Flags = flags; - this.matcherSpecification = new ParameterMatcherBuilder(this.ParameterInfo) - .SetFlags(this.Flags).Build(); + ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); + Flags = flags; + _matcherSpecification = new ParameterMatcherBuilder(ParameterInfo) + .SetFlags(Flags).Build(); } /// @@ -37,6 +37,6 @@ public ParameterFilter(ParameterInfo parameterInfo, Matching flags) /// public bool IsSatisfiedBy(object request) { - return this.matcherSpecification.IsSatisfiedBy(request); + return _matcherSpecification.IsSatisfiedBy(request); } } \ No newline at end of file diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index 9dc4d65..1bb17ad 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -183,7 +183,7 @@ private IRequestSpecification AsField() private class DerivesFromTypeComparer : IEqualityComparer { - public bool Equals(Type x, Type y) + public bool Equals(Type? x, Type? y) { return y switch { diff --git a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs index 4de76b1..fb4ff60 100644 --- a/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/PropertyDataSource.cs @@ -17,7 +17,7 @@ public class PropertyDataSource : DataSource /// public PropertyDataSource(PropertyInfo propertyInfo) { - this.PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); + PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); } /// @@ -26,11 +26,11 @@ public PropertyDataSource(PropertyInfo propertyInfo) public PropertyInfo PropertyInfo { get; } /// - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - var value = this.PropertyInfo.GetValue(null); + var value = PropertyInfo.GetValue(null); - if (value is not IEnumerable enumerable) + if (value is not IEnumerable enumerable) { throw new InvalidCastException("Member does not return an enumerable value."); } diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 9cd283a..9667654 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -4,20 +4,20 @@ namespace AutoFixture.TUnit.Internal; internal class TestParameter(ParameterInfo parameterInfo) { - private readonly Lazy lazyCustomization = new( + private readonly Lazy _lazyCustomization = new( () => GetCustomization(parameterInfo)); - private readonly Lazy lazyFrozenAttribute = new( + private readonly Lazy _lazyFrozenAttribute = new( () => parameterInfo.GetCustomAttributes() .OfType().FirstOrDefault()); public ParameterInfo ParameterInfo { get; } = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); - public ICustomization GetCustomization() => this.lazyCustomization.Value; + public ICustomization GetCustomization() => _lazyCustomization.Value; - public ICustomization GetCustomization(object value) + public ICustomization GetCustomization(object? value) { - var frozenAttribute = this.lazyFrozenAttribute.Value; + var frozenAttribute = _lazyFrozenAttribute.Value; if (frozenAttribute is null) { @@ -25,7 +25,7 @@ public ICustomization GetCustomization(object value) } return new FrozenValueCustomization( - new ParameterFilter(this.ParameterInfo, frozenAttribute.By), + new ParameterFilter(ParameterInfo, frozenAttribute.By), value); } diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs index e29c318..32a5b82 100644 --- a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -10,7 +10,7 @@ namespace AutoFixture.TUnit; /// 1. A static property /// 2. A static field /// 3. A static method (with parameters) -/// The member must return something compatible with IEnumerable<object[]> with the test data. +/// The member must return something compatible with IEnumerable<object?[]> with the test data. /// [CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", @@ -22,7 +22,7 @@ public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute /// /// The name of the public static member on the test class that will provide the test data. /// The parameters for the member (only supported for methods; ignored for everything else). - public MemberAutoDataAttribute(string memberName, params object[] parameters) + public MemberAutoDataAttribute(string memberName, params object?[] parameters) : this(() => new Fixture(), memberType: null, memberName, parameters) { } @@ -33,7 +33,7 @@ public MemberAutoDataAttribute(string memberName, params object[] parameters) /// The type declaring the source member. /// The name of the public static member on the test class that will provide the test data. /// The parameters for the member (only supported for methods; ignored for everything else). - public MemberAutoDataAttribute(Type? memberType, string memberName, params object[] parameters) + public MemberAutoDataAttribute(Type? memberType, string memberName, params object?[] parameters) : this(() => new Fixture(), memberType, memberName, parameters) { } @@ -44,7 +44,7 @@ public MemberAutoDataAttribute(Type? memberType, string memberName, params objec /// The fixture factory delegate. /// The name of the public static member on the test class that will provide the test data. /// The parameters for the member (only supported for methods; ignored for everything else). - protected MemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) + protected MemberAutoDataAttribute(Func fixtureFactory, string memberName, params object?[] parameters) : this(fixtureFactory, memberType: null, memberName, parameters) { } @@ -57,12 +57,12 @@ protected MemberAutoDataAttribute(Func fixtureFactory, string memberNa /// The name of the public static member on the test class that will provide the test data. /// The parameters for the member (only supported for methods; ignored for everything else). /// Thrown when arguments are null. - protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object[]? parameters) + protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberType, string memberName, params object?[]? parameters) { - this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); - this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); - this.Parameters = parameters ?? new object[] { null! }; - this.MemberType = memberType; + FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); + MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName)); + Parameters = parameters ?? [null!]; + MemberType = memberType; } /// @@ -83,7 +83,7 @@ protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberTyp /// /// Gets the parameters passed to the member. Only supported for static methods. /// - public object[] Parameters { get; } + public object?[] Parameters { get; } /// public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) @@ -92,15 +92,15 @@ protected MemberAutoDataAttribute(Func fixtureFactory, Type? memberTyp if (testMethod is null) { - throw new ArgumentNullException(nameof(testMethod)); + throw new ArgumentNullException(nameof(dataGeneratorMetadata), "The test method cannot be null."); } - var sourceType = this.MemberType ?? testMethod.DeclaringType + var sourceType = MemberType ?? testMethod.DeclaringType ?? throw new InvalidOperationException("Source type cannot be null."); var source = new AutoDataSource( - createFixture: this.FixtureFactory, - source: new MemberDataSource(sourceType, this.MemberName, this.Parameters)); + createFixture: FixtureFactory, + source: new MemberDataSource(sourceType, MemberName, Parameters)); return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); } diff --git a/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs index e381ea2..fe454f5 100644 --- a/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ArgumentsAutoDataAttributeTests.cs @@ -116,7 +116,7 @@ public async Task GetDataOrdersCustomizationAttributes(string methodName) [MethodDataSource(typeof(InlinePrimitiveValuesTestData), nameof(InlinePrimitiveValuesTestData.GetData))] [MethodDataSource(typeof(InlineFrozenValuesTestData), nameof(InlineFrozenValuesTestData.GetData))] public async Task ReturnsSingleTestDataWithExpectedValues(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, - object[] expected) + object?[] expected) { // Act var actual = attribute.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(testMethod.DeclaringType, testMethod.Name)).ToArray(); diff --git a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs index c9ca72c..58c5eb8 100644 --- a/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs +++ b/tests/AutoFixture.TUnit.Tests/ClassAutoDataAttributeTests.cs @@ -233,7 +233,7 @@ public async Task GetDataReturnsExpectedTestData() () => new DelegatingFixture { OnCreate = (r, c) => builder.Create(r, c) }, typeof(MixedTypeClassData)); var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); - object[][] expected = + object?[][] expected = [ [1, "value", EnumType.First, new Tuple("value", 1)], [9, "value", EnumType.First, new Tuple("value", 1)], @@ -261,7 +261,7 @@ public async Task GetDataReturnsExpectedTestDataFromParameterizedSource() typeof(ParameterizedClassData), 29, "myValue", EnumType.Third); var testMethod = typeof(ExampleTestClass).GetMethod(nameof(ExampleTestClass.TestMethod)); - object[][] expected = + object?[][] expected = [ [29, "myValue", EnumType.Third, new Tuple("value", 1)], [29, "myValue", EnumType.Third, new Tuple("value", 1)] @@ -283,9 +283,9 @@ public async Task TestWithNullParametersPasses() .GetMethod(nameof(ExampleTestClass>.TestMethod)); var expected = new[] { - new object[] { null!, null!, null!, null! }, - new object[] { string.Empty, null!, null!, null! }, - new object[] { null!, " ", null!, null! }, + new object?[] { null!, null!, null!, null! }, + new object?[] { string.Empty, null!, null!, null! }, + new object?[] { null!, " ", null!, null! }, }; // Act @@ -297,9 +297,9 @@ public async Task TestWithNullParametersPasses() await Assert.That(actual).IsEquivalentTo(expected); } - public class TestDataWithNullValues : IEnumerable + public class TestDataWithNullValues : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return [null!, null!, null!, null!]; yield return [string.Empty, null!, null!, null!]; @@ -308,7 +308,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs index 6ec2a20..2bd16f3 100644 --- a/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs +++ b/tests/AutoFixture.TUnit.Tests/CompositeDataAttributeSufficientDataTest.cs @@ -7,34 +7,34 @@ namespace AutoFixture.TUnit.Tests; public class CompositeDataAttributeSufficientDataTest { - private readonly MethodInfo method = typeof(TypeWithOverloadedMembers) + private readonly MethodInfo _method = typeof(TypeWithOverloadedMembers) .GetMethod(nameof(TypeWithOverloadedMembers.DoSomething), [typeof(object), typeof(object), typeof(object)]); [Test] [MethodDataSource(typeof(CompositeDataAttributeSufficientDataTest), nameof(GetEnumerator))] public async Task GetDataReturnsCorrectResult(IEnumerable attributes, - IEnumerable expectedResult) + IEnumerable expectedResult) { // Arrange var attribute = new CompositeDataAttribute(attributes.ToArray()); // Act - var result = attribute.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(this.method)) + var result = attribute.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(_method)) .Select(x => x()) .ToArray(); // Assert - await Assert.That(result).IsEquivalentTo(expectedResult, new CollectionEquivalentToEqualityComparer()); + await Assert.That(result).IsEquivalentTo(expectedResult, new CollectionEquivalentToEqualityComparer()); } public IEnumerable<(IEnumerable Attributes, - IEnumerable ExpectedResult)> GetEnumerator() + IEnumerable ExpectedResult)> GetEnumerator() { yield return CreateTestData( data: [ - new FakeDataAttribute(this.method, [[1, 2, 3]]) + new FakeDataAttribute(_method, [[1, 2, 3]]) ], expected: [ @@ -44,8 +44,8 @@ public async Task GetDataReturnsCorrectResult(IEnumerable attributes, - IEnumerable expectedResult) CreateTestData(AutoFixtureDataSourceAttribute[] data, object[][] expected) + IEnumerable expectedResult) CreateTestData(AutoFixtureDataSourceAttribute[] data, object?[][] expected) { return (data, expected); } - private sealed class TheoryComparer : IEqualityComparer + private sealed class TheoryComparer : IEqualityComparer { - public bool Equals(object[] x, object[] y) + public bool Equals(object?[] x, object?[] y) { return x!.SequenceEqual(y!); } - public int GetHashCode(object[] array) + public int GetHashCode(object?[] array) { return array.Select(obj => obj.GetHashCode()).Aggregate((x, y) => x ^ y); } diff --git a/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs index 2fe4723..b6b076d 100644 --- a/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs +++ b/tests/AutoFixture.TUnit.Tests/DependencyConstraintsTests.cs @@ -39,7 +39,7 @@ public async Task AutoFixtureXunit3UnitTestsDoNotReference(string assemblyName) { // Arrange // Act - var references = this.GetType().GetTypeInfo().Assembly.GetReferencedAssemblies(); + var references = GetType().GetTypeInfo().Assembly.GetReferencedAssemblies(); // Assert await Assert.That(references).DoesNotContain(an => an.Name == assemblyName); } diff --git a/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs index c479105..53df50b 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/AutoDataSourceTests.cs @@ -89,9 +89,9 @@ public async Task CombinesTestDataFromSourceWithAutoGeneratedValues() // Assert await Assert.That(result).IsNotNull(); await Assert.That(result.Length).IsEqualTo(3); - await Assert.That(result[0]).IsEquivalentTo(new object[] { "a", 15, 13.3 }); - await Assert.That(result[1]).IsEquivalentTo(new object[] { "b", 123, 13.3 }); - await Assert.That(result[2]).IsEquivalentTo(new object[] { "c", 999, 13.3 }); + await Assert.That(result[0]).IsEquivalentTo(new object?[] { "a", 15, 13.3 }); + await Assert.That(result[1]).IsEquivalentTo(new object?[] { "b", 123, 13.3 }); + await Assert.That(result[2]).IsEquivalentTo(new object?[] { "c", 999, 13.3 }); } [Test] @@ -121,9 +121,9 @@ public async Task DoesNotGenerateValuesWhenAllValuesProvidedBySource() // Assert await Assert.That(result).IsNotNull(); await Assert.That(result.Length).IsEqualTo(3); - await Assert.That(result[0]).IsEquivalentTo(new object[] { "a", 85, 913.12 }); - await Assert.That(result[1]).IsEquivalentTo(new object[] { "b", 519, 73.1 }); - await Assert.That(result[2]).IsEquivalentTo(new object[] { "c", 411, 529.6 }); + await Assert.That(result[0]).IsEquivalentTo(new object?[] { "a", 85, 913.12 }); + await Assert.That(result[1]).IsEquivalentTo(new object?[] { "b", 519, 73.1 }); + await Assert.That(result[2]).IsEquivalentTo(new object?[] { "c", 411, 529.6 }); } [Test] @@ -132,7 +132,7 @@ public async Task ReturnsNoTestDataWhenSourceReturnsNoTestData() // Arrange var source = new DelegatingDataSource { - TestData = Array.Empty(), + TestData = Array.Empty(), }; var fixture = new DelegatingFixture(); var sut = new AutoDataSource(() => fixture, source); diff --git a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs index 5d9a363..dc2d875 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/ClassDataSourceTests.cs @@ -78,9 +78,9 @@ public async Task GeneratesTestDatWithPrimitiveValues() // Arrange var expected = new[] { - new object[] { "hello", 1, new RecordType("world") }, - new object[] { "foo", 2, new RecordType("bar") }, - new object[] { "Han", 3, new RecordType("Solo") } + new object?[] { "hello", 1, new RecordType("world") }, + new object?[] { "foo", 2, new RecordType("bar") }, + new object?[] { "Han", 3, new RecordType("Solo") } }; var sut = new ClassDataSource(typeof(TestSourceWithMixedValues)); var method = typeof(SampleTestType) @@ -95,23 +95,23 @@ public async Task GeneratesTestDatWithPrimitiveValues() await Assert.That(actual).IsEquivalentTo(expected); } - private class TestSourceWithMixedValues : IEnumerable + private class TestSourceWithMixedValues : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return ["hello", 1, new RecordType("world")]; yield return ["foo", 2, new RecordType("bar")]; yield return ["Han", 3, new RecordType("Solo")]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } [Test] public async Task ThrowsWhenConstructorParametersDontMatch() { // Arrange - var parameters = new object[] { "a", 1 }; + var parameters = new object?[] { "a", 1 }; var sut = new ClassDataSource(typeof(TestSourceWithMixedValues), parameters); var method = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); @@ -124,7 +124,7 @@ public async Task ThrowsWhenConstructorParametersDontMatch() public async Task AppliesExpectedConstructorParameters() { // Arrange - object[] parameters = [new object[] { "y", 25 }]; + object?[] parameters = [new object?[] { "y", 25 }]; var sut = new ClassDataSource(typeof(DelegatingTestData), parameters); var method = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithReferenceTypeParameter)); @@ -133,6 +133,6 @@ public async Task AppliesExpectedConstructorParameters() var result = sut.GenerateDataSources(DataGeneratorMetadataHelper.CreateDataGeneratorMetadata(method)).ToArray(); // Assert - await Assert.That(result.Single()).IsEquivalentTo(new object[] { "y", 25 }); + await Assert.That(result.Single()).IsEquivalentTo(new object?[] { "y", 25 }); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs index 25d8684..ee97832 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/DataSourceTests.cs @@ -71,11 +71,11 @@ public async Task ReturnsArgumentsFittingTestParameters() // Arrange var testData = new[] { - new object[] { "hello", 16, 32.86d }, - new object[] { null!, -1, -20.22 }, - new object[] { "one", 2 }, - new object[] { null! }, - new object[] { }, + new object?[] { "hello", 16, 32.86d }, + new object?[] { null!, -1, -20.22 }, + new object?[] { "one", 2 }, + new object?[] { null! }, + new object?[] { }, }; var sut = new DelegatingDataSource { TestData = testData }; var testMethod = typeof(SampleTestType) @@ -100,7 +100,7 @@ await Assert.That(actual) public async Task ThrowsWhenTestDataContainsMoreArgumentsThanParameters() { // Arrange - var testData = new[] { new object[] { "hello", 16, 32.86d, "extra" } }; + var testData = new[] { new object?[] { "hello", 16, 32.86d, "extra" } }; var sut = new DelegatingDataSource { TestData = testData }; var testMethod = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); diff --git a/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs index 2c0f953..214a0b5 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/FieldDataSourceTests.cs @@ -7,7 +7,7 @@ namespace AutoFixture.TUnit.Tests.Internal; public class FieldDataSourceTests { - public static IEnumerable TestDataFieldWithMixedValues = + public static IEnumerable TestDataFieldWithMixedValues = [ ["hello", 1, new FieldHolder { Field = "world" }], ["foo", 2, new FieldHolder { Field = "bar" }], @@ -82,9 +82,9 @@ public async Task GeneratesTestDataMatchingTestParameters() // Arrange var expected = new[] { - new object[] { "hello", 1, new RecordType("world") }, - new object[] { "foo", 2, new RecordType("bar") }, - new object[] { "Han", 3, new RecordType("Solo") } + new object?[] { "hello", 1, new RecordType("world") }, + new object?[] { "foo", 2, new RecordType("bar") }, + new object?[] { "Han", 3, new RecordType("Solo") } }; var sourceField = typeof(FieldDataSourceTests) .GetField(nameof(TestDataFieldWithRecordValues)); @@ -101,7 +101,7 @@ public async Task GeneratesTestDataMatchingTestParameters() await Assert.That(result).IsEquivalentTo(expected); } - public static IEnumerable TestDataFieldWithRecordValues = + public static IEnumerable TestDataFieldWithRecordValues = [ ["hello", 1, new RecordType("world")], ["foo", 2, new RecordType("bar")], diff --git a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs index 4fe249c..47ce3a0 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/InlineDataSourceTests.cs @@ -11,7 +11,8 @@ public async Task SutIsTestDataSource() { // Arrange // Act - var sut = new InlineDataSource(Array.Empty()); + var sut = new InlineDataSource([ + ]); // Assert await Assert.That(sut).IsAssignableTo(); } @@ -41,7 +42,8 @@ public async Task ValuesIsCorrect() public async Task GetTestDataWithNullMethodThrows() { // Arrange - var sut = new InlineDataSource(Array.Empty()); + var sut = new InlineDataSource([ + ]); // Act & Assert await Assert.That(() => sut.GenerateDataSources(null!)).ThrowsExactly(); @@ -51,7 +53,7 @@ await Assert.That(() => public async Task SourceThrowsWhenArgumentCountExceedParameterCount() { // Arrange - var values = new object[] { "aloha", 42, 12.3d, "extra" }; + var values = new object?[] { "aloha", 42, 12.3d, "extra" }; var sut = new InlineDataSource(values); var testMethod = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); @@ -67,7 +69,7 @@ await Assert.That(() => public async Task ReturnsTestDataWhenArgumentCountMatchesParameterCount() { // Arrange - var values = new object[] { "aloha", 42, 12.3d }; + var values = new object?[] { "aloha", 42, 12.3d }; var sut = new InlineDataSource(values); var testMethod = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); @@ -84,7 +86,7 @@ public async Task ReturnsTestDataWhenArgumentCountMatchesParameterCount() public async Task ReturnsAllArgumentsWhenArgumentCountLessThanParameterCount() { // Arrange - var values = new object[] { "aloha", 42 }; + var values = new object?[] { "aloha", 42 }; var sut = new InlineDataSource(values); var testMethod = typeof(SampleTestType) .GetMethod(nameof(SampleTestType.TestMethodWithMultipleParameters)); diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs index 12b389d..0f8c3e6 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/MemberDataSourceTests.cs @@ -9,9 +9,9 @@ public class MemberDataSourceTests public static object NonTestDataField = new(); public static object NonTestDataProperty => new(); public static object NonTestDataMethod() => new(); - public static IEnumerable EmptyTestDataField = Array.Empty(); - public static IEnumerable EmptyTestData => Array.Empty(); - public static IEnumerable GetEmptyTestData() => Array.Empty(); + public static IEnumerable EmptyTestDataField = Array.Empty(); + public static IEnumerable EmptyTestData => Array.Empty(); + public static IEnumerable GetEmptyTestData() => Array.Empty(); [Test] public async Task SutIsTestDataSource() diff --git a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs index 42aceb6..f001d08 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/MethodDataSourceTests.cs @@ -7,7 +7,7 @@ namespace AutoFixture.TUnit.Tests.Internal; public class MethodDataSourceTests { - public static IEnumerable GetTestDataFieldWithMixedValues() + public static IEnumerable GetTestDataFieldWithMixedValues() { yield return ["hello", 1, new RecordType("world")]; yield return ["foo", 2, new RecordType("bar")]; @@ -19,7 +19,7 @@ public async Task SutIsTestDataSource() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); // Act var sut = new MethodDataSource(methodInfo); @@ -41,7 +41,7 @@ public async Task ThrowsWhenArgumentsIsNull() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); // Act & Assert await Assert.That(() => @@ -53,7 +53,7 @@ public async Task ConstructorSetsProperties() { // Arrange var methodInfo = typeof(MethodDataSourceTests) - .GetMethod(nameof(this.SutIsTestDataSource)); + .GetMethod(nameof(SutIsTestDataSource)); var arguments = new[] { new object() }; // Act @@ -70,9 +70,9 @@ public async Task GetTestDataInvokesMethodInfo() // Arrange var expected = new[] { - new object[] { "hello", 1, new RecordType("world") }, - new object[] { "foo", 2, new RecordType("bar") }, - new object[] { "Han", 3, new RecordType("Solo") } + new object?[] { "hello", 1, new RecordType("world") }, + new object?[] { "foo", 2, new RecordType("bar") }, + new object?[] { "Han", 3, new RecordType("Solo") } }; var testDataSource = typeof(MethodDataSourceTests) .GetMethod(nameof(GetTestDataFieldWithMixedValues)); diff --git a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs index a7ae04c..76ba20b 100644 --- a/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs +++ b/tests/AutoFixture.TUnit.Tests/Internal/PropertyDataSourceTests.cs @@ -19,7 +19,7 @@ public async Task SutIsTestDataSource() await Assert.That(sut).IsAssignableTo(); } - public static IEnumerable TestDataPropertyWithMixedValues => + public static IEnumerable TestDataPropertyWithMixedValues => [ ["hello", 1, new PropertyHolder { Property = "world" }], ["foo", 2, new PropertyHolder { Property = "bar" }], @@ -84,9 +84,9 @@ public async Task GeneratesTestDataMatchingTestParameters() // Arrange var expected = new[] { - new object[] { "hello", 1, new RecordType("world") }, - new object[] { "foo", 2, new RecordType("bar") }, - new object[] { "Han", 3, new RecordType("Solo") } + new object?[] { "hello", 1, new RecordType("world") }, + new object?[] { "foo", 2, new RecordType("bar") }, + new object?[] { "Han", 3, new RecordType("Solo") } }; var sourceProperty = typeof(PropertyDataSourceTests) .GetProperty(nameof(TestDataPropertyWithRecordValues)); @@ -103,7 +103,7 @@ public async Task GeneratesTestDataMatchingTestParameters() await Assert.That(result).IsEquivalentTo(expected); } - public static IEnumerable TestDataPropertyWithRecordValues => + public static IEnumerable TestDataPropertyWithRecordValues => [ ["hello", 1, new RecordType("world")], ["foo", 2, new RecordType("bar")], @@ -116,9 +116,9 @@ public async Task ReturnsNullArguments() // Arrange var expected = new[] { - new object[] { null!, 1, null! }, - new object[] { null!, 2, null! }, - new object[] { null!, 3, null! } + new object?[] { null!, 1, null! }, + new object?[] { null!, 2, null! }, + new object?[] { null!, 3, null! } }; var sourceProperty = typeof(PropertyDataSourceTests) .GetProperty(nameof(TestDataPropertyWithNullValues)); @@ -135,7 +135,7 @@ public async Task ReturnsNullArguments() await Assert.That(result).IsEquivalentTo(expected); } - public static IEnumerable TestDataPropertyWithNullValues => + public static IEnumerable TestDataPropertyWithNullValues => [ [null!, 1, null!], [null!, 2, null!], diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs index 7f96fa2..d29e84b 100644 --- a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeScenarioTests.cs @@ -138,21 +138,21 @@ public async Task InjectsComplexTypes( await Assert.That(c).IsSameReferenceAs(a); } - public static IEnumerable GetSingleStringValueTestData() + public static IEnumerable GetSingleStringValueTestData() { yield return ["test-one"]; yield return ["test-two"]; yield return ["test-three"]; } - public static IEnumerable GetMultipleValueTestData() + public static IEnumerable GetMultipleValueTestData() { yield return ["test-one", 22, 25.7m]; yield return ["test-two", 75, 228.1m]; yield return ["test-three", 19, 137.09m]; } - public static IEnumerable GetStringValuesTestData() + public static IEnumerable GetStringValuesTestData() { yield return ["test-one", "test-uno"]; yield return ["test-two", "test-dos"]; diff --git a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs index 940365b..8f201aa 100644 --- a/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs +++ b/tests/AutoFixture.TUnit.Tests/MemberAutoDataAttributeTest.cs @@ -27,7 +27,7 @@ public async Task InitializedWithMemberNameAndParameters() { // Arrange var memberName = Guid.NewGuid().ToString(); - var parameters = new object[] { "value-one", 3, 12.2f }; + var parameters = new object?[] { "value-one", 3, 12.2f }; // Act var sut = new MemberAutoDataAttribute(memberName, parameters); @@ -44,7 +44,7 @@ public async Task InitializedWithTypeMemberNameAndParameters() { // Arrange var memberName = Guid.NewGuid().ToString(); - var parameters = new object[] { "value-one", 3, 12.2f }; + var parameters = new object?[] { "value-one", 3, 12.2f }; var testType = typeof(MemberAutoDataAttributeTest); // Act @@ -212,9 +212,9 @@ public async Task GeneratesTestsFromParameterlessMethod() var testMethod = TestTypeWithMethodData.GetSingleStringValueTestMethodInfo(); var expected = new[] { - new object[] { "value-one" }, - new object[] { "value-two" }, - new object[] { "value-three" } + new object?[] { "value-one" }, + new object?[] { "value-two" }, + new object?[] { "value-three" } }; // Act @@ -235,9 +235,9 @@ public async Task GeneratesTestsFromMethodWithParameter() var testMethod = TestTypeWithMethodData.GetStringTestsFromArgumentMethodInfo(); var expected = new[] { - new object[] { "value-one" }, - new object[] { "value-two" }, - new object[] { "value-three" } + new object?[] { "value-one" }, + new object?[] { "value-two" }, + new object?[] { "value-three" } }; // Act @@ -257,9 +257,9 @@ public async Task GeneratesTestDataForTestsWithMultipleParameters() var testMethod = TestTypeWithMethodData.GetMultipleValueTestMethodInfo(); var expected = new[] { - new object[] { "value-one", 12, 23.3m }, - new object[] { "value-two", 38, 12.7m }, - new object[] { "value-three", 94, 52.21m } + new object?[] { "value-one", 12, 23.3m }, + new object?[] { "value-two", 38, 12.7m }, + new object?[] { "value-three", 94, 52.21m } }; // Act @@ -314,9 +314,9 @@ public async Task GeneratesTestDataWithInjectedParameters() var testMethod = TestTypeWithMethodData.GetTestWithFrozenParameter(); var expected = new[] { - new object[] { "value-one", "value-two", "value-two" }, - new object[] { "value-two", "value-three", "value-three" }, - new object[] { "value-three", "value-one", "value-one" } + new object?[] { "value-one", "value-two", "value-two" }, + new object?[] { "value-two", "value-three", "value-three" }, + new object?[] { "value-three", "value-one", "value-one" } }; // Act @@ -371,9 +371,9 @@ public async Task SupportsInheritedTestDataMembers() var testMethod = ChildTestTypeMethodData.GetMultipleValueTestMethodInfo(); var expected = new[] { - new object[] { "value-one", 12, 23.3m }, - new object[] { "value-two", 38, 12.7m }, - new object[] { "value-three", 94, 52.21m } + new object?[] { "value-one", 12, 23.3m }, + new object?[] { "value-two", 38, 12.7m }, + new object?[] { "value-three", 94, 52.21m } }; // Act @@ -385,7 +385,7 @@ public async Task SupportsInheritedTestDataMembers() await Assert.That(testData).IsEquivalentTo(expected); } - public static IEnumerable TestDataWithNullValues + public static IEnumerable TestDataWithNullValues { get { diff --git a/tests/AutoFixture.TUnit.Tests/Scenario.cs b/tests/AutoFixture.TUnit.Tests/Scenario.cs index 59111f0..59b3181 100644 --- a/tests/AutoFixture.TUnit.Tests/Scenario.cs +++ b/tests/AutoFixture.TUnit.Tests/Scenario.cs @@ -82,7 +82,7 @@ public async Task CustomInlineDataSuppliesExtraValues(int x, int y, int z) await Assert.That(z).IsEqualTo(42); } - public class MyCustomArgumentsAutoDataAttribute(params object[] values) + public class MyCustomArgumentsAutoDataAttribute(params object?[] values) : ArgumentsAutoDataAttribute(() => new Fixture().Customize(new TheAnswer()), values); [Test, MemberAutoData(nameof(StringData))] @@ -133,7 +133,7 @@ public async Task CustomMemberAutoDataCanBeParametrized(int x, int y, int z) await Assert.That(z).IsEqualTo(43); } - public static IEnumerable StringData + public static IEnumerable StringData { get { @@ -142,7 +142,7 @@ public static IEnumerable StringData } } - public static IEnumerable IntData + public static IEnumerable IntData { get { @@ -152,12 +152,12 @@ public static IEnumerable IntData } } - public static IEnumerable GetParametrizedData(int x, int y, int z) + public static IEnumerable GetParametrizedData(int x, int y, int z) { yield return [x, y, z]; } - public class MyCustomMemberAutoDataAttribute(string memberName, params object[] parameters) + public class MyCustomMemberAutoDataAttribute(string memberName, params object?[] parameters) : MemberAutoDataAttribute(() => new Fixture().Customize(new TheAnswer()), memberName, parameters); private class TheAnswer : ICustomization @@ -497,43 +497,43 @@ public async Task ClassAutoDataSuppliesDataOfMixedTypes(int p1, string p2, Prope [Test, ClassAutoData(typeof(ParameterizedDataClass), 28, "bar", 93.102)] public async Task ClassAutoDataCanBeParameterized(int p1, string p2, double p3, RecordType p4) { - var actual = new object[] { p1, p2, p3 }; - var expected = new object[] { 28, "bar", 93.102 }; + var actual = new object?[] { p1, p2, p3 }; + var expected = new object?[] { 28, "bar", 93.102 }; await Assert.That(actual).IsEquivalentTo(expected); await Assert.That(p4).IsNotNull(); } - public class StringDataClass : IEnumerable + public class StringDataClass : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return ["foo", "bar", "foobar"]; yield return ["dim", "sum", "dimsum"]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - public class MixedDataClass : IEnumerable + public class MixedDataClass : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return [1]; yield return [4, "testValue"]; yield return [20, "otherValue", new PropertyHolder { Property = "testValue1" }]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - public class ParameterizedDataClass(int p1, string p2, double p3) : IEnumerable + public class ParameterizedDataClass(int p1, string p2, double p3) : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs index 276aca2..56af2ae 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithEmptyTestData.cs @@ -2,14 +2,14 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class ClassWithEmptyTestData : IEnumerable +public class ClassWithEmptyTestData : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return []; yield return []; yield return []; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs index e95410f..503ad89 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ClassWithNullTestData.cs @@ -2,14 +2,14 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class ClassWithNullTestData : IEnumerable +public class ClassWithNullTestData : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return null!; yield return null!; yield return null!; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs index d297a7c..ed47d20 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomization.cs @@ -4,12 +4,12 @@ internal class DelegatingCustomization : ICustomization { internal DelegatingCustomization() { - this.OnCustomize = _ => { }; + OnCustomize = _ => { }; } public void Customize(IFixture fixture) { - this.OnCustomize(fixture); + OnCustomize(fixture); } internal Action OnCustomize { get; set; } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs index b04bd83..aedfc51 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingCustomizeAttribute.cs @@ -6,7 +6,7 @@ internal class DelegatingCustomizeAttribute : CustomizeAttribute { public override ICustomization GetCustomization(ParameterInfo parameter) { - return this.OnGetCustomization(parameter); + return OnGetCustomization(parameter); } public Func OnGetCustomization { get; set; } = p => new DelegatingCustomization(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs index 136c159..0deca77 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingDataSource.cs @@ -4,10 +4,10 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class DelegatingDataSource : AutoFixtureDataSourceAttribute, IDataSource { - public IEnumerable TestData { get; set; } = Array.Empty(); + public IEnumerable TestData { get; set; } = Array.Empty(); - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { - return this.TestData; + return TestData; } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs index a77d9e1..edddd31 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingFixture.cs @@ -5,18 +5,22 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class DelegatingFixture : IFixture { - private readonly List customizations = new(); - private readonly List residueCollectors = new(); + private readonly List _customizations = + [ + ]; + private readonly List _residueCollectors = + [ + ]; public IList Behaviors => throw new InvalidOperationException(); - public IList Customizations => this.customizations; + public IList Customizations => _customizations; public bool OmitAutoProperties { get; set; } public int RepeatCount { get; set; } - public IList ResidueCollectors => this.residueCollectors; + public IList ResidueCollectors => _residueCollectors; public void AddManyTo(ICollection collection, Func creator) { @@ -40,7 +44,7 @@ public ICustomizationComposer Build() public IFixture Customize(ICustomization customization) { - this.OnCustomize?.Invoke(customization); + OnCustomize?.Invoke(customization); return this; } @@ -81,7 +85,7 @@ public void Register(Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs index ccb5dab..dffe7f4 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingMemberDataSource.cs @@ -2,8 +2,8 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class DelegatingMemberDataSource(Type type, string name, params object[] arguments) +public class DelegatingMemberDataSource(Type type, string name, params object?[] arguments) : MemberDataSource(type, name, arguments) { - public DataSource GetSource() => this.Source; + public DataSource GetSource() => Source; } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs index c5d6e79..752af7d 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingSpecimenBuilder.cs @@ -6,7 +6,7 @@ internal class DelegatingSpecimenBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { - return this.OnCreate(request, context); + return OnCreate(request, context); } internal Func OnCreate { get; set; } = (_, _) => new object(); diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs index b8d688b..f3d4f99 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DelegatingTestData.cs @@ -2,21 +2,21 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class DelegatingTestData : IEnumerable +public class DelegatingTestData : IEnumerable { - private readonly List data; + private readonly List _data; - public DelegatingTestData(params object[][] data) + public DelegatingTestData(params object?[][] data) { - this.data = data.ToList(); + this._data = data.ToList(); } - public DelegatingTestData(IEnumerable data) + public DelegatingTestData(IEnumerable data) { - this.data = data as List ?? data.ToList(); + this._data = data as List ?? data.ToList(); } - public IEnumerator GetEnumerator() => this.data.GetEnumerator(); + public IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs index 07c6018..455976d 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedArgumentsAutoDataAttribute.cs @@ -1,4 +1,4 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -internal class DerivedArgumentsAutoDataAttribute(Func fixtureFactory, params object[] values) +internal class DerivedArgumentsAutoDataAttribute(Func fixtureFactory, params object?[] values) : ArgumentsAutoDataAttribute(fixtureFactory, values); \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs index 4eadeb0..98a1ce3 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedClassAutoDataAttribute.cs @@ -7,7 +7,7 @@ public DerivedClassAutoDataAttribute(Type sourceType) { } - public DerivedClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object[] parameters) + public DerivedClassAutoDataAttribute(Func fixtureFactory, Type sourceType, params object?[] parameters) : base(fixtureFactory, sourceType, parameters) { } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs index 4a91a3a..3d54985 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/DerivedMemberAutoDataAttribute.cs @@ -2,12 +2,12 @@ public class DerivedMemberAutoDataAttribute : MemberAutoDataAttribute { - public DerivedMemberAutoDataAttribute(Func fixtureFactory, string memberName, params object[] parameters) + public DerivedMemberAutoDataAttribute(Func fixtureFactory, string memberName, params object?[] parameters) : base(fixtureFactory, memberName, parameters) { } - public DerivedMemberAutoDataAttribute(Func fixtureFactory, Type memberType, string memberName, params object[] parameters) + public DerivedMemberAutoDataAttribute(Func fixtureFactory, Type memberType, string memberName, params object?[] parameters) : base(fixtureFactory, memberType, memberName, parameters) { } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs index b9a8f61..726cd51 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/EmptyClassData.cs @@ -2,12 +2,12 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class EmptyClassData : IEnumerable +public class EmptyClassData : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield break; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs index 3d604b8..63e7e60 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/FakeDataAttribute.cs @@ -2,11 +2,11 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) : AutoFixtureDataSourceAttribute +public class FakeDataAttribute(MethodInfo expectedMethod, IEnumerable output) : AutoFixtureDataSourceAttribute { - private readonly MethodInfo expectedMethod = expectedMethod; + private readonly MethodInfo _expectedMethod = expectedMethod; - public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) + public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { return output; } diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs index 3f0a4f1..d2842e8 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineAttributeTestData.cs @@ -6,7 +6,7 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal abstract class InlineAttributeTestData { protected static DerivedArgumentsAutoDataAttribute CreateAttributeWithFakeFixture( - object[] inlineValues, + object?[] inlineValues, params (string ParameterName, object Value)[] parameters) { return new DerivedArgumentsAutoDataAttribute( @@ -27,7 +27,7 @@ object OnCreateParameter(object request, ISpecimenContext context) } protected static DerivedArgumentsAutoDataAttribute CreateAttribute( - object[] inlineValues, + object?[] inlineValues, params (string ParameterName, object Value)[] parameters) { return new DerivedArgumentsAutoDataAttribute( diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs index 8a92b3d..a975c1e 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlineFrozenValuesTestData.cs @@ -3,10 +3,10 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class InlineFrozenValuesTestData : InlineAttributeTestData<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, - object[] expected)> + object?[] expected)> { public override IEnumerable<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, - object[] expected)> GetData() + object?[] expected)> GetData() { // All values provided by fixture yield return diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs index 2c56f77..e4f306e 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/InlinePrimitiveValuesTestData.cs @@ -3,10 +3,10 @@ namespace AutoFixture.TUnit.Tests.TestTypes; internal class InlinePrimitiveValuesTestData : InlineAttributeTestData<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, - object[] expected)> + object?[] expected)> { public override IEnumerable<(AutoFixtureDataSourceAttribute attribute, MethodInfo testMethod, - object[] expected)> GetData() + object?[] expected)> GetData() { // All values provided by fixture yield return diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs index e6b2243..7e6a0bc 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/MixedTypeClassData.cs @@ -3,9 +3,9 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class MixedTypeClassData : IEnumerable +public class MixedTypeClassData : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return []; yield return [9]; @@ -14,5 +14,5 @@ public IEnumerator GetEnumerator() yield return [-95, "test-92", EnumType.Second, new Tuple("myValue", 5)]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs index d28d3db..0a53403 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterNameCriterion.cs @@ -17,6 +17,6 @@ public ParameterNameCriterion(string name) public bool Equals(ParameterInfo other) { - return this.NameCriterion.Equals(other.Name); + return NameCriterion.Equals(other.Name); } } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs index f5965a4..b3aa6dd 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/ParameterizedClassData.cs @@ -3,13 +3,13 @@ namespace AutoFixture.TUnit.Tests.TestTypes; -public class ParameterizedClassData(int p1, string p2, EnumType p3) : IEnumerable +public class ParameterizedClassData(int p1, string p2, EnumType p3) : IEnumerable { - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { yield return [p1, p2, p3]; yield return [p1, p2, p3]; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } \ No newline at end of file diff --git a/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs index 5d56037..9d11ce1 100644 --- a/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs +++ b/tests/AutoFixture.TUnit.Tests/TestTypes/TestTypeWithMethodData.cs @@ -5,7 +5,7 @@ namespace AutoFixture.TUnit.Tests.TestTypes; public class TestTypeWithMethodData { - public IEnumerable NonStaticSource() + public IEnumerable NonStaticSource() { yield return [new object()]; yield return [new object()]; @@ -29,7 +29,7 @@ public static MethodInfo GetNonEnumerableMethodInfo() .GetMethod(nameof(NonEnumerableMethod)); } - public static IEnumerable TestDataWithNoValues() + public static IEnumerable TestDataWithNoValues() { yield return []; yield return []; @@ -49,14 +49,14 @@ public static MethodInfo GetSingleStringValueTestMethodInfo() .GetMethod(nameof(SingleStringValueTest)); } - public static IEnumerable GetSingleStringValueTestData() + public static IEnumerable GetSingleStringValueTestData() { yield return ["value-one"]; yield return ["value-two"]; yield return ["value-three"]; } - public static IEnumerable GetStringTestsFromArgument(string argument) + public static IEnumerable GetStringTestsFromArgument(string argument) { yield return [argument + "-one"]; yield return [argument + "-two"]; @@ -85,7 +85,7 @@ public static MethodInfo GetMultipleValueTestMethodInfo() .GetMethod(nameof(MultipleValueTest)); } - public static IEnumerable GetMultipleValueTestData() + public static IEnumerable GetMultipleValueTestData() { yield return ["value-one", 12, 23.3m]; yield return ["value-two", 38, 12.7m]; @@ -102,7 +102,7 @@ public async Task TestWithFrozenParameter(string a, [Frozen] string b, string c) await Assert.That(c).IsEqualTo(b); } - public static IEnumerable GetDataForTestWithFrozenParameter() + public static IEnumerable GetDataForTestWithFrozenParameter() { yield return ["value-one", "value-two"]; yield return ["value-two", "value-three"]; @@ -123,7 +123,7 @@ public async Task TestWithComplexTypes([Frozen] PropertyHolder a, Proper await Assert.That(b).IsSameReferenceAs(a); } - public static IEnumerable GetTestWithComplexTypesData() + public static IEnumerable GetTestWithComplexTypesData() { yield return [ @@ -148,12 +148,12 @@ public static MethodInfo GetTestWithComplexTypes() .GetMethod(nameof(TestWithComplexTypes)); } - public static IEnumerable GetStringValuesTestData() + public static IEnumerable GetStringValuesTestData() { yield return ["test-one", "test-uno"]; yield return ["test-two", "test-dos"]; yield return ["test-three", "test-tres"]; } - public static IEnumerable GetEmptyTestData() => []; + public static IEnumerable GetEmptyTestData() => []; } \ No newline at end of file diff --git a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs index 6f403a2..aab8b8a 100644 --- a/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs +++ b/tests/TestTypeFoundation/AbstractTypeWithNonDefaultConstructor.cs @@ -9,7 +9,7 @@ protected AbstractTypeWithNonDefaultConstructor(T value) throw new ArgumentNullException(nameof(value)); } - this.Property = value; + Property = value; } public T Property { get; } diff --git a/tests/TestTypeFoundation/CompositeType.cs b/tests/TestTypeFoundation/CompositeType.cs index 55d6cb5..847c05d 100644 --- a/tests/TestTypeFoundation/CompositeType.cs +++ b/tests/TestTypeFoundation/CompositeType.cs @@ -14,7 +14,7 @@ public CompositeType(params AbstractType[] types) throw new ArgumentNullException(nameof(types)); } - this.Types = types; + Types = types; } public IEnumerable Types { get; } diff --git a/tests/TestTypeFoundation/ConcreteType.cs b/tests/TestTypeFoundation/ConcreteType.cs index 5748a47..02d5ee6 100644 --- a/tests/TestTypeFoundation/ConcreteType.cs +++ b/tests/TestTypeFoundation/ConcreteType.cs @@ -8,28 +8,28 @@ public ConcreteType() public ConcreteType(object obj) { - this.Property1 = obj; + Property1 = obj; } public ConcreteType(object obj1, object obj2) { - this.Property1 = obj1; - this.Property2 = obj2; + Property1 = obj1; + Property2 = obj2; } public ConcreteType(object obj1, object obj2, object obj3) { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; + Property1 = obj1; + Property2 = obj2; + Property3 = obj3; } public ConcreteType(object obj1, object obj2, object obj3, object obj4) { - this.Property1 = obj1; - this.Property2 = obj2; - this.Property3 = obj3; - this.Property4 = obj4; + Property1 = obj1; + Property2 = obj2; + Property3 = obj3; + Property4 = obj4; } public override object Property4 { get; set; } diff --git a/tests/TestTypeFoundation/GenericType.cs b/tests/TestTypeFoundation/GenericType.cs index 662ddc5..6a64727 100644 --- a/tests/TestTypeFoundation/GenericType.cs +++ b/tests/TestTypeFoundation/GenericType.cs @@ -10,7 +10,7 @@ public GenericType(T t) throw new ArgumentNullException(nameof(t)); } - this.Value = t; + Value = t; } private T Value { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHost.cs b/tests/TestTypeFoundation/GuardedConstructorHost.cs index 2f53c29..d2528c3 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHost.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHost.cs @@ -10,7 +10,7 @@ public GuardedConstructorHost(T item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public T Item { get; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs index df72d37..410bac4 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyField.cs @@ -12,7 +12,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyField(TItem item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public TItem Item { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs index 0ae442e..ae535f7 100644 --- a/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs +++ b/tests/TestTypeFoundation/GuardedConstructorHostHoldingStaticReadOnlyProperty.cs @@ -15,7 +15,7 @@ public GuardedConstructorHostHoldingStaticReadOnlyProperty(TItem item) throw new ArgumentNullException(nameof(item)); } - this.Item = item; + Item = item; } public static TStaticProperty Property { get; private set; } diff --git a/tests/TestTypeFoundation/GuardedPropertyHolder.cs b/tests/TestTypeFoundation/GuardedPropertyHolder.cs index 4a8adc6..c7847d7 100644 --- a/tests/TestTypeFoundation/GuardedPropertyHolder.cs +++ b/tests/TestTypeFoundation/GuardedPropertyHolder.cs @@ -3,13 +3,13 @@ namespace TestTypeFoundation; public class GuardedPropertyHolder where T : class { - private T property; + private T _property; public T Property { get { - return this.property; + return _property; } set @@ -19,7 +19,7 @@ public T Property throw new ArgumentNullException(nameof(value)); } - this.property = value; + _property = value; } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs index 63a9bd2..67a5d4d 100644 --- a/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IllBehavedPropertyHolder.cs @@ -2,7 +2,7 @@ namespace TestTypeFoundation; public class IllBehavedPropertyHolder { - private T propertyIllBehavedSet; + private T _propertyIllBehavedSet; public T PropertyIllBehavedGet { @@ -20,12 +20,12 @@ public T PropertyIllBehavedSet { get { - return this.propertyIllBehavedSet; + return _propertyIllBehavedSet; } set { - this.propertyIllBehavedSet = default(T); + _propertyIllBehavedSet = default(T); } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/IndexedPropertyHolder.cs b/tests/TestTypeFoundation/IndexedPropertyHolder.cs index 406ee71..bcd1452 100644 --- a/tests/TestTypeFoundation/IndexedPropertyHolder.cs +++ b/tests/TestTypeFoundation/IndexedPropertyHolder.cs @@ -2,11 +2,13 @@ public class IndexedPropertyHolder { - private readonly List items = new(); + private readonly List _items = + [ + ]; public T this[int index] { - get { return this.items[index]; } - set { this.items[index] = value; } + get { return _items[index]; } + set { _items[index] = value; } } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/ItemHolder.cs b/tests/TestTypeFoundation/ItemHolder.cs index 102b1f7..0bb6260 100644 --- a/tests/TestTypeFoundation/ItemHolder.cs +++ b/tests/TestTypeFoundation/ItemHolder.cs @@ -7,19 +7,21 @@ public ItemHolder() } public ItemHolder(T1 item) - : this(new[] { item }, new T2[0]) + : this([item], [ + ]) { } public ItemHolder(T2 item) - : this(new T1[0], new[] { item }) + : this([ + ], [item]) { } private ItemHolder(T1[] t1S, T2[] t2S) { - this.Item1S = t1S; - this.Item2S = t2S; + Item1S = t1S; + Item2S = t2S; } public IEnumerable Item1S { get; } @@ -33,12 +35,12 @@ private ItemHolder(T1[] t1S, T2[] t2S) public class ItemHolder { public ItemHolder(T x, T y, T z) - : this(new[] { x, y, z }) + : this([x, y, z]) { } public ItemHolder(T item) - : this(new[] { item }) + : this([item]) { } @@ -47,13 +49,13 @@ public ItemHolder() } public ItemHolder(T x, T y) - : this(new[] { x, y }) + : this([x, y]) { } private ItemHolder(T[] items) { - this.Items = items; + Items = items; } public IEnumerable Items { get; } diff --git a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs index c51e8a2..63ede74 100644 --- a/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs +++ b/tests/TestTypeFoundation/MultiUnorderedConstructorType.cs @@ -19,8 +19,8 @@ public MultiUnorderedConstructorType(string text, int number) throw new ArgumentNullException(nameof(text)); } - this.Text = text; - this.Number = number; + Text = text; + Number = number; } public string Text { get; } @@ -36,8 +36,8 @@ public ParameterObject(string text, int number) throw new ArgumentNullException(nameof(text)); } - this.Text = text; - this.Number = number; + Text = text; + Number = number; } public string Text { get; } diff --git a/tests/TestTypeFoundation/PropertyHolder.cs b/tests/TestTypeFoundation/PropertyHolder.cs index b1e471c..1b3b870 100644 --- a/tests/TestTypeFoundation/PropertyHolder.cs +++ b/tests/TestTypeFoundation/PropertyHolder.cs @@ -8,7 +8,7 @@ public class PropertyHolder public void SetProperty(T value) { - this.Property = value; + Property = value; } public static PropertyInfo GetProperty() diff --git a/tests/TestTypeFoundation/RecordType.cs b/tests/TestTypeFoundation/RecordType.cs index 30794e5..dedd9e7 100644 --- a/tests/TestTypeFoundation/RecordType.cs +++ b/tests/TestTypeFoundation/RecordType.cs @@ -16,16 +16,16 @@ public bool Equals(RecordType? other) return true; } - return EqualityComparer.Default.Equals(this.Value, other.Value); + return EqualityComparer.Default.Equals(Value, other.Value); } public override bool Equals(object? obj) { - return this.Equals(obj as RecordType); + return Equals(obj as RecordType); } public override int GetHashCode() { - return EqualityComparer.Default.GetHashCode(this.Value); + return EqualityComparer.Default.GetHashCode(Value); } } \ No newline at end of file diff --git a/tests/TestTypeFoundation/TypeWithIndexer.cs b/tests/TestTypeFoundation/TypeWithIndexer.cs index e5b7c0f..4d092b6 100644 --- a/tests/TestTypeFoundation/TypeWithIndexer.cs +++ b/tests/TestTypeFoundation/TypeWithIndexer.cs @@ -2,17 +2,17 @@ public class TypeWithIndexer { - private readonly Dictionary dict = new(); + private readonly Dictionary _dict = new(); public string this[string index] { get { - return this.dict[index]; + return _dict[index]; } set { - this.dict[index] = value; + _dict[index] = value; } } } \ No newline at end of file From 3303d9f7d76d55eb8acce13959afb43f29d8f2e0 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:49:11 +0100 Subject: [PATCH 8/9] Tidy --- tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj | 1 + tests/TestTypeFoundation/TestTypeFoundation.csproj | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj b/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj index 9f192d3..38fc7ec 100644 --- a/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj +++ b/tests/AutoFixture.TUnit.Tests/AutoFixture.TUnit.Tests.csproj @@ -18,6 +18,7 @@ + diff --git a/tests/TestTypeFoundation/TestTypeFoundation.csproj b/tests/TestTypeFoundation/TestTypeFoundation.csproj index 94b9aa5..a2b784e 100644 --- a/tests/TestTypeFoundation/TestTypeFoundation.csproj +++ b/tests/TestTypeFoundation/TestTypeFoundation.csproj @@ -7,6 +7,10 @@ TestTypeFoundation TestTypeFoundation + + + + From de35fc7d19684dfb8e1fb88b46be07b88d3b9418 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:50:56 +0100 Subject: [PATCH 9/9] Fixes --- src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs | 1 - src/AutoFixture.TUnit/AutoDataAttribute.cs | 1 - src/AutoFixture.TUnit/ClassAutoDataAttribute.cs | 1 - src/AutoFixture.TUnit/CompositeDataAttribute.cs | 1 - src/AutoFixture.TUnit/Internal/Argument.cs | 2 +- src/AutoFixture.TUnit/Internal/AutoDataSource.cs | 2 +- src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs | 2 +- src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs | 2 +- src/AutoFixture.TUnit/Internal/ParameterFilter.cs | 2 +- src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs | 2 +- src/AutoFixture.TUnit/Internal/TestParameter.cs | 2 +- src/AutoFixture.TUnit/MemberAutoDataAttribute.cs | 1 - 12 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs index 5d5c20e..87be067 100644 --- a/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs @@ -7,7 +7,6 @@ namespace AutoFixture.TUnit; /// Provides a data source for a data theory, with the data coming from inline /// values combined with auto-generated data specimens generated by AutoFixture. /// -[CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "This attribute is the root of a potential attribute hierarchy.")] public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute diff --git a/src/AutoFixture.TUnit/AutoDataAttribute.cs b/src/AutoFixture.TUnit/AutoDataAttribute.cs index 3ef8bb1..f233a2b 100644 --- a/src/AutoFixture.TUnit/AutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/AutoDataAttribute.cs @@ -7,7 +7,6 @@ namespace AutoFixture.TUnit; /// Provides auto-generated data specimens generated by AutoFixture as an extension to /// xUnit.net's Theory attribute. /// -[CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "This attribute is the root of a potential attribute hierarchy.")] public class AutoDataAttribute : AutoFixtureDataSourceAttribute diff --git a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs index eca3ceb..1b837f8 100644 --- a/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/ClassAutoDataAttribute.cs @@ -8,7 +8,6 @@ namespace AutoFixture.TUnit; /// which must implement IEnumerable<object?[]>, /// combined with auto-generated data specimens generated by AutoFixture. /// -[CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "This attribute is the root of a potential attribute hierarchy.")] public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute diff --git a/src/AutoFixture.TUnit/CompositeDataAttribute.cs b/src/AutoFixture.TUnit/CompositeDataAttribute.cs index 641d765..792472f 100644 --- a/src/AutoFixture.TUnit/CompositeDataAttribute.cs +++ b/src/AutoFixture.TUnit/CompositeDataAttribute.cs @@ -6,7 +6,6 @@ namespace AutoFixture.TUnit; /// /// An implementation of DataAttribute that composes other DataAttribute instances. /// -[CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "This attribute is the root of a potential attribute hierarchy.")] public class CompositeDataAttribute : AutoFixtureDataSourceAttribute diff --git a/src/AutoFixture.TUnit/Internal/Argument.cs b/src/AutoFixture.TUnit/Internal/Argument.cs index c194698..22626fa 100644 --- a/src/AutoFixture.TUnit/Internal/Argument.cs +++ b/src/AutoFixture.TUnit/Internal/Argument.cs @@ -1,6 +1,6 @@ namespace AutoFixture.TUnit.Internal; -internal class Argument(TestParameter parameter, object? value) +internal sealed class Argument(TestParameter parameter, object? value) { public TestParameter Parameter { get; } = parameter ?? throw new ArgumentNullException(nameof(parameter)); diff --git a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs index b247860..5714986 100644 --- a/src/AutoFixture.TUnit/Internal/AutoDataSource.cs +++ b/src/AutoFixture.TUnit/Internal/AutoDataSource.cs @@ -34,7 +34,7 @@ public AutoDataSource(Func createFixture, IDataSource? source = defaul /// /// Returns the combined test data provided by the source and auto-generated values. /// - /// The target method for which to provide the arguments. + /// The target method for which to provide the arguments. /// Returns a sequence of argument collections. public override IEnumerable GetData(DataGeneratorMetadata dataGeneratorMetadata) { diff --git a/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs index 42131b9..90f4f6b 100644 --- a/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs +++ b/src/AutoFixture.TUnit/Internal/CustomizeAttributeComparer.cs @@ -1,6 +1,6 @@ namespace AutoFixture.TUnit.Internal; -internal class CustomizeAttributeComparer : Comparer +internal sealed class CustomizeAttributeComparer : Comparer { public override int Compare(IParameterCustomizationSource x, IParameterCustomizationSource y) { diff --git a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs index 7ae8b08..2be3440 100644 --- a/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs +++ b/src/AutoFixture.TUnit/Internal/FrozenValueCustomization.cs @@ -2,7 +2,7 @@ namespace AutoFixture.TUnit.Internal; -internal class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization +internal sealed class FrozenValueCustomization(IRequestSpecification specification, object? value) : ICustomization { private readonly IRequestSpecification _specification = specification ?? throw new ArgumentNullException(nameof(specification)); diff --git a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs index a03d907..79c5576 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterFilter.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterFilter.cs @@ -6,7 +6,7 @@ namespace AutoFixture.TUnit.Internal; /// /// Specification for identifying requests that match the test parameter by provided criteria. /// -internal class ParameterFilter : IRequestSpecification +internal sealed class ParameterFilter : IRequestSpecification { private readonly IRequestSpecification _matcherSpecification; diff --git a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs index 1bb17ad..b83a31e 100644 --- a/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs +++ b/src/AutoFixture.TUnit/Internal/ParameterMatcherBuilder.cs @@ -181,7 +181,7 @@ private IRequestSpecification AsField() new Criterion(_parameterInfo.Name, StringComparer.OrdinalIgnoreCase))); } - private class DerivesFromTypeComparer : IEqualityComparer + private sealed class DerivesFromTypeComparer : IEqualityComparer { public bool Equals(Type? x, Type? y) { diff --git a/src/AutoFixture.TUnit/Internal/TestParameter.cs b/src/AutoFixture.TUnit/Internal/TestParameter.cs index 9667654..ed54cad 100644 --- a/src/AutoFixture.TUnit/Internal/TestParameter.cs +++ b/src/AutoFixture.TUnit/Internal/TestParameter.cs @@ -2,7 +2,7 @@ namespace AutoFixture.TUnit.Internal; -internal class TestParameter(ParameterInfo parameterInfo) +internal sealed class TestParameter(ParameterInfo parameterInfo) { private readonly Lazy _lazyCustomization = new( () => GetCustomization(parameterInfo)); diff --git a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs index 32a5b82..712ef02 100644 --- a/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs +++ b/src/AutoFixture.TUnit/MemberAutoDataAttribute.cs @@ -12,7 +12,6 @@ namespace AutoFixture.TUnit; /// 3. A static method (with parameters) /// The member must return something compatible with IEnumerable<object?[]> with the test data. /// -[CLSCompliant(false)] [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "This attribute is the root of a potential attribute hierarchy.")] public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute