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

Change Aspire RunSessionRequest definition #45515

Merged
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
Change Aspire RunSessionRequest definition
  • Loading branch information
tlmii committed Dec 17, 2024
commit 4f4de87e3e986737dae0e782f4a48ca897e2cca1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal class RunSessionRequest
public EnvVar[] Environment { get; set; } = Array.Empty<EnvVar>();

[JsonPropertyName("args")]
public string[] Arguments { get; set; } = Array.Empty<string>();
public string[]? Arguments { get; set; }

public ProjectLaunchRequest? ToProjectLaunchInformation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class AspireServerServiceTests(ITestOutputHelper output)
env = new List<EnvVar> { new EnvVar { Name = "var1", Value = "value1" } }
};

private static readonly TestRunSessionRequest Project2SessionRequest = new TestRunSessionRequest(Project1Path, debugging: false, launchProfile: null, disableLaunchProfile: false)
{
args = null,
env = new List<EnvVar> { new EnvVar { Name = "var1", Value = "value1" } }
};

[Fact]
public async Task SessionStarted_Test()
{
Expand Down Expand Up @@ -111,6 +117,30 @@ public async Task LaunchProject_Success()
mocks.Verify();
}

[Fact]
public async Task LaunchProject_WithNullArgs_PassesThroughNullArgs()
{
var mocks = new Mocks();

mocks.GetOrCreate<IAspireServerEventsMock>()
.ImplementStartProjectAsync(DcpId, "2", requireNullArguments: true);

var server = await GetAspireServer(mocks);
var tokens = server.GetServerVariables();

using HttpClient client = GetHttpClient(tokens);

HttpResponseMessage response;
response = await client.PutAsJsonAsync(VersionedSessionUrl, Project2SessionRequest);

Assert.Equal(HttpStatusCode.Created, response.StatusCode);
Assert.Equal($"{client.BaseAddress}run_session/2", response.Headers.Location.AbsoluteUri);

await server.DisposeAsync();

mocks.Verify();
}

[Fact]
public async Task LaunchProject_Success_ThenStopProcessRequest()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

using Moq;
using Moq.Language.Flow;

namespace Aspire.Tools.Service.UnitTests;

Expand All @@ -11,19 +12,28 @@ public IAspireServerEventsMock(Mocks mocks, MockBehavior? mockBehavior = null)
{
}

public IAspireServerEventsMock ImplementStartProjectAsync(string dcpId, string sessionId, Exception? ex = null)
public IAspireServerEventsMock ImplementStartProjectAsync(string dcpId, string sessionId, Exception? ex = null, bool requireNullArguments = false)
{
MockObject.Setup(x => x.StartProjectAsync(dcpId, It.IsAny<ProjectLaunchRequest>(), It.IsAny<CancellationToken>()))
.Returns(() =>
{
if (ex is not null)
{
throw ex;
}
ISetup<IAspireServerEvents, ValueTask<string>> setup;
if (requireNullArguments)
{
setup = MockObject.Setup(x => x.StartProjectAsync(dcpId, It.Is<ProjectLaunchRequest>(plr => plr.Arguments == null), It.IsAny<CancellationToken>()));
}
else
{
setup = MockObject.Setup(x => x.StartProjectAsync(dcpId, It.IsAny<ProjectLaunchRequest>(), It.IsAny<CancellationToken>()));
}

setup.Returns(() =>
{
if (ex is not null)
{
throw ex;
}

return new ValueTask<string>(sessionId);
}).Verifiable();

return new ValueTask<string>(sessionId);
})
.Verifiable();
return this;
}

Expand Down
Loading