Skip to content

Commit

Permalink
Add test for additional WithArgs overload
Browse files Browse the repository at this point in the history
  • Loading branch information
afscrome committed Sep 9, 2024
1 parent d85371b commit 8132c74
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions tests/Aspire.Hosting.Tests/ExecutableResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ public async Task AddExecutableWithArgs()
});

var exe2 = appBuilder.AddExecutable("e2", "python", ".", "app.py")
.WithArgs(context =>
{
context.Args.Add("arg1");
context.Args.Add(exe1.GetEndpoint("ep"));
context.Args.Add(testResource);
});
.WithArgs("arg1", exe1.GetEndpoint("ep"), testResource);

using var app = appBuilder.Build();

Expand Down Expand Up @@ -61,6 +56,39 @@ public async Task AddExecutableWithArgs()
Assert.Equal(expectedManifest, manifest.ToString());
}

[Fact]
public async Task AddExecutableWithArgsCallback()
{
var appBuilder = DistributedApplication.CreateBuilder();

var testResource = new TestResource("test", "connectionString");

var exe1 = appBuilder.AddExecutable("e1", "ruby", ".", "app.rb")
.WithEndpoint("ep", e =>
{
e.UriScheme = "http";
e.AllocatedEndpoint = new(e, "localhost", 1234);
});

var exe2 = appBuilder.AddExecutable("e2", "python", ".", "app.py")
.WithArgs(context =>
{
context.Args.Add("arg1");
context.Args.Add(exe1.GetEndpoint("ep"));
context.Args.Add(testResource);
});

using var app = appBuilder.Build();

var args = await ArgumentEvaluator.GetArgumentListAsync(exe2.Resource);

Assert.Collection(args,
arg => Assert.Equal("app.py", arg),
arg => Assert.Equal("arg1", arg),
arg => Assert.Equal("http://localhost:1234", arg),
arg => Assert.Equal("connectionString", arg));
}

private sealed class TestResource(string name, string connectionString) : Resource(name), IResourceWithConnectionString
{
public ReferenceExpression ConnectionStringExpression =>
Expand Down

0 comments on commit 8132c74

Please sign in to comment.