Skip to content

Commit

Permalink
fix actual endpoint selection, ignore global in usings, fix additiona…
Browse files Browse the repository at this point in the history
…l types detection when changing to type with properties
  • Loading branch information
Daninator1 committed Mar 31, 2022
1 parent 8dfbf14 commit f51c4e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions Breaker.Logic/Comparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ private static readonly (string name, bool removeAllowed)[] CheckedAttributes =
("FromServices", false)
};

private static EndpointDetails GetActualEndpoint(EndpointDetails expectedEndpoint, IReadOnlyCollection<EndpointDetails> actualEndpoints)
private static EndpointDetails GetActualEndpoint(EndpointDetails expectedEndpoint, IReadOnlyCollection<EndpointDetails> actualEndpoints, IReadOnlyCollection<EndpointDetails> expectedEndpoints)
{
var possibleActualEndpoints = actualEndpoints.Where(a
=> IsOneHttpMethodRouteEqual(a.HttpMethodSpecificRoutes, expectedEndpoint.HttpMethodSpecificRoutes)).ToList();

return possibleActualEndpoints.Count > 1
return expectedEndpoints.Count > 1 && actualEndpoints.Count == 1 || possibleActualEndpoints.Count > 1
? possibleActualEndpoints.SingleOrDefault(a => a.Identifier.ValueText == expectedEndpoint.Identifier.ValueText)
: possibleActualEndpoints.FirstOrDefault();

Expand Down Expand Up @@ -87,7 +87,8 @@ private static (string Namespace, string BaseRoute, ClassDeclarationSyntax Contr
var actualEndpoint = actualEndpointsGroup is null
? null
: GetActualEndpoint(expectedEndpoint,
actualEndpointsGroup.Select(x => x).ToList());
actualEndpointsGroup.Select(x => x).ToList(),
expectedEndpointsGroup.Select(x => x).ToList());

if (actualEndpoint is null)
{
Expand Down Expand Up @@ -194,14 +195,14 @@ private static (string Namespace, string BaseRoute, ClassDeclarationSyntax Contr
var additionalTypes = actualTypes
.Where(a
=> expectedTypes.All(e
=> (e.PropertyTypes is null && a.Type.Text != e.Type.Text) || a.IsNullable != e.IsNullable ||
=> (e.PropertyTypes is null) && a.Type.Text != e.Type.Text || a.IsNullable != e.IsNullable ||
a.Identifier.ValueText != e.Identifier.ValueText))
.ToList();

foreach (var expectedType in expectedTypes)
{
var actualType = actualTypes.SingleOrDefault(p
=> ((p.PropertyTypes is not null && expectedType.PropertyTypes is not null) ||
=> ((expectedType.PropertyTypes is not null) ||
p.Type.Text == expectedType.Type.Text) && p.IsNullable == expectedType.IsNullable &&
p.Identifier.ValueText == expectedType.Identifier.ValueText);

Expand Down
4 changes: 3 additions & 1 deletion Breaker.Logic/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private static string GetNamespace(this SyntaxNode node,
var compilationUsings = node.Ancestors().OfType<CompilationUnitSyntax>().Single().Usings
.Select(u => u.Name.ToString());

var usings = compilationUsings.Concat(classNamespace.Usings.Select(u => u.Name.ToString()));
var usings = compilationUsings
.Concat(classNamespace.Usings.Select(u => u.Name.ToString()))
.Select(s => s.Replace("global::", ""));

return possibleClassesAndNamespaces.Single(x => usings.Contains(x.possibleNamespace)).possibleNamespace;
}
Expand Down

0 comments on commit f51c4e9

Please sign in to comment.