Skip to content

Commit 253a8f0

Browse files
committed
throw if argument is null
1 parent aa877b2 commit 253a8f0

File tree

2 files changed

+57
-1
lines changed
  • src/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi
  • tests/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi

2 files changed

+57
-1
lines changed

src/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi/AssemblyLoader.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public static TResult UsingAssembly<TArg, TResult>(
3232
ILogger? logger = null
3333
)
3434
{
35+
if (assemblyFile is null)
36+
throw new ArgumentNullException(nameof(assemblyFile));
37+
3538
return UsingAssemblyCore(
3639
new(
3740
ComponentAssemblyPath: assemblyFile.FullName,
@@ -61,7 +64,7 @@ public static TResult UsingAssembly<TArg, TResult>(
6164
return UsingAssemblyCore(
6265
new(
6366
ComponentAssemblyPath: componentAssemblyPath ?? throw new ArgumentNullException(nameof(componentAssemblyPath)),
64-
Stream: assemblyStream
67+
Stream: assemblyStream ?? throw new ArgumentNullException(nameof(assemblyStream))
6568
),
6669
loadIntoReflectionOnlyContext,
6770
arg,

tests/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi/AssemblyLoader.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,59 @@ public void Init()
3838
logger = services.BuildServiceProvider().GetService<ILoggerFactory>()?.CreateLogger("test");
3939
}
4040

41+
[Test]
42+
public void UsingAssembly_ArgumentNull_AssemblyFile(
43+
[Values(true, false)] bool loadIntoReflectionOnlyContext
44+
)
45+
{
46+
Assert.Throws<ArgumentNullException>(() => {
47+
AssemblyLoader.UsingAssembly(
48+
assemblyFile: null!,
49+
loadIntoReflectionOnlyContext: loadIntoReflectionOnlyContext,
50+
arg: 0,
51+
(assm, arg) => arg,
52+
context: out _,
53+
logger: null
54+
);
55+
});
56+
}
57+
58+
[Test]
59+
public void UsingAssembly_ArgumentNull_AssemblyStream(
60+
[Values(true, false)] bool loadIntoReflectionOnlyContext
61+
)
62+
{
63+
Assert.Throws<ArgumentNullException>(() => {
64+
AssemblyLoader.UsingAssembly(
65+
assemblyStream: null!,
66+
componentAssemblyPath: string.Empty,
67+
loadIntoReflectionOnlyContext: loadIntoReflectionOnlyContext,
68+
arg: 0,
69+
(assm, arg) => arg,
70+
context: out _,
71+
logger: null
72+
);
73+
});
74+
}
75+
76+
[Test]
77+
public void UsingAssembly_ArgumentNull_ComponentAssemblyPath(
78+
[Values(true, false)] bool loadIntoReflectionOnlyContext
79+
)
80+
{
81+
Assert.Throws<ArgumentNullException>(() => {
82+
AssemblyLoader.UsingAssembly(
83+
assemblyStream: Stream.Null,
84+
componentAssemblyPath: null!,
85+
loadIntoReflectionOnlyContext: loadIntoReflectionOnlyContext,
86+
arg: 0,
87+
(assm, arg) => arg,
88+
context: out _,
89+
logger: null
90+
);
91+
});
92+
}
93+
4194
#if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER
4295
[TestCase(true, "netstandard2.1")]
4396
[TestCase(false, "netstandard2.1")]

0 commit comments

Comments
 (0)