-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend assembly assertions with
BeSignedWithPublicKey
and `BeUnsign…
…ed` (#2207)
- Loading branch information
Showing
13 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,50 @@ | ||
using System.Reflection; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace FluentAssertions.Specs; | ||
|
||
public static class FindAssembly | ||
{ | ||
public static Assembly Containing<T>() | ||
public static Assembly Containing<T>() => typeof(T).Assembly; | ||
|
||
public static Assembly Stub(string publicKey) => new AssemblyStub(publicKey); | ||
|
||
private sealed class AssemblyStub : Assembly | ||
{ | ||
return typeof(T).Assembly; | ||
private readonly AssemblyName assemblyName = new(); | ||
|
||
public override string FullName => nameof(AssemblyStub); | ||
|
||
public AssemblyStub(string publicKey) | ||
{ | ||
assemblyName.SetPublicKey(FromHexString(publicKey)); | ||
} | ||
|
||
public override AssemblyName GetName() => assemblyName; | ||
|
||
#if NET6_0_OR_GREATER | ||
private static byte[] FromHexString(string chars) | ||
=> chars is null | ||
? null | ||
: Convert.FromHexString(chars); | ||
#else | ||
private static byte[] FromHexString(string chars) | ||
{ | ||
if (chars is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var bytes = new byte[chars.Length / 2]; | ||
|
||
for (var i = 0; i < bytes.Length; i++) | ||
{ | ||
var bits = chars.Substring(i * 2, 2); | ||
bytes[i] = Convert.ToByte(bits, 16); | ||
} | ||
|
||
return bytes; | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters