|
| 1 | +namespace Luma.IntegrationTests; |
| 2 | + |
| 3 | +public partial class Tests |
| 4 | +{ |
| 5 | + [TestMethod] |
| 6 | + public async Task GenerateImageAsync() |
| 7 | + { |
| 8 | + using var client = GetAuthenticatedClient(); |
| 9 | + using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5)); |
| 10 | + var cancellationToken = cancellationTokenSource.Token; |
| 11 | + |
| 12 | + Generation generation = await client.Generations.GenerateImageAsync( |
| 13 | + prompt: "The beautiful woman just smiles", |
| 14 | + aspectRatio: AspectRatio.x4_3, |
| 15 | + cancellationToken: cancellationToken); |
| 16 | + |
| 17 | + if (generation.Id == null) |
| 18 | + { |
| 19 | + throw new InvalidOperationException("Generation Id is null."); |
| 20 | + } |
| 21 | + |
| 22 | + while (generation.State != State.Failed && generation.State != State.Completed) |
| 23 | + { |
| 24 | + await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); |
| 25 | + |
| 26 | + generation = await client.Generations.GetGenerationAsync( |
| 27 | + id: generation.Id!.Value.ToString(), |
| 28 | + cancellationToken: cancellationToken); |
| 29 | + } |
| 30 | + |
| 31 | + Console.WriteLine($"Id: {generation.Id}"); |
| 32 | + Console.WriteLine($"FailureReason: {generation.FailureReason}"); |
| 33 | + Console.WriteLine($"Image URL: {generation.Assets?.Image}"); |
| 34 | + Console.WriteLine($"State: {generation.State}"); |
| 35 | + |
| 36 | + generation.FailureReason.Should().BeNull(); |
| 37 | + generation.Id.Should().NotBeEmpty(); |
| 38 | + generation.Assets.Should().NotBeNull(); |
| 39 | + generation.Assets!.Image.Should().NotBeNull(); |
| 40 | + generation.State.Should().Be(State.Completed); |
| 41 | + } |
| 42 | +} |
0 commit comments