Skip to content

Commit f470b5d

Browse files
authored
Use file scoped namepsaces (#763)
1 parent 8b2beb2 commit f470b5d

File tree

312 files changed

+15426
-15736
lines changed

Some content is hidden

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

312 files changed

+15426
-15736
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dotnet_style_qualification_for_field = false:suggestion
1717
dotnet_style_qualification_for_property = false:suggestion
1818
dotnet_style_qualification_for_method = false:suggestion
1919
dotnet_style_qualification_for_event = false:suggestion
20+
csharp_style_namespace_declarations=file_scoped:warning
2021

2122
# ReSharper properties
2223
resharper_int_align_switch_expressions = true

src/NSubstitute/Arg.cs

Lines changed: 161 additions & 162 deletions
Large diffs are not rendered by default.

src/NSubstitute/Callback.cs

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,126 @@
1-
using System.Collections.Concurrent;
2-
using NSubstitute.Callbacks;
1+
using NSubstitute.Callbacks;
32
using NSubstitute.Core;
3+
using System.Collections.Concurrent;
44

55
// Disable nullability for client API, so it does not affect clients.
66
#nullable disable annotations
77

8-
namespace NSubstitute
8+
namespace NSubstitute;
9+
10+
/// <summary>
11+
/// Perform this chain of callbacks and/or always callback when called.
12+
/// </summary>
13+
public class Callback
914
{
1015
/// <summary>
11-
/// Perform this chain of callbacks and/or always callback when called.
16+
/// Perform as first in chain of callback when called.
1217
/// </summary>
13-
public class Callback
18+
/// <param name="doThis"></param>
19+
/// <returns></returns>
20+
public static ConfiguredCallback First(Action<CallInfo> doThis)
1421
{
15-
/// <summary>
16-
/// Perform as first in chain of callback when called.
17-
/// </summary>
18-
/// <param name="doThis"></param>
19-
/// <returns></returns>
20-
public static ConfiguredCallback First(Action<CallInfo> doThis)
21-
{
22-
return new ConfiguredCallback().Then(doThis);
23-
}
22+
return new ConfiguredCallback().Then(doThis);
23+
}
2424

25-
/// <summary>
26-
/// Perform this action always when callback is called.
27-
/// </summary>
28-
/// <param name="doThis"></param>
29-
/// <returns></returns>
30-
public static Callback Always(Action<CallInfo> doThis)
31-
{
32-
return new ConfiguredCallback().AndAlways(doThis);
33-
}
25+
/// <summary>
26+
/// Perform this action always when callback is called.
27+
/// </summary>
28+
/// <param name="doThis"></param>
29+
/// <returns></returns>
30+
public static Callback Always(Action<CallInfo> doThis)
31+
{
32+
return new ConfiguredCallback().AndAlways(doThis);
33+
}
3434

35-
/// <summary>
36-
/// Throw exception returned by function as first callback in chain of callback when called.
37-
/// </summary>
38-
/// <param name="throwThis"></param>
39-
/// <returns></returns>
40-
public static ConfiguredCallback FirstThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
41-
{
42-
return new ConfiguredCallback().ThenThrow(throwThis);
43-
}
35+
/// <summary>
36+
/// Throw exception returned by function as first callback in chain of callback when called.
37+
/// </summary>
38+
/// <param name="throwThis"></param>
39+
/// <returns></returns>
40+
public static ConfiguredCallback FirstThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
41+
{
42+
return new ConfiguredCallback().ThenThrow(throwThis);
43+
}
4444

45-
/// <summary>
46-
/// Throw this exception as first callback in chain of callback when called.
47-
/// </summary>
48-
/// <param name="exception"></param>
49-
/// <returns></returns>
50-
public static ConfiguredCallback FirstThrow<TException>(TException exception) where TException : Exception
51-
{
52-
return new ConfiguredCallback().ThenThrow(info => exception);
53-
}
45+
/// <summary>
46+
/// Throw this exception as first callback in chain of callback when called.
47+
/// </summary>
48+
/// <param name="exception"></param>
49+
/// <returns></returns>
50+
public static ConfiguredCallback FirstThrow<TException>(TException exception) where TException : Exception
51+
{
52+
return new ConfiguredCallback().ThenThrow(info => exception);
53+
}
5454

55-
/// <summary>
56-
/// Throw exception returned by function always when callback is called.
57-
/// </summary>
58-
/// <typeparam name="TException">The type of the exception.</typeparam>
59-
/// <param name="throwThis">The throw this.</param>
60-
/// <returns></returns>
61-
public static Callback AlwaysThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
62-
{
63-
return new ConfiguredCallback().AndAlways(ToCallback(throwThis));
64-
}
55+
/// <summary>
56+
/// Throw exception returned by function always when callback is called.
57+
/// </summary>
58+
/// <typeparam name="TException">The type of the exception.</typeparam>
59+
/// <param name="throwThis">The throw this.</param>
60+
/// <returns></returns>
61+
public static Callback AlwaysThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
62+
{
63+
return new ConfiguredCallback().AndAlways(ToCallback(throwThis));
64+
}
6565

66-
/// <summary>
67-
/// Throw this exception always when callback is called.
68-
/// </summary>
69-
/// <typeparam name="TException">The type of the exception.</typeparam>
70-
/// <param name="exception">The exception.</param>
71-
/// <returns></returns>
72-
public static Callback AlwaysThrow<TException>(TException exception) where TException : Exception
73-
{
74-
return AlwaysThrow(_ => exception);
75-
}
66+
/// <summary>
67+
/// Throw this exception always when callback is called.
68+
/// </summary>
69+
/// <typeparam name="TException">The type of the exception.</typeparam>
70+
/// <param name="exception">The exception.</param>
71+
/// <returns></returns>
72+
public static Callback AlwaysThrow<TException>(TException exception) where TException : Exception
73+
{
74+
return AlwaysThrow(_ => exception);
75+
}
7676

77-
protected static Action<CallInfo> ToCallback<TException>(Func<CallInfo, TException> throwThis)
78-
where TException : notnull, Exception
79-
{
80-
return ci => { if (throwThis != null) throw throwThis(ci); };
81-
}
77+
protected static Action<CallInfo> ToCallback<TException>(Func<CallInfo, TException> throwThis)
78+
where TException : notnull, Exception
79+
{
80+
return ci => { if (throwThis != null) throw throwThis(ci); };
81+
}
8282

83-
internal Callback() { }
84-
private readonly ConcurrentQueue<Action<CallInfo>> callbackQueue = new ConcurrentQueue<Action<CallInfo>>();
85-
private Action<CallInfo> alwaysDo = x => { };
86-
private Action<CallInfo> keepDoing = x => { };
83+
internal Callback() { }
84+
private readonly ConcurrentQueue<Action<CallInfo>> callbackQueue = new ConcurrentQueue<Action<CallInfo>>();
85+
private Action<CallInfo> alwaysDo = x => { };
86+
private Action<CallInfo> keepDoing = x => { };
8787

88-
protected void AddCallback(Action<CallInfo> doThis)
89-
{
90-
callbackQueue.Enqueue(doThis);
91-
}
88+
protected void AddCallback(Action<CallInfo> doThis)
89+
{
90+
callbackQueue.Enqueue(doThis);
91+
}
9292

93-
protected void SetAlwaysDo(Action<CallInfo> always)
93+
protected void SetAlwaysDo(Action<CallInfo> always)
94+
{
95+
alwaysDo = always ?? (_ => { });
96+
}
97+
98+
protected void SetKeepDoing(Action<CallInfo> keep)
99+
{
100+
keepDoing = keep ?? (_ => { });
101+
}
102+
103+
public void Call(CallInfo callInfo)
104+
{
105+
try
94106
{
95-
alwaysDo = always ?? (_ => { });
107+
CallFromStack(callInfo);
96108
}
97-
98-
protected void SetKeepDoing(Action<CallInfo> keep)
109+
finally
99110
{
100-
keepDoing = keep ?? (_ => { });
111+
alwaysDo(callInfo);
101112
}
113+
}
102114

103-
public void Call(CallInfo callInfo)
115+
private void CallFromStack(CallInfo callInfo)
116+
{
117+
if (callbackQueue.TryDequeue(out var callback))
104118
{
105-
try
106-
{
107-
CallFromStack(callInfo);
108-
}
109-
finally
110-
{
111-
alwaysDo(callInfo);
112-
}
119+
callback(callInfo);
113120
}
114-
115-
private void CallFromStack(CallInfo callInfo)
121+
else
116122
{
117-
if (callbackQueue.TryDequeue(out var callback))
118-
{
119-
callback(callInfo);
120-
}
121-
else
122-
{
123-
keepDoing(callInfo);
124-
}
123+
keepDoing(callInfo);
125124
}
126125
}
127126
}

src/NSubstitute/Callbacks/ConfiguredCallback.cs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,73 @@
33
// Disable nullability for client API, so it does not affect clients.
44
#nullable disable annotations
55

6-
namespace NSubstitute.Callbacks
6+
namespace NSubstitute.Callbacks;
7+
8+
public class ConfiguredCallback : EndCallbackChain
79
{
8-
public class ConfiguredCallback : EndCallbackChain
10+
internal ConfiguredCallback() { }
11+
12+
/// <summary>
13+
/// Perform this action once in chain of called callbacks.
14+
/// </summary>
15+
public ConfiguredCallback Then(Action<CallInfo> doThis)
916
{
10-
internal ConfiguredCallback() { }
17+
AddCallback(doThis);
18+
return this;
19+
}
1120

12-
/// <summary>
13-
/// Perform this action once in chain of called callbacks.
14-
/// </summary>
15-
public ConfiguredCallback Then(Action<CallInfo> doThis)
16-
{
17-
AddCallback(doThis);
18-
return this;
19-
}
21+
/// <summary>
22+
/// Keep doing this action after the other callbacks have run.
23+
/// </summary>
24+
public EndCallbackChain ThenKeepDoing(Action<CallInfo> doThis)
25+
{
26+
SetKeepDoing(doThis);
27+
return this;
28+
}
2029

21-
/// <summary>
22-
/// Keep doing this action after the other callbacks have run.
23-
/// </summary>
24-
public EndCallbackChain ThenKeepDoing(Action<CallInfo> doThis)
25-
{
26-
SetKeepDoing(doThis);
27-
return this;
28-
}
30+
/// <summary>
31+
/// Keep throwing this exception after the other callbacks have run.
32+
/// </summary>
33+
public EndCallbackChain ThenKeepThrowing<TException>(Func<CallInfo, TException> throwThis) where TException : Exception =>
34+
ThenKeepDoing(ToCallback(throwThis));
2935

30-
/// <summary>
31-
/// Keep throwing this exception after the other callbacks have run.
32-
/// </summary>
33-
public EndCallbackChain ThenKeepThrowing<TException>(Func<CallInfo, TException> throwThis) where TException : Exception =>
34-
ThenKeepDoing(ToCallback(throwThis));
36+
/// <summary>
37+
/// Keep throwing this exception after the other callbacks have run.
38+
/// </summary>
39+
public EndCallbackChain ThenKeepThrowing<TException>(TException throwThis) where TException : Exception =>
40+
ThenKeepThrowing(info => throwThis);
3541

36-
/// <summary>
37-
/// Keep throwing this exception after the other callbacks have run.
38-
/// </summary>
39-
public EndCallbackChain ThenKeepThrowing<TException>(TException throwThis) where TException : Exception =>
40-
ThenKeepThrowing(info => throwThis);
42+
/// <summary>
43+
/// Throw exception returned by function once when called in a chain of callbacks.
44+
/// </summary>
45+
/// <typeparam name="TException">The type of the exception</typeparam>
46+
/// <param name="throwThis">Produce the exception to throw for a CallInfo</param>
47+
public ConfiguredCallback ThenThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
48+
{
49+
AddCallback(ToCallback(throwThis));
50+
return this;
51+
}
4152

42-
/// <summary>
43-
/// Throw exception returned by function once when called in a chain of callbacks.
44-
/// </summary>
45-
/// <typeparam name="TException">The type of the exception</typeparam>
46-
/// <param name="throwThis">Produce the exception to throw for a CallInfo</param>
47-
public ConfiguredCallback ThenThrow<TException>(Func<CallInfo, TException> throwThis) where TException : Exception
48-
{
49-
AddCallback(ToCallback(throwThis));
50-
return this;
51-
}
53+
/// <summary>
54+
/// Throw this exception once when called in a chain of callbacks.
55+
/// </summary>
56+
/// <typeparam name="TException">The type of the exception</typeparam>
57+
/// <param name="exception">The exception to throw</param>
58+
public ConfiguredCallback ThenThrow<TException>(TException exception) where TException : Exception =>
59+
ThenThrow(_ => exception);
60+
}
5261

53-
/// <summary>
54-
/// Throw this exception once when called in a chain of callbacks.
55-
/// </summary>
56-
/// <typeparam name="TException">The type of the exception</typeparam>
57-
/// <param name="exception">The exception to throw</param>
58-
public ConfiguredCallback ThenThrow<TException>(TException exception) where TException : Exception =>
59-
ThenThrow(_ => exception);
60-
}
62+
public class EndCallbackChain : Callback
63+
{
64+
internal EndCallbackChain() { }
6165

62-
public class EndCallbackChain : Callback
66+
/// <summary>
67+
/// Perform the given action for every call.
68+
/// </summary>
69+
/// <param name="doThis">The action to perform for every call</param>
70+
public Callback AndAlways(Action<CallInfo> doThis)
6371
{
64-
internal EndCallbackChain() { }
65-
66-
/// <summary>
67-
/// Perform the given action for every call.
68-
/// </summary>
69-
/// <param name="doThis">The action to perform for every call</param>
70-
public Callback AndAlways(Action<CallInfo> doThis)
71-
{
72-
SetAlwaysDo(doThis);
73-
return this;
74-
}
72+
SetAlwaysDo(doThis);
73+
return this;
7574
}
7675
}

0 commit comments

Comments
 (0)