Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code analysis errors #1286

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static async Task PopulateExistingAspireResources<TResource>(
}
}

internal async Task<UserPrincipal> GetUserPrincipalAsync(TokenCredential credential, CancellationToken cancellationToken)
internal static async Task<UserPrincipal> GetUserPrincipalAsync(TokenCredential credential, CancellationToken cancellationToken)
{
var response = await credential.GetTokenAsync(new(["https://graph.windows.net/.default"]), cancellationToken).ConfigureAwait(false);

Expand Down
24 changes: 0 additions & 24 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ public async Task RunApplicationAsync(CancellationToken cancellationToken = defa
PrepareServices();
PrepareContainers();
PrepareExecutables();
// PrepareProxylessServices();

// await CreateContainerSingletonsAsync(cancellationToken).ConfigureAwait(false);

await CreateServicesAsync(cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -106,13 +103,6 @@ public async Task StopApplicationAsync(CancellationToken cancellationToken = def
}
}

private async Task CreateContainerSingletonsAsync(CancellationToken cancellationToken = default)
{
// Find containers that consume no Services--their associated Services can be started in Proxyless mode
var toCreate = _appResources.Where(r => r.DcpResource is Container && !r.ServicesConsumed.Any());
await CreateContainersAsync(toCreate, cancellationToken).ConfigureAwait(false);
}

JamesNK marked this conversation as resolved.
Show resolved Hide resolved
private async Task CreateServicesAsync(CancellationToken cancellationToken = default)
{
try
Expand Down Expand Up @@ -340,20 +330,6 @@ private void PrepareProjectExecutables()
}
}

private void PrepareProxylessServices()
{
// Find containers that consume no Services--their associated Services can be started in Proxyless mode
var singletonContainers = _appResources.Where(r => r.DcpResource is Container && !r.ServicesConsumed.Any());

foreach (var container in singletonContainers)
{
foreach (var service in container.ServicesProduced)
{
service.Service.Spec.AddressAllocationMode = AddressAllocationModes.Proxyless;
}
}
}

private async Task CreateExecutablesAsync(IEnumerable<AppResource> executableResources, CancellationToken cancellationToken)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationT
return Task.CompletedTask;
}

private void PrepareServices(DistributedApplicationModel model)
private static void PrepareServices(DistributedApplicationModel model)
{
// Automatically add ServiceBindingAnnotations to project resources based on ApplicationUrl set in the launch profile.
foreach (var projectResource in model.Resources.OfType<ProjectResource>())
Expand Down
6 changes: 3 additions & 3 deletions src/Aspire.Hosting/Publishing/ManifestPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected async Task WriteManifestAsync(DistributedApplicationModel model, Utf8J
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
}

private void WriteResources(DistributedApplicationModel model, ManifestPublishingContext context)
private static void WriteResources(DistributedApplicationModel model, ManifestPublishingContext context)
{
context.Writer.WriteStartObject("resources");
foreach (var resource in model.Resources)
Expand All @@ -65,7 +65,7 @@ private void WriteResources(DistributedApplicationModel model, ManifestPublishin
context.Writer.WriteEndObject();
}

private void WriteResource(IResource resource, ManifestPublishingContext context)
private static void WriteResource(IResource resource, ManifestPublishingContext context)
{
// First see if the resource has a callback annotation with overrides the behavior for rendering
// out the JSON. If so use that callback, otherwise use the fallback logic that we have.
Expand Down Expand Up @@ -123,7 +123,7 @@ private static void WriteProject(ProjectResource project, ManifestPublishingCont
context.WriteBindings(project);
}

private void WriteExecutable(ExecutableResource executable, ManifestPublishingContext context)
private static void WriteExecutable(ExecutableResource executable, ManifestPublishingContext context)
{
context.Writer.WriteString("type", "executable.v0");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void EmptyAttributes_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([], out var name));
Assert.False(resolver.TryResolvePeerName([], out _));
}

[Fact]
Expand All @@ -25,7 +25,7 @@ public void EmptyUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "")], out _));
}

[Fact]
Expand All @@ -35,7 +35,7 @@ public void NullUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create<string, string>("http.url", null!)], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create<string, string>("http.url", null!)], out _));
}

// http://localhost:59267/6eed7c2dedc14419901b813e8fe87a86/getScriptTag
Expand All @@ -47,7 +47,7 @@ public void RelativeUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out _));
}

[Fact]
Expand All @@ -57,7 +57,7 @@ public void NonLocalHostUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://dummy:59267/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://dummy:59267/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out _));
}

[Fact]
Expand All @@ -67,7 +67,7 @@ public void NoPathGuidUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/getScriptTag")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/getScriptTag")], out _));
}

[Fact]
Expand All @@ -77,7 +77,7 @@ public void InvalidUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "ht$tp://localhost:59267/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "ht$tp://localhost:59267/6eed7c2dedc14419901b813e8fe87a86/getScriptTag")], out _));
}

[Fact]
Expand All @@ -87,7 +87,7 @@ public void NoPathUrlAttribute_Match()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/")], out _));
}

[Fact]
Expand All @@ -97,7 +97,7 @@ public void GuidPathUrlAttribute_NoMatch()
var resolver = new BrowserLinkOutgoingPeerResolver();

// Act & Assert
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/not-a-guid/getScriptTag")], out var name));
Assert.False(resolver.TryResolvePeerName([KeyValuePair.Create("http.url", "http://localhost:59267/not-a-guid/getScriptTag")], out _));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void AddLogs_Error_UnviewedCount_WithNonReadSubscription()
}

[Fact]
private void GetLogs_UnknownApplication()
public void GetLogs_UnknownApplication()
{
// Arrange
var repository = CreateRepository();
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,4 @@ private static TestProgram CreateTestProgramJsonDocumentManifestPublisher(bool i
program.AppBuilder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, JsonDocumentManifestPublisher>("manifest");
return program;
}

private static TestProgram CreateTestProgram(string[]? args = null) => TestProgram.Create<ManifestGenerationTests>(args);
}
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Tests/ProjectResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void ProjectWithoutServiceMetadataFailsWithLaunchProfile()
Assert.Equal("Project does not contain service metadata.", ex.Message);
}

private IDistributedApplicationBuilder CreateBuilder()
private static IDistributedApplicationBuilder CreateBuilder()
{
var appBuilder = DistributedApplication.CreateBuilder(["--publisher", "manifest"]);
// Block DCP from actually starting anything up as we don't need it for this test.
Expand Down