Skip to content

Commit dd5c788

Browse files
committed
refactor: move to file scoped namespaces
1 parent 0e396ef commit dd5c788

251 files changed

Lines changed: 18924 additions & 19161 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ csharp_space_between_square_brackets = false
229229
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#wrap-options
230230
csharp_preserve_single_line_statements = false
231231
csharp_preserve_single_line_blocks = true
232+
csharp_style_namespace_declarations = file_scoped:warning
232233

233234
##########################################
234235
# .NET Naming Conventions

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PropertyGroup Label="Compile settings">
1919
<Nullable>enable</Nullable>
2020
<LangVersion>10.0</LangVersion>
21-
<ImplicitUsings>disable</ImplicitUsings>
21+
<ImplicitUsings>enable</ImplicitUsings>
2222
<NoWarn>CA1014,NU5104</NoWarn>
2323

2424
<!-- Used by code coverage -->
@@ -47,7 +47,7 @@
4747
<!-- Shared code analyzers used for all projects in the solution -->
4848
<ItemGroup Label="Code Analyzers">
4949
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="All" />
50-
<PackageReference Include="Meziantou.Analyzer" Version="1.0.676" PrivateAssets="All" />
50+
<PackageReference Include="Meziantou.Analyzer" Version="1.0.678" PrivateAssets="All" />
5151
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.32.0.39516" PrivateAssets="All" />
5252
</ItemGroup>
5353

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
using System;
22
using System.Runtime.Serialization;
33

4-
namespace Bunit.Asserting
4+
namespace Bunit.Asserting;
5+
6+
/// <summary>
7+
/// Represents a generic assert exception used when an actual result does not match an expected result.
8+
/// </summary>
9+
[Serializable]
10+
public class ActualExpectedAssertException : Exception
511
{
612
/// <summary>
7-
/// Represents a generic assert exception used when an actual result does not match an expected result.
13+
/// Initializes a new instance of the <see cref="ActualExpectedAssertException"/> class.
814
/// </summary>
9-
[Serializable]
10-
public class ActualExpectedAssertException : Exception
15+
/// <param name="actual">The actual result.</param>
16+
/// <param name="expected">The expected result.</param>
17+
/// <param name="actualText">A text explaining the actual result.</param>
18+
/// <param name="expectedText">A text explaining the expected result.</param>
19+
/// <param name="message">An error message explaining the context of the assertion.</param>
20+
public ActualExpectedAssertException(string actual, string expected, string actualText, string expectedText, string message)
21+
: base(CreateMessage(actual, expected, actualText, expectedText, message))
1122
{
12-
/// <summary>
13-
/// Initializes a new instance of the <see cref="ActualExpectedAssertException"/> class.
14-
/// </summary>
15-
/// <param name="actual">The actual result.</param>
16-
/// <param name="expected">The expected result.</param>
17-
/// <param name="actualText">A text explaining the actual result.</param>
18-
/// <param name="expectedText">A text explaining the expected result.</param>
19-
/// <param name="message">An error message explaining the context of the assertion.</param>
20-
public ActualExpectedAssertException(string actual, string expected, string actualText, string expectedText, string message)
21-
: base(CreateMessage(actual, expected, actualText, expectedText, message))
22-
{
23-
}
23+
}
2424

25-
/// <summary>
26-
/// Initializes a new instance of the <see cref="ActualExpectedAssertException"/> class.
27-
/// </summary>
28-
protected ActualExpectedAssertException(SerializationInfo info, StreamingContext context)
29-
: base(info, context) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ActualExpectedAssertException"/> class.
27+
/// </summary>
28+
protected ActualExpectedAssertException(SerializationInfo info, StreamingContext context)
29+
: base(info, context) { }
3030

31-
private static string CreateMessage(string actual, string expected, string actualText, string expectedText, string message)
32-
{
33-
return $"{message}{Environment.NewLine}{actualText}: {actual}{Environment.NewLine}{expectedText}: {expected}";
34-
}
31+
private static string CreateMessage(string actual, string expected, string actualText, string expectedText, string message)
32+
{
33+
return $"{message}{Environment.NewLine}{actualText}: {actual}{Environment.NewLine}{expectedText}: {expected}";
3534
}
3635
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22

3-
namespace Bunit.Asserting
4-
{
5-
/// <summary>
6-
/// Add this attribute to assertion methods to indicate to
7-
/// 3rd party analyzers that the method is an assertion method.
8-
/// See more here: https://rules.sonarsource.com/csharp/RSPEC-2699.
9-
/// </summary>
10-
[AttributeUsage(AttributeTargets.Method)]
11-
public sealed class AssertionMethodAttribute : Attribute { }
12-
}
3+
namespace Bunit.Asserting;
4+
5+
/// <summary>
6+
/// Add this attribute to assertion methods to indicate to
7+
/// 3rd party analyzers that the method is an assertion method.
8+
/// See more here: https://rules.sonarsource.com/csharp/RSPEC-2699.
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Method)]
11+
public sealed class AssertionMethodAttribute : Attribute { }

src/bunit.core/ComponentFactories/GenericComponentFactory{TComponent,TReplacementComponent}.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
using System;
33
using Microsoft.AspNetCore.Components;
44

5-
namespace Bunit.ComponentFactories
5+
namespace Bunit.ComponentFactories;
6+
7+
internal sealed class GenericComponentFactory<TComponent, TReplacementComponent> : IComponentFactory
8+
where TComponent : IComponent
9+
where TReplacementComponent : IComponent
610
{
7-
internal sealed class GenericComponentFactory<TComponent, TReplacementComponent> : IComponentFactory
8-
where TComponent : IComponent
9-
where TReplacementComponent : IComponent
10-
{
11-
public bool CanCreate(Type componentType) => componentType == typeof(TComponent);
12-
public IComponent Create(Type componentType) => Activator.CreateInstance<TReplacementComponent>()!;
13-
}
11+
public bool CanCreate(Type componentType) => componentType == typeof(TComponent);
12+
public IComponent Create(Type componentType) => Activator.CreateInstance<TReplacementComponent>()!;
1413
}
1514
#endif

src/bunit.core/ComponentFactories/InstanceComponentFactory.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22
using System;
33
using Microsoft.AspNetCore.Components;
44

5-
namespace Bunit.ComponentFactories
5+
namespace Bunit.ComponentFactories;
6+
7+
internal sealed class InstanceComponentFactory<TComponent> : IComponentFactory
8+
where TComponent : IComponent
69
{
7-
internal sealed class InstanceComponentFactory<TComponent> : IComponentFactory
8-
where TComponent : IComponent
9-
{
10-
private readonly TComponent instance;
11-
private int createCount;
10+
private readonly TComponent instance;
11+
private int createCount;
1212

13-
public InstanceComponentFactory(TComponent instance)
14-
=> this.instance = instance;
13+
public InstanceComponentFactory(TComponent instance)
14+
=> this.instance = instance;
1515

16-
public bool CanCreate(Type componentType)
17-
=> componentType == typeof(TComponent);
16+
public bool CanCreate(Type componentType)
17+
=> componentType == typeof(TComponent);
1818

19-
public IComponent Create(Type componentType)
19+
public IComponent Create(Type componentType)
20+
{
21+
if (createCount == 1)
2022
{
21-
if(createCount == 1)
22-
{
23-
throw new InvalidOperationException(
24-
$"The instance object passed to the" +
25-
$"{nameof(TestContextBase.ComponentFactories)}.{nameof(ComponentFactoryCollectionExtensions.Add)}<{typeof(TComponent).Name}>(instance) method can only be used to replace " +
26-
$"one {typeof(TComponent)} component in the render tree.");
27-
}
23+
throw new InvalidOperationException(
24+
$"The instance object passed to the" +
25+
$"{nameof(TestContextBase.ComponentFactories)}.{nameof(ComponentFactoryCollectionExtensions.Add)}<{typeof(TComponent).Name}>(instance) method can only be used to replace " +
26+
$"one {typeof(TComponent)} component in the render tree.");
27+
}
2828

29-
createCount++;
29+
createCount++;
3030

31-
return instance;
32-
}
31+
return instance;
3332
}
3433
}
3534
#endif

src/bunit.core/ComponentFactoryCollection.cs

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,94 @@
22
using System.Collections;
33
using System.Collections.Generic;
44

5-
namespace Bunit
5+
namespace Bunit;
6+
7+
/// <summary>
8+
/// Represents a collection of <see cref="IComponentFactory"/>.
9+
/// </summary>
10+
public sealed class ComponentFactoryCollection : IList<IComponentFactory>
611
{
12+
private readonly IList<IComponentFactory> factories = new List<IComponentFactory>();
13+
714
/// <summary>
8-
/// Represents a collection of <see cref="IComponentFactory"/>.
15+
/// Gets or sets a <see cref="IComponentFactory"/> at the specified index.
916
/// </summary>
10-
public sealed class ComponentFactoryCollection : IList<IComponentFactory>
11-
{
12-
private readonly IList<IComponentFactory> factories = new List<IComponentFactory>();
17+
/// <param name="index">The zero-based index of the element to get or set.</param>
18+
/// <returns>The <see cref="IComponentFactory"/> at the specified index.</returns>
19+
public IComponentFactory this[int index] { get => factories[index]; set => factories[index] = value; }
1320

14-
/// <summary>
15-
/// Gets or sets a <see cref="IComponentFactory"/> at the specified index.
16-
/// </summary>
17-
/// <param name="index">The zero-based index of the element to get or set.</param>
18-
/// <returns>The <see cref="IComponentFactory"/> at the specified index.</returns>
19-
public IComponentFactory this[int index] { get => factories[index]; set => factories[index] = value; }
20-
21-
/// <summary>
22-
/// Gets the number of <see cref="IComponentFactory"/> contained in the <see cref="ComponentFactoryCollection"/>.
23-
/// </summary>
24-
public int Count => factories.Count;
21+
/// <summary>
22+
/// Gets the number of <see cref="IComponentFactory"/> contained in the <see cref="ComponentFactoryCollection"/>.
23+
/// </summary>
24+
public int Count => factories.Count;
2525

26-
/// <summary>
27-
/// Gets a value indicating whether the <see cref="ComponentFactoryCollection"/> is read-only.
28-
/// </summary>
29-
public bool IsReadOnly => factories.IsReadOnly;
26+
/// <summary>
27+
/// Gets a value indicating whether the <see cref="ComponentFactoryCollection"/> is read-only.
28+
/// </summary>
29+
public bool IsReadOnly => factories.IsReadOnly;
3030

31-
/// <summary>
32-
/// Adds an <see cref="IComponentFactory"/> to the <see cref="ComponentFactoryCollection"/>.
33-
/// </summary>
34-
/// <param name="item">The <see cref="IComponentFactory"/> to add to the collection.</param>
35-
public void Add(IComponentFactory item) => factories.Add(item);
31+
/// <summary>
32+
/// Adds an <see cref="IComponentFactory"/> to the <see cref="ComponentFactoryCollection"/>.
33+
/// </summary>
34+
/// <param name="item">The <see cref="IComponentFactory"/> to add to the collection.</param>
35+
public void Add(IComponentFactory item) => factories.Add(item);
3636

37-
/// <summary>
38-
/// Removes all <see cref="IComponentFactory"/>s from the <see cref="ComponentFactoryCollection"/>.
39-
/// </summary>
40-
public void Clear() => factories.Clear();
37+
/// <summary>
38+
/// Removes all <see cref="IComponentFactory"/>s from the <see cref="ComponentFactoryCollection"/>.
39+
/// </summary>
40+
public void Clear() => factories.Clear();
4141

42-
/// <summary>
43-
/// Determines whether the <see cref="ComponentFactoryCollection"/> contains a specific <see cref="IComponentFactory"/>.
44-
/// </summary>
45-
/// <param name="item">The object to locate in the <see cref="ComponentFactoryCollection"/>..</param>
46-
/// <returns>true if item is found in the <see cref="ComponentFactoryCollection"/>; otherwise, false.</returns>
47-
public bool Contains(IComponentFactory item) => factories.Contains(item);
42+
/// <summary>
43+
/// Determines whether the <see cref="ComponentFactoryCollection"/> contains a specific <see cref="IComponentFactory"/>.
44+
/// </summary>
45+
/// <param name="item">The object to locate in the <see cref="ComponentFactoryCollection"/>..</param>
46+
/// <returns>true if item is found in the <see cref="ComponentFactoryCollection"/>; otherwise, false.</returns>
47+
public bool Contains(IComponentFactory item) => factories.Contains(item);
4848

49-
/// <summary>
50-
/// Copies the <see cref="IComponentFactory"/>s of the <see cref="ComponentFactoryCollection"/> to an <see cref="System.Array"/>, starting at a particular <see cref="System.Array"/> index.
51-
/// </summary>
52-
/// <param name="array">The one-dimensional <see cref="System.Array"/> that is the destination of the elements copied from <see cref="ComponentFactoryCollection"/>. The <see cref="System.Array"/> must have zero-based indexing.</param>
53-
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
54-
public void CopyTo(IComponentFactory[] array, int arrayIndex) => factories.CopyTo(array, arrayIndex);
49+
/// <summary>
50+
/// Copies the <see cref="IComponentFactory"/>s of the <see cref="ComponentFactoryCollection"/> to an <see cref="System.Array"/>, starting at a particular <see cref="System.Array"/> index.
51+
/// </summary>
52+
/// <param name="array">The one-dimensional <see cref="System.Array"/> that is the destination of the elements copied from <see cref="ComponentFactoryCollection"/>. The <see cref="System.Array"/> must have zero-based indexing.</param>
53+
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
54+
public void CopyTo(IComponentFactory[] array, int arrayIndex) => factories.CopyTo(array, arrayIndex);
5555

56-
/// <summary>
57-
/// Returns an enumerator that iterates through the collection of <see cref="IComponentFactory"/>.
58-
/// </summary>
59-
/// <returns>An enumerator that can be used to iterate through the collection of <see cref="IComponentFactory"/>.</returns>
60-
public IEnumerator<IComponentFactory> GetEnumerator() => factories.GetEnumerator();
56+
/// <summary>
57+
/// Returns an enumerator that iterates through the collection of <see cref="IComponentFactory"/>.
58+
/// </summary>
59+
/// <returns>An enumerator that can be used to iterate through the collection of <see cref="IComponentFactory"/>.</returns>
60+
public IEnumerator<IComponentFactory> GetEnumerator() => factories.GetEnumerator();
6161

62-
/// <summary>
63-
/// Determines the index of a specific <see cref="IComponentFactory"/> in the <see cref="ComponentFactoryCollection"/>.
64-
/// </summary>
65-
/// <param name="item">The <see cref="IComponentFactory"/> to locate in the <see cref="ComponentFactoryCollection"/>..</param>
66-
/// <returns>The index of <see cref="IComponentFactory"/> if found in the list; otherwise, -1.</returns>
67-
public int IndexOf(IComponentFactory item) => factories.IndexOf(item);
62+
/// <summary>
63+
/// Determines the index of a specific <see cref="IComponentFactory"/> in the <see cref="ComponentFactoryCollection"/>.
64+
/// </summary>
65+
/// <param name="item">The <see cref="IComponentFactory"/> to locate in the <see cref="ComponentFactoryCollection"/>..</param>
66+
/// <returns>The index of <see cref="IComponentFactory"/> if found in the list; otherwise, -1.</returns>
67+
public int IndexOf(IComponentFactory item) => factories.IndexOf(item);
6868

69-
/// <summary>
70-
/// Inserts an <see cref="IComponentFactory"/> to the <see cref="ComponentFactoryCollection"/> at the specified index.
71-
/// </summary>
72-
/// <param name="index">The zero-based index at which <see cref="IComponentFactory"/> should be inserted.</param>
73-
/// <param name="item">The <see cref="IComponentFactory"/> to insert into the <see cref="ComponentFactoryCollection"/>.</param>
74-
public void Insert(int index, IComponentFactory item) => factories.Insert(index, item);
69+
/// <summary>
70+
/// Inserts an <see cref="IComponentFactory"/> to the <see cref="ComponentFactoryCollection"/> at the specified index.
71+
/// </summary>
72+
/// <param name="index">The zero-based index at which <see cref="IComponentFactory"/> should be inserted.</param>
73+
/// <param name="item">The <see cref="IComponentFactory"/> to insert into the <see cref="ComponentFactoryCollection"/>.</param>
74+
public void Insert(int index, IComponentFactory item) => factories.Insert(index, item);
7575

76-
/// <summary>
77-
/// Removes the first occurrence of a specific <see cref="IComponentFactory"/> from the <see cref="ComponentFactoryCollection"/>.
78-
/// </summary>
79-
/// <param name="item">The <see cref="IComponentFactory"/> to remove from the <see cref="ComponentFactoryCollection"/>.</param>
80-
/// <returns>true if <see cref="IComponentFactory"/> was successfully removed from the <see cref="ComponentFactoryCollection"/>; otherwise, false. This method also returns false if <see cref="IComponentFactory"/> is not found in the original <see cref="ComponentFactoryCollection"/>.</returns>
81-
public bool Remove(IComponentFactory item) => factories.Remove(item);
76+
/// <summary>
77+
/// Removes the first occurrence of a specific <see cref="IComponentFactory"/> from the <see cref="ComponentFactoryCollection"/>.
78+
/// </summary>
79+
/// <param name="item">The <see cref="IComponentFactory"/> to remove from the <see cref="ComponentFactoryCollection"/>.</param>
80+
/// <returns>true if <see cref="IComponentFactory"/> was successfully removed from the <see cref="ComponentFactoryCollection"/>; otherwise, false. This method also returns false if <see cref="IComponentFactory"/> is not found in the original <see cref="ComponentFactoryCollection"/>.</returns>
81+
public bool Remove(IComponentFactory item) => factories.Remove(item);
8282

83-
/// <summary>
84-
/// Removes the <see cref="ComponentFactoryCollection"/> <see cref="IComponentFactory"/> at the specified index.
85-
/// </summary>
86-
/// <param name="index">The zero-based index of the <see cref="IComponentFactory"/> to remove.</param>
87-
public void RemoveAt(int index) => factories.RemoveAt(index);
83+
/// <summary>
84+
/// Removes the <see cref="ComponentFactoryCollection"/> <see cref="IComponentFactory"/> at the specified index.
85+
/// </summary>
86+
/// <param name="index">The zero-based index of the <see cref="IComponentFactory"/> to remove.</param>
87+
public void RemoveAt(int index) => factories.RemoveAt(index);
8888

89-
/// <summary>
90-
/// Returns an enumerator that iterates through a <see cref="ComponentFactoryCollection"/>.
91-
/// </summary>
92-
/// <returns>An <see cref="IEnumerator"/> object that can be used to iterate through the <see cref="ComponentFactoryCollection"/>.</returns>
93-
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)factories).GetEnumerator();
94-
}
89+
/// <summary>
90+
/// Returns an enumerator that iterates through a <see cref="ComponentFactoryCollection"/>.
91+
/// </summary>
92+
/// <returns>An <see cref="IEnumerator"/> object that can be used to iterate through the <see cref="ComponentFactoryCollection"/>.</returns>
93+
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)factories).GetEnumerator();
9594
}
9695
#endif

0 commit comments

Comments
 (0)