-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
1,937 additions
and
2,133 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<solution> | ||
<add key="disableSourceControlIntegration" value="true" /> | ||
</solution> | ||
<packageSources> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="Restier Nightly" value="https://www.myget.org/F/restier-nightly/api/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# CA1031: Do not catch general exception types | ||
dotnet_diagnostic.CA1031.severity = suggestion |
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
src/CloudNimble.Breakdance.Assemblies/BreakdanceAttributes.cs
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace CloudNimble.Breakdance.Assemblies | ||
{ | ||
|
||
/// <summary> | ||
/// Tells Breakdance that the attributed method generates a manifest file that is used to test functional outputs. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] | ||
public sealed class BreakdanceManifestGeneratorAttribute : Attribute | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Tells Breakdance that the attributed method generates a manifest file that is used to test functional outputs. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] | ||
public sealed class BreakdanceTestAssemblyAttribute : Attribute | ||
{ | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/CloudNimble.Breakdance.Assemblies/ClaimsPrincipalTestHelpers.cs
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace System.Security.Claims | ||
{ | ||
|
||
/// <summary> | ||
/// A set of helpers to make it easier to test code that calls <see cref="ClaimsPrincipal.Current" />. | ||
/// </summary> | ||
public static class ClaimsPrincipalTestHelpers | ||
{ | ||
|
||
/// <summary> | ||
/// Sets the <see cref="ClaimsPrincipal.ClaimsPrincipalSelector"/> to a new ClaimsIdentity with the specified claims. | ||
/// </summary> | ||
/// <param name="claims">The Claims to set for the test run.</param> | ||
/// <param name="authenticationType">If needed, the AuthenticationType of the ClaimsIdentity. Defaults to "BreakdanceTests".</param> | ||
/// <param name="nameType">The ClaimType to specify for the Name claim. Defaults to <see cref="ClaimTypes.NameIdentifier"/>.</param> | ||
/// <param name="roleType">The ClaimType to specify for Role claims. Defaults to <see cref="ClaimTypes.Role"/>.</param> | ||
public static void SetSelector(List<Claim> claims, string authenticationType = "BreakdanceTests", string nameType = ClaimTypes.NameIdentifier, string roleType = ClaimTypes.Role) | ||
{ | ||
ClaimsPrincipal.ClaimsPrincipalSelector = () => new ClaimsPrincipal(new ClaimsIdentity(claims, authenticationType, nameType, roleType)); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the <see cref="ClaimsPrincipal.ClaimsPrincipalSelector"/> to a new ClaimsIdentity with the specified claims. | ||
/// </summary> | ||
/// <param name="claim">The Claims to set for the test run.</param> | ||
/// <param name="authenticationType">If needed, the AuthenticationType of the ClaimsIdentity. Defaults to "BreakdanceTests".</param> | ||
/// <param name="nameType">The ClaimType to specify for the Name claim. Defaults to <see cref="ClaimTypes.NameIdentifier"/>.</param> | ||
/// <param name="roleType">The ClaimType to specify for Role claims. Defaults to <see cref="ClaimTypes.Role"/>.</param> | ||
public static void SetSelector(Claim claim, string authenticationType = "BreakdanceTests", string nameType = ClaimTypes.NameIdentifier, string roleType = ClaimTypes.Role) | ||
{ | ||
ClaimsPrincipal.ClaimsPrincipalSelector = () => new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { claim }, authenticationType, nameType, roleType)); | ||
} | ||
|
||
} | ||
|
||
} |
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
119 changes: 119 additions & 0 deletions
119
src/CloudNimble.Breakdance.Assemblies/DependencyInjectionTestHelpers.cs
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace CloudNimble.Breakdance.Assemblies | ||
{ | ||
|
||
/// <summary> | ||
/// A set of utilities for Breakdance that help you verify Dependency Injection configurations, especially in architrectures sensitive to injection order. | ||
/// </summary> | ||
public static class DependencyInjectionTestHelpers | ||
{ | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="collection"></param> | ||
public static string GetContainerContentsLog(ServiceCollection collection) | ||
{ | ||
if (collection == null) | ||
{ | ||
throw new ArgumentNullException(nameof(collection)); | ||
} | ||
|
||
return collection.ToList().ToDetailedString(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="provider"></param> | ||
public static string GetContainerContentsLog(IServiceProvider provider) | ||
{ | ||
if (provider == null) | ||
{ | ||
throw new ArgumentNullException(nameof(provider)); | ||
} | ||
|
||
var dictionary = provider.GetAllServiceDescriptors(); | ||
return dictionary.Select(c => c.Value).ToList().ToDetailedString(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="hostBuilder"></param> | ||
public static string GetContainerContentsLog(IHostBuilder hostBuilder) | ||
{ | ||
if (hostBuilder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(hostBuilder)); | ||
} | ||
|
||
var dictionary = hostBuilder.GetAllServiceDescriptors(); | ||
return dictionary.Select(c => c.Value).ToList().ToDetailedString(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="func"></param> | ||
/// <returns></returns> | ||
private static string FuncToString(Func<IServiceProvider, object> func) | ||
{ | ||
if (func == null) | ||
{ | ||
return "None"; | ||
} | ||
Expression<Func<IServiceProvider, object>> expression = (x) => func; | ||
return expression.Body.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="list"></param> | ||
/// <returns></returns> | ||
private static string ToDetailedString(this List<ServiceDescriptor> list) | ||
{ | ||
if (list == null || !list.Any()) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var serviceTypeLength = list.Select(c => c.ServiceType.ToString().Length).OrderByDescending(c => c).First(); | ||
var implementationTypeLength = list.Select(c => c.ImplementationType?.ToString()?.Length ?? 0).OrderByDescending(c => c).First(); | ||
|
||
var sb = new StringBuilder(); | ||
|
||
list.ForEach(c => | ||
{ | ||
sb.Append($"Lifetime: {c.Lifetime,-9} | ServiceType: "); | ||
sb.AppendFormat(GetFormatString(0, -serviceTypeLength), c.ServiceType.ToString()); | ||
sb.Append(" | ImplementationType: "); | ||
sb.AppendFormat(GetFormatString(0, -implementationTypeLength), c.ImplementationType?.ToString() ?? "None"); | ||
sb.Append($" | ImplementationFactory: {FuncToString(c.ImplementationFactory)}\n"); | ||
}); | ||
return sb.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="index"></param> | ||
/// <param name="spacing"></param> | ||
/// <returns></returns> | ||
private static string GetFormatString(int index, int spacing) | ||
{ | ||
var test = $"{{{index}, {spacing}}}"; | ||
return test; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.