Skip to content

Commit

Permalink
Fix Template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Jun 14, 2024
1 parent de4c97a commit 456ee28
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public static ControllerActionEndpointConventionBuilder MapControllers(this IEnd
EnsureControllerServices(endpoints);

var result = GetOrCreateDataSource(endpoints).DefaultBuilder;
result.Items["__EndpointRouteBuilder"] = endpoints;
if (!result.Items.ContainsKey("__EndpointRouteBuilder"))
{
result.Items["__EndpointRouteBuilder"] = endpoints;
}

return result;
}

Expand All @@ -48,7 +52,10 @@ public static ControllerActionEndpointConventionBuilder MapDefaultControllerRout
EnsureControllerServices(endpoints);

var dataSource = GetOrCreateDataSource(endpoints);
dataSource.DefaultBuilder.Items["__EndpointRouteBuilder"] = endpoints;
if (!dataSource.DefaultBuilder.Items.ContainsKey("__EndpointRouteBuilder"))
{
dataSource.DefaultBuilder.Items["__EndpointRouteBuilder"] = endpoints;
}

return dataSource.AddRoute(
"default",
Expand Down Expand Up @@ -94,7 +101,10 @@ public static ControllerActionEndpointConventionBuilder MapControllerRoute(
EnsureControllerServices(endpoints);

var dataSource = GetOrCreateDataSource(endpoints);
dataSource.DefaultBuilder.Items["__EndpointRouteBuilder"] = endpoints;
if (!dataSource.DefaultBuilder.Items.ContainsKey("__EndpointRouteBuilder"))
{
dataSource.DefaultBuilder.Items["__EndpointRouteBuilder"] = endpoints;
}

return dataSource.AddRoute(
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ public static PageActionEndpointConventionBuilder WithStaticAssets(
{
ArgumentNullException.ThrowIfNull(builder);

var endpointBuilder = builder.Items["__EndpointRouteBuilder"];
var (resolver, registered) = builder.Items.TryGetValue("__ResourceCollectionResolver", out var value)
if (builder.Items.TryGetValue("__EndpointRouteBuilder", out var endpointBuilder))
{
var (resolver, registered) = builder.Items.TryGetValue("__ResourceCollectionResolver", out var value)
? ((ResourceCollectionResolver)value, true)
: (new ResourceCollectionResolver((IEndpointRouteBuilder)endpointBuilder), false);

resolver.ManifestName = manifestPath;
if (!registered)
{
var collection = resolver.ResolveResourceCollection();
var importMap = resolver.ResolveImportMap();

builder.Add(endpointBuilder =>
resolver.ManifestName = manifestPath;
if (!registered)
{
endpointBuilder.Metadata.Add(collection);
endpointBuilder.Metadata.Add(importMap);
});
var collection = resolver.ResolveResourceCollection();
var importMap = resolver.ResolveImportMap();

builder.Add(endpointBuilder =>
{
endpointBuilder.Metadata.Add(collection);
endpointBuilder.Metadata.Add(importMap);
});
}
}

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,30 @@ public static ControllerActionEndpointConventionBuilder WithStaticAssets(
{
ArgumentNullException.ThrowIfNull(builder);

var endpointBuilder = builder.Items["__EndpointRouteBuilder"];
var (resolver, registered) = builder.Items.TryGetValue("__ResourceCollectionResolver", out var value)
? ((ResourceCollectionResolver)value, true)
: (new ResourceCollectionResolver((IEndpointRouteBuilder)endpointBuilder), false);

resolver.ManifestName = manifestPath;
if (!registered)
if (builder.Items.TryGetValue("__EndpointRouteBuilder", out var endpointBuilder))
{
var collection = resolver.ResolveResourceCollection();
var importMap = resolver.ResolveImportMap();
var (resolver, registered) = builder.Items.TryGetValue("__ResourceCollectionResolver", out var value)
? ((ResourceCollectionResolver)value, true)
: (new ResourceCollectionResolver((IEndpointRouteBuilder)endpointBuilder), false);

builder.Add(endpointBuilder =>
resolver.ManifestName = manifestPath;
if (!registered)
{
// Do not add metadata to API controllers
if (endpointBuilder.Metadata.OfType<ApiControllerAttribute>().Any())
{
return;
}
var collection = resolver.ResolveResourceCollection();
var importMap = resolver.ResolveImportMap();

endpointBuilder.Metadata.Add(collection);
endpointBuilder.Metadata.Add(importMap);
});
builder.Add(endpointBuilder =>
{
// Do not add metadata to API controllers
if (endpointBuilder.Metadata.OfType<ApiControllerAttribute>().Any())
{
return;
}
endpointBuilder.Metadata.Add(collection);
endpointBuilder.Metadata.Add(importMap);
});
}
}

return builder;
Expand Down

0 comments on commit 456ee28

Please sign in to comment.