Skip to content

Commit 618f041

Browse files
committed
Update to use file-scoped namespace
1 parent 94a228b commit 618f041

28 files changed

+1021
-1106
lines changed

Atc.Test.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=dependant/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/Atc.Test/Atc.Test.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<ItemGroup>
1717
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.17.0" />
1818
<PackageReference Include="AutoFixture.Xunit2" Version="4.17.0" />
19-
<PackageReference Include="FluentAssertions" Version="6.1.0" />
20-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
21-
<PackageReference Include="NSubstitute" Version="4.2.2" />
19+
<PackageReference Include="FluentAssertions" Version="6.4.0" />
20+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
21+
<PackageReference Include="NSubstitute" Version="4.3.0" />
2222
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
23-
<PackageReference Include="System.Text.Json" Version="5.0.2" />
23+
<PackageReference Include="System.Text.Json" Version="6.0.2" />
2424
</ItemGroup>
2525

2626
</Project>
+12-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
using AutoFixture.AutoNSubstitute;
2-
using AutoFixture.Xunit2;
1+
namespace Atc.Test;
32

4-
namespace Atc.Test
3+
/// <summary>
4+
/// Provides auto-generated data specimens generated by AutoFixture and NSubstitute
5+
/// as an extension to xUnit.net's Theory attribute.
6+
/// </summary>
7+
/// <remarks>
8+
/// NSubstitute is used when the type is abstract, or when the <see cref="SubstituteAttribute"/> is applied.
9+
/// </remarks>
10+
public sealed class AutoNSubstituteDataAttribute : AutoDataAttribute
511
{
612
/// <summary>
7-
/// Provides auto-generated data specimens generated by AutoFixture and NSubstitute
8-
/// as an extension to xUnit.net's Theory attribute.
13+
/// Initializes a new instance of the <see cref="AutoNSubstituteDataAttribute"/> class.
914
/// </summary>
10-
/// <remarks>
11-
/// NSubstitute is used when the type is abstract, or when the <see cref="SubstituteAttribute"/> is applied.
12-
/// </remarks>
13-
public sealed class AutoNSubstituteDataAttribute : AutoDataAttribute
15+
public AutoNSubstituteDataAttribute()
16+
: base(FixtureFactory.Create)
1417
{
15-
/// <summary>
16-
/// Initializes a new instance of the <see cref="AutoNSubstituteDataAttribute"/> class.
17-
/// </summary>
18-
public AutoNSubstituteDataAttribute()
19-
: base(FixtureFactory.Create)
20-
{
21-
}
2218
}
2319
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
1+
namespace Atc.Test.Customizations;
22

3-
namespace Atc.Test.Customizations
3+
[AttributeUsage(AttributeTargets.Class)]
4+
public sealed class AutoRegisterAttribute : Attribute
45
{
5-
[AttributeUsage(AttributeTargets.Class)]
6-
public sealed class AutoRegisterAttribute : Attribute
7-
{
8-
}
96
}
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,66 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Reflection;
5-
using AutoFixture;
6-
using AutoFixture.Kernel;
1+
namespace Atc.Test.Customizations;
72

8-
namespace Atc.Test.Customizations
3+
/// <summary>
4+
/// Responsible for registering customizations with the <see cref="AutoRegisterAttribute"/> specified.
5+
/// </summary>
6+
public class AutoRegisterCustomization : ICustomization
97
{
10-
/// <summary>
11-
/// Responsible for registering customizations with the <see cref="AutoRegisterAttribute"/> specified.
12-
/// </summary>
13-
public class AutoRegisterCustomization : ICustomization
14-
{
15-
private static Type[]? autoRegisterTypes;
8+
private static Type[]? autoRegisterTypes;
169

17-
/// <inheritdoc/>
18-
public void Customize(IFixture fixture)
10+
/// <inheritdoc/>
11+
public void Customize(IFixture fixture)
12+
{
13+
if (fixture is null)
1914
{
20-
if (fixture is null)
21-
{
22-
throw new ArgumentNullException(nameof(fixture));
23-
}
15+
throw new ArgumentNullException(nameof(fixture));
16+
}
2417

25-
if (autoRegisterTypes is null)
26-
{
27-
autoRegisterTypes = AppDomain.CurrentDomain
28-
.GetAssemblies()
29-
.SelectMany(GetLoadableTypes)
30-
.Where(HasAutoRegisterAttribute)
31-
.ToArray();
32-
}
18+
if (autoRegisterTypes is null)
19+
{
20+
autoRegisterTypes = AppDomain.CurrentDomain
21+
.GetAssemblies()
22+
.SelectMany(GetLoadableTypes)
23+
.Where(HasAutoRegisterAttribute)
24+
.ToArray();
25+
}
3326

34-
foreach (var type in autoRegisterTypes)
27+
foreach (var type in autoRegisterTypes)
28+
{
29+
var customization = Activator.CreateInstance(type);
30+
switch (customization)
3531
{
36-
var customization = Activator.CreateInstance(type);
37-
switch (customization)
38-
{
39-
case ICustomization c:
40-
fixture.Customize(c);
41-
break;
32+
case ICustomization c:
33+
fixture.Customize(c);
34+
break;
4235

43-
case ISpecimenBuilder b:
44-
fixture.Customizations.Add(b);
45-
break;
36+
case ISpecimenBuilder b:
37+
fixture.Customizations.Add(b);
38+
break;
4639

47-
default:
48-
throw new NotSupportedException(
49-
$"Invalid type {type.Name}. Only ICustomization and " +
50-
$"ISpecimenBuilder is supported for the " +
51-
$"AutoRegisterAttribute.");
52-
}
40+
default:
41+
throw new NotSupportedException(
42+
$"Invalid type {type.Name}. Only ICustomization and " +
43+
$"ISpecimenBuilder is supported for the " +
44+
$"AutoRegisterAttribute.");
5345
}
5446
}
47+
}
5548

56-
private static bool HasAutoRegisterAttribute(Type type)
57-
=> type.GetCustomAttributes(
58-
typeof(AutoRegisterAttribute),
59-
inherit: false).Length > 0;
49+
private static bool HasAutoRegisterAttribute(Type type)
50+
=> type.GetCustomAttributes(
51+
typeof(AutoRegisterAttribute),
52+
inherit: false).Length > 0;
6053

61-
private static IEnumerable<Type> GetLoadableTypes(Assembly assembly)
54+
private static IEnumerable<Type> GetLoadableTypes(Assembly assembly)
55+
{
56+
try
6257
{
63-
try
64-
{
65-
return assembly.GetTypes();
66-
}
67-
catch (ReflectionTypeLoadException e)
68-
{
69-
return e.Types?.OfType<Type>()
70-
?? Enumerable.Empty<Type>();
71-
}
58+
return assembly.GetTypes();
59+
}
60+
catch (ReflectionTypeLoadException e)
61+
{
62+
return e.Types?.OfType<Type>()
63+
?? Enumerable.Empty<Type>();
7264
}
7365
}
7466
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
using System.Threading;
2-
using AutoFixture.Kernel;
1+
namespace Atc.Test.Customizations.Generators;
32

4-
namespace Atc.Test.Customizations.Generators
3+
/// <summary>
4+
/// Responsible for generating <see cref="CancellationToken"/> instances
5+
/// that has not been canceled.
6+
/// </summary>
7+
[AutoRegister]
8+
public class CancellationTokenGenerator : ISpecimenBuilder
59
{
6-
/// <summary>
7-
/// Responsible for generating <see cref="CancellationToken"/> instances
8-
/// that has not been canceled.
9-
/// </summary>
10-
[AutoRegister]
11-
public class CancellationTokenGenerator : ISpecimenBuilder
10+
/// <inheritdoc/>
11+
public object Create(object request, ISpecimenContext context)
1212
{
13-
/// <inheritdoc/>
14-
public object Create(object request, ISpecimenContext context)
13+
if (!request.IsRequestFor<CancellationToken>())
1514
{
16-
if (!request.IsRequestFor<CancellationToken>())
17-
{
18-
return new NoSpecimen();
19-
}
20-
21-
return new CancellationToken(canceled: false);
15+
return new NoSpecimen();
2216
}
17+
18+
return new CancellationToken(canceled: false);
2319
}
2420
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
using System;
2-
using System.Reflection;
3-
using AutoFixture.Kernel;
1+
namespace Atc.Test.Customizations.Generators;
42

5-
namespace Atc.Test.Customizations.Generators
3+
/// <summary>
4+
/// Extensions for <see cref="ISpecimenBuilder"/> requests.
5+
/// </summary>
6+
public static class SpecimenRequestExtensions
67
{
78
/// <summary>
8-
/// Extensions for <see cref="ISpecimenBuilder"/> requests.
9+
/// Checks if an <see cref="ISpecimenBuilder"/> request is
10+
/// for a specific <see cref="Type"/>.
911
/// </summary>
10-
public static class SpecimenRequestExtensions
12+
/// <typeparam name="T">The type to check for.</typeparam>
13+
/// <param name="request">The request.</param>
14+
/// <returns>True if the request is for the specified Type of <typeparamref name="T"/>.</returns>
15+
public static bool IsRequestFor<T>(this object request) => request switch
1116
{
12-
/// <summary>
13-
/// Checks if an <see cref="ISpecimenBuilder"/> request is
14-
/// for a specific <see cref="Type"/>.
15-
/// </summary>
16-
/// <typeparam name="T">The type to check for.</typeparam>
17-
/// <param name="request">The request.</param>
18-
/// <returns>True if the request is for the specified Type of <typeparamref name="T"/>.</returns>
19-
public static bool IsRequestFor<T>(this object request) => request switch
20-
{
21-
ParameterInfo pi => pi.ParameterType == typeof(T),
22-
Type type => type == typeof(T),
23-
_ => false,
24-
};
25-
}
17+
ParameterInfo pi => pi.ParameterType == typeof(T),
18+
Type type => type == typeof(T),
19+
_ => false,
20+
};
2621
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
using AutoFixture;
1+
namespace Atc.Test.Customizations;
22

3-
namespace Atc.Test.Customizations
3+
/// <summary>
4+
/// Responsible for setting up recursion behavior
5+
/// to ensure AutoFixture will not throw on recursion.
6+
/// </summary>
7+
public class RecursionCustomization : ICustomization
48
{
5-
/// <summary>
6-
/// Responsible for setting up recursion behavior
7-
/// to ensure AutoFixture will not throw on recursion.
8-
/// </summary>
9-
public class RecursionCustomization : ICustomization
9+
/// <inheritdoc/>
10+
public void Customize(IFixture fixture)
1011
{
11-
/// <inheritdoc/>
12-
public void Customize(IFixture fixture)
13-
{
14-
fixture?.Behaviors
15-
.Remove(new ThrowingRecursionBehavior());
12+
fixture?.Behaviors
13+
.Remove(new ThrowingRecursionBehavior());
1614

17-
fixture?.Behaviors
18-
.Add(new OmitOnRecursionBehavior());
19-
}
15+
fixture?.Behaviors
16+
.Add(new OmitOnRecursionBehavior());
2017
}
2118
}

0 commit comments

Comments
 (0)