Skip to content

Commit

Permalink
Merge branch 'restier-beta2'
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmclaws committed Apr 11, 2021
2 parents de3bc84 + 2ceed2e commit dd377ae
Show file tree
Hide file tree
Showing 80 changed files with 1,937 additions and 2,133 deletions.
11 changes: 0 additions & 11 deletions DeployNuGet.bat

This file was deleted.

10 changes: 10 additions & 0 deletions NuGet.Config
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>
4 changes: 4 additions & 0 deletions src/.editorconfig
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
6 changes: 0 additions & 6 deletions src/CloudNimble.Breakdance.Assemblies/AssemblyInfo.cs

This file was deleted.

46 changes: 33 additions & 13 deletions src/CloudNimble.Breakdance.Assemblies/Breakdance.Assemblies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<RootNamespace>CloudNimble.Breakdance.Assemblies</RootNamespace>
<AssemblyName>CloudNimble.Breakdance.Assemblies</AssemblyName>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net472;netstandard2.0;net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -31,27 +31,47 @@
1.0.0-alpha1:
- Initial release.
</PackageReleaseNotes>
</PropertyGroup>



<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net46|AnyCPU'">
<NoWarn>;NU5125;NU5105;NU5048;NU5014;NU5104;CS0649</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="[2.2.0, 6.0.0)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="[2.2.0, 6.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.NETCore.Platforms" Version="1.1" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="[1.1.0, 6.0.0)" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Collections.NonGeneric" Version="[4.3.0, 6.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<PackageReference Include="Microsoft.NETCore.Platforms" Version="[3.1.3, 6.0.0)" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="[4.7.0, 6.0.0)" />
<PackageReference Include="System.Threading.Tasks" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Threading.Tasks.Parallel" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Reflection" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Reflection.Primitives" Version="[4.3.0, 6.0.0)" />
<PackageReference Include="System.Threading.Tasks" Version="[4.3.0, 6.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>CloudNimble.Breakdance.Tests.Assemblies, PublicKey=002400000480000094000000060200000024000052534131000400000100010019716104c2a5bbd61d08e1c8ece3d4c8f1ed31e923438d04be62e6be757659457ba97931e75d3182ae93c5bf2259e5804e4d71c4b333648ef1e56bdb8b83391c6ddcea54fbc74474832789c38c7c208298006805721bf5ac6907491d4f1189d06564aa4f7f5e1ca9ad6ce766e8f10b70e2cecc52ce4d42feee42552b1fdd7fad</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Threading.Tasks" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
<PackageReference Include="System.Reflection.Primitives" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks" Version="4.3.0" />
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
</ItemGroup>



</Project>
22 changes: 22 additions & 0 deletions src/CloudNimble.Breakdance.Assemblies/BreakdanceAttributes.cs
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
{
}

}
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));
}

}

}
10 changes: 10 additions & 0 deletions src/CloudNimble.Breakdance.Assemblies/Comparers/MemberComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public int Compare(object x, object y)
/// <returns></returns>
public int Compare(MemberInfo x, MemberInfo y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}

if (y == null)
{
throw new ArgumentNullException(nameof(y));
}

if (x.MemberType == y.MemberType)
{
Type xt = x.DeclaringType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ sealed public class ObjectTypeComparer : IComparer, IComparer<object>
/// <returns></returns>
public int Compare(object x, object y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}

if (y == null)
{
throw new ArgumentNullException(nameof(y));
}

string a = x.GetType().FullName;
string b = y.GetType().FullName;
int ac = 0, bc = 0;
Expand Down
14 changes: 12 additions & 2 deletions src/CloudNimble.Breakdance.Assemblies/Comparers/TypeComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ sealed public class TypeComparer : IComparer

#region Private Members

private static bool AlphabeticalGrouping = false;
private const bool AlphabeticalGrouping = false;

#endregion

/// <summary>
///
/// </summary>
Expand All @@ -34,6 +34,16 @@ sealed public class TypeComparer : IComparer
/// <returns></returns>
public int Compare(object x, object y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}

if (y == null)
{
throw new ArgumentNullException(nameof(y));
}

Type a = x as Type;
Type b = y as Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MemberDefinition
/// <summary>
/// A <see cref="List{String}"/> containging the full name of each attribute on the type member.
/// </summary>
public List<string> Attributes { get; set; }
public List<string> Attributes { get; private set; }

/// <summary>
/// The full name of the type member in question.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TypeDefinition
/// <summary>
/// A <see cref="List{String}"/> containging the full name of each attribute on the type.
/// </summary>
public List<string> Attributes { get; set; }
public List<string> Attributes { get; private set; }

/// <summary>
/// The full name of the type member in question.
Expand All @@ -24,7 +24,7 @@ public class TypeDefinition
/// <summary>
///
/// </summary>
public List<MemberDefinition> Members { get; set; }
public List<MemberDefinition> Members { get; private set; }

#endregion

Expand Down
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;
}

}

}

0 comments on commit dd377ae

Please sign in to comment.