Skip to content

Commit

Permalink
BRGD-237 Add Scopes to Templates (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
talenfisher committed May 7, 2022
1 parent 45ac7a9 commit bc448f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Sdk.Models/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class Command
/// </summary>
public IEnumerable<CommandParameter> Parameters { get; set; } = Array.Empty<CommandParameter>();

/// <summary>
/// Gets or sets the command's scopes.
/// </summary>
public IEnumerable<string> Scopes { get; set; } = Array.Empty<string>();

/// <summary>
/// Gets or sets a value indicating whether or not this command is enabled.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Sdk.PackageTool/Services/TemplateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public async Task GenerateTemplate(Stream stream, CommandMetadata[] metadata, Ca
Type = CommandType.Embedded,
RequiredRole = commandMetadata.RequiredRole,
Parameters = commandMetadata.Parameters,
Scopes = commandMetadata.Scopes,
IsEnabled = true,
EmbeddedLocation = await commandService.PackageArtifact(commandMetadata, cancellationToken),
};
Expand Down
19 changes: 19 additions & 0 deletions tests/UnitTests/Sdk.PackageTool/Services/TemplateServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ CancellationToken cancellationToken
resource.Properties.Parameters.Should().BeEquivalentTo(command.Parameters);
}

[Test, Auto]
public async Task ShouldGenerateTemplateWithScopes(
CommandMetadata command,
[Target] TemplateService templateService,
CancellationToken cancellationToken
)
{
using var stream = new MemoryStream();
using var reader = new StreamReader(stream);
await templateService.GenerateTemplate(stream, new[] { command }, cancellationToken);
stream.Position = 0;

var serializer = new DeserializerBuilder().Build();
var result = serializer.Deserialize<Template>(reader);

var resource = result!.Resources.ElementAt(0).Value;
resource.Properties.Scopes.Should().BeEquivalentTo(command.Scopes);
}

[Test, Auto]
public async Task ShouldGenerateTemplateWithIsEnabled(
CommandMetadata command,
Expand Down

0 comments on commit bc448f2

Please sign in to comment.