Skip to content

Commit 44e007a

Browse files
authored
Expanded Compatibility to other versions (#14)
* updated .net dependencies to be more broad * updated release flow to trigger on github release create * added example projects for .net versions * extracted example to different solution
1 parent 1808d5b commit 44e007a

34 files changed

+411
-109
lines changed

.github/workflows/publish-nuget.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: Publish NuGet Package
22

33
on:
4-
workflow_dispatch:
4+
release:
5+
types:
6+
- published
57

68
permissions:
79
contents: read
@@ -12,12 +14,14 @@ concurrency:
1214

1315
jobs:
1416
publish:
17+
if: ${{ github.event.release.target_commitish == 'main' && startsWith(github.event.release.tag_name, 'v') }}
1518
runs-on: ubuntu-latest
1619

1720
steps:
1821
- name: Checkout
1922
uses: actions/checkout@v6
2023
with:
24+
ref: ${{ github.event.release.tag_name }}
2125
fetch-depth: 0
2226

2327
- name: Setup .NET

ConstructorCustomization.AutoFixture.Tests/ConstructorCustomization.AutoFixture.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
34
<IsTestProject>true</IsTestProject>
45
<IsPackable>false</IsPackable>
56
<PackageId>ConstructorCustomization.AutoFixture.Tests</PackageId>

ConstructorCustomization.AutoFixture/ConstructorCustomization.AutoFixture.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net8.0;net10.0;netstandard2.1</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
27
<ItemGroup>
38
<PackageReference Include="AutoFixture" />
49
</ItemGroup>

ConstructorCustomization.AutoFixture/ConstructorCustomization.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq.Expressions;
1+
using System.Linq.Expressions;
22
using System.Reflection;
33

44
using AutoFixture;
@@ -167,8 +167,8 @@ protected virtual void Configure() { }
167167
/// </summary>
168168
protected void UsePlugin(Func<Type, bool> predicate, Func<Type, IFixture, IValueCreationService, object?> factory)
169169
{
170-
ArgumentNullException.ThrowIfNull(predicate);
171-
ArgumentNullException.ThrowIfNull(factory);
170+
ThrowIfNull(predicate);
171+
ThrowIfNull(factory);
172172
Plugins.Add(new DelegateValueCreationPlugin(predicate, factory));
173173
}
174174

@@ -178,7 +178,7 @@ protected void UsePlugin(Func<Type, bool> predicate, Func<Type, IFixture, IValue
178178
/// </summary>
179179
protected void UsePlugin(IValueCreationPlugin plugin)
180180
{
181-
ArgumentNullException.ThrowIfNull(plugin);
181+
ThrowIfNull(plugin);
182182
Plugins.Add(plugin);
183183
}
184184

@@ -189,7 +189,7 @@ protected void UsePlugin(IValueCreationPlugin plugin)
189189
/// <typeparam name="TType">The exact type to handle.</typeparam>
190190
protected void UseValueFor<TType>(Func<IFixture, TType?> factory)
191191
{
192-
ArgumentNullException.ThrowIfNull(factory);
192+
ThrowIfNull(factory);
193193
Plugins.Add(new DelegateValueCreationPlugin(
194194
t => t == typeof(TType),
195195
(type, fixture, svc) => factory(fixture)));
@@ -203,7 +203,7 @@ protected void UseValueFor<TType>(Func<IFixture, TType?> factory)
203203
/// <typeparam name="TType">The exact type to handle.</typeparam>
204204
protected void UseValueFor<TType>(Func<IFixture, IValueCreationService, TType?> factory)
205205
{
206-
ArgumentNullException.ThrowIfNull(factory);
206+
ThrowIfNull(factory);
207207
Plugins.Add(new DelegateValueCreationPlugin(
208208
t => t == typeof(TType),
209209
(type, fixture, svc) => factory(fixture, svc)));
@@ -215,7 +215,7 @@ protected void UseValueFor<TType>(Func<IFixture, IValueCreationService, TType?>
215215
/// </summary>
216216
protected void UseStrategy(ISpecimenBuilderStrategy strategy)
217217
{
218-
ArgumentNullException.ThrowIfNull(strategy);
218+
ThrowIfNull(strategy);
219219
UserStrategies.Add(strategy);
220220
}
221221

@@ -226,7 +226,7 @@ protected void UseStrategy(ISpecimenBuilderStrategy strategy)
226226
/// </summary>
227227
protected void UseConstructorSelector(IConstructorSelector selector)
228228
{
229-
ArgumentNullException.ThrowIfNull(selector);
229+
ThrowIfNull(selector);
230230
RegisteredConstructorSelector = selector;
231231
}
232232

@@ -237,7 +237,7 @@ protected void UseConstructorSelector(IConstructorSelector selector)
237237
/// </summary>
238238
protected void UseParameterPropertyMatcher(IParameterPropertyMatcher matcher)
239239
{
240-
ArgumentNullException.ThrowIfNull(matcher);
240+
ThrowIfNull(matcher);
241241
RegisteredParameterPropertyMatcher = matcher;
242242
}
243243

@@ -251,8 +251,8 @@ protected void UseParameterPropertyMatcher(IParameterPropertyMatcher matcher)
251251
/// <param name="propertyExpression">The target property expression.</param>
252252
protected void MatchParameterToProperty<TProperty>(string parameterName, Expression<Func<T, TProperty>> propertyExpression)
253253
{
254-
ArgumentException.ThrowIfNullOrWhiteSpace(parameterName);
255-
ArgumentNullException.ThrowIfNull(propertyExpression);
254+
ThrowIfNullOrWhiteSpace(parameterName);
255+
ThrowIfNull(propertyExpression);
256256

257257
var propertyName = PropertyExpressionParser.GetPropertyName(propertyExpression);
258258
ExplicitParameterPropertyMappings[parameterName.Trim()] = propertyName;
@@ -266,7 +266,7 @@ protected void MatchParameterToProperty<TProperty>(string parameterName, Express
266266
/// </summary>
267267
protected void UsePropertyExpressionParser(IPropertyExpressionParser parser)
268268
{
269-
ArgumentNullException.ThrowIfNull(parser);
269+
ThrowIfNull(parser);
270270
RegisteredPropertyExpressionParser = parser;
271271
}
272272

@@ -279,7 +279,7 @@ protected void UsePropertyExpressionParser(IPropertyExpressionParser parser)
279279
/// </summary>
280280
protected void UsePropertyValueStore(Func<IPropertyValueStore> factory)
281281
{
282-
ArgumentNullException.ThrowIfNull(factory);
282+
ThrowIfNull(factory);
283283
RegisteredValueStoreFactory = factory;
284284
}
285285

@@ -292,7 +292,7 @@ protected void UsePropertyValueStore(Func<IPropertyValueStore> factory)
292292
/// </summary>
293293
protected void UseValueCreationService(IValueCreationService service)
294294
{
295-
ArgumentNullException.ThrowIfNull(service);
295+
ThrowIfNull(service);
296296
RegisteredValueCreationService = service;
297297
}
298298

@@ -318,7 +318,7 @@ protected void SetDefault<TProperty>(Expression<Func<T, TProperty>> propertyExpr
318318
/// </summary>
319319
protected void SetDefault<TProperty>(Expression<Func<T, TProperty>> propertyExpression, Func<TProperty> valueFactory)
320320
{
321-
ArgumentNullException.ThrowIfNull(valueFactory);
321+
ThrowIfNull(valueFactory);
322322
var propertyName = PropertyExpressionParser.GetPropertyName(propertyExpression);
323323
DefaultPropertyValueStore.SetValue(propertyName, new ConfiguredValueFactory(_ => valueFactory()));
324324
}
@@ -329,7 +329,7 @@ protected void SetDefault<TProperty>(Expression<Func<T, TProperty>> propertyExpr
329329
/// </summary>
330330
protected void SetDefault<TProperty>(Expression<Func<T, TProperty>> propertyExpression, Func<IFixture, TProperty> valueFactory)
331331
{
332-
ArgumentNullException.ThrowIfNull(valueFactory);
332+
ThrowIfNull(valueFactory);
333333
var propertyName = PropertyExpressionParser.GetPropertyName(propertyExpression);
334334
DefaultPropertyValueStore.SetValue(propertyName, new ConfiguredValueFactory(fixture => valueFactory(fixture)));
335335
}
@@ -356,7 +356,7 @@ public TSelf With<TProperty>(Expression<Func<T, TProperty>> propertyExpression,
356356
/// </summary>
357357
public TSelf With<TProperty>(Expression<Func<T, TProperty>> propertyExpression, Func<TProperty> valueFactory)
358358
{
359-
ArgumentNullException.ThrowIfNull(valueFactory);
359+
ThrowIfNull(valueFactory);
360360
var propertyName = PropertyExpressionParser.GetPropertyName(propertyExpression);
361361
OverridePropertyValueStore.SetValue(propertyName, new ConfiguredValueFactory(_ => valueFactory()));
362362
return (TSelf)this;
@@ -368,7 +368,7 @@ public TSelf With<TProperty>(Expression<Func<T, TProperty>> propertyExpression,
368368
/// </summary>
369369
public TSelf With<TProperty>(Expression<Func<T, TProperty>> propertyExpression, Func<IFixture, TProperty> valueFactory)
370370
{
371-
ArgumentNullException.ThrowIfNull(valueFactory);
371+
ThrowIfNull(valueFactory);
372372
var propertyName = PropertyExpressionParser.GetPropertyName(propertyExpression);
373373
OverridePropertyValueStore.SetValue(propertyName, new ConfiguredValueFactory(fixture => valueFactory(fixture)));
374374
return (TSelf)this;
@@ -521,7 +521,7 @@ protected virtual T CreateInstance(IFixture fixture)
521521

522522
private bool TryGetMappedPropertyName(ParameterInfo parameter, out string propertyName)
523523
{
524-
ArgumentNullException.ThrowIfNull(parameter);
524+
ThrowIfNull(parameter);
525525

526526
var parameterName = parameter.Name;
527527
if (string.IsNullOrWhiteSpace(parameterName))

ConstructorCustomization.AutoFixture/Customization/Adapters/CaseInsensitiveParameterPropertyMatcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22

33
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
44

@@ -17,15 +17,15 @@ internal sealed class CaseInsensitiveParameterPropertyMatcher : IParameterProper
1717
/// <param name="comparer">The comparer used when evaluating parameter and property names.</param>
1818
public CaseInsensitiveParameterPropertyMatcher(StringComparer comparer)
1919
{
20-
ArgumentNullException.ThrowIfNull(comparer);
20+
ThrowIfNull(comparer);
2121
this.comparer = comparer;
2222
}
2323

2424
/// <inheritdoc />
2525
public bool TryGetPropertyName(ParameterInfo parameter, IEnumerable<string> configuredPropertyNames, out string propertyName)
2626
{
27-
ArgumentNullException.ThrowIfNull(parameter);
28-
ArgumentNullException.ThrowIfNull(configuredPropertyNames);
27+
ThrowIfNull(parameter);
28+
ThrowIfNull(configuredPropertyNames);
2929

3030
var parameterName = parameter.Name;
3131
if (string.IsNullOrWhiteSpace(parameterName))

ConstructorCustomization.AutoFixture/Customization/Adapters/LargestConstructorSelector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22

33
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
44

@@ -12,8 +12,8 @@ internal sealed class LargestConstructorSelector : IConstructorSelector
1212
/// <inheritdoc />
1313
public ConstructorInfo SelectConstructor(Type targetType, ConstructorInfo[] constructors)
1414
{
15-
ArgumentNullException.ThrowIfNull(targetType);
16-
ArgumentNullException.ThrowIfNull(constructors);
15+
ThrowIfNull(targetType);
16+
ThrowIfNull(constructors);
1717

1818
if (constructors.Length == 0)
1919
{

ConstructorCustomization.AutoFixture/Customization/Adapters/PropertyExpressionParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq.Expressions;
1+
using System.Linq.Expressions;
22

33
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
44

@@ -12,7 +12,7 @@ internal sealed class PropertyExpressionParser : IPropertyExpressionParser
1212
/// <inheritdoc />
1313
public string GetPropertyName(LambdaExpression propertyExpression)
1414
{
15-
ArgumentNullException.ThrowIfNull(propertyExpression);
15+
ThrowIfNull(propertyExpression);
1616

1717
var body = propertyExpression.Body;
1818
if (body is UnaryExpression unaryExpression && unaryExpression.NodeType == ExpressionType.Convert)

ConstructorCustomization.AutoFixture/Customization/Adapters/PropertyValueStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
1+
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
22

33
namespace ConstructorCustomization.AutoFixture.Customization.Adapters;
44

@@ -15,7 +15,7 @@ internal sealed class PropertyValueStore : IPropertyValueStore
1515
/// <param name="comparer">The comparer used to match property names.</param>
1616
public PropertyValueStore(StringComparer comparer)
1717
{
18-
ArgumentNullException.ThrowIfNull(comparer);
18+
ThrowIfNull(comparer);
1919
values = new Dictionary<string, object?>(comparer);
2020
}
2121

ConstructorCustomization.AutoFixture/Customization/Domain/CustomizationDomainOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ConstructorCustomization.AutoFixture.Customization.Domain;
1+
namespace ConstructorCustomization.AutoFixture.Customization.Domain;
22

33
internal sealed class CustomizationDomainOptions
44
{
@@ -14,7 +14,7 @@ private CustomizationDomainOptions(int collectionItemCount, StringComparer prope
1414

1515
public static CustomizationDomainOptions From(ConstructorCustomizationOptions options)
1616
{
17-
ArgumentNullException.ThrowIfNull(options);
17+
ThrowIfNull(options);
1818

1919
if (options.CollectionItemCount < 0)
2020
{

ConstructorCustomization.AutoFixture/Customization/Domain/PropertyValueResolutionPolicy.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using AutoFixture;
1+
using AutoFixture;
22

33
using ConstructorCustomization.AutoFixture.Customization.Application.Ports;
44

@@ -15,11 +15,11 @@ public static bool TryResolveConfiguredValue(
1515
out object? resolvedValue,
1616
out PropertyValueSource valueSource)
1717
{
18-
ArgumentException.ThrowIfNullOrWhiteSpace(propertyName);
19-
ArgumentNullException.ThrowIfNull(overrideStore);
20-
ArgumentNullException.ThrowIfNull(defaultStore);
21-
ArgumentNullException.ThrowIfNull(fixture);
22-
ArgumentNullException.ThrowIfNull(configuredValueResolver);
18+
ThrowIfNullOrWhiteSpace(propertyName);
19+
ThrowIfNull(overrideStore);
20+
ThrowIfNull(defaultStore);
21+
ThrowIfNull(fixture);
22+
ThrowIfNull(configuredValueResolver);
2323

2424
if (overrideStore.TryGetValue(propertyName, out var overrideValue))
2525
{

0 commit comments

Comments
 (0)