public async Task Restore_ByDigest_ShouldSucceed() { var registry = "example.com"; var registryUri = new Uri("https://" + registry); var repository = "hello/there"; var client = new MockRegistryBlobClient(); var clientFactory = StrictMock.Of <IContainerRegistryClientFactory>(); clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny <RootConfiguration>(), registryUri, repository)).Returns(client); var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory; var settings = new InvocationSettings(BicepTestConstants.CreateFeaturesProvider(TestContext, registryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory); var tempDirectory = FileHelper.GetUniqueTestOutputPath(TestContext); Directory.CreateDirectory(tempDirectory); var publishedBicepFilePath = Path.Combine(tempDirectory, "published.bicep"); File.WriteAllText(publishedBicepFilePath, string.Empty); var(publishOutput, publishError, publishResult) = await Bicep(settings, "publish", publishedBicepFilePath, "--target", $"br:{registry}/{repository}:v1"); using (new AssertionScope()) { publishResult.Should().Be(0); publishOutput.Should().BeEmpty(); publishError.Should().BeEmpty(); } client.Blobs.Should().HaveCount(2); client.Manifests.Should().HaveCount(1); client.ManifestTags.Should().HaveCount(1); string digest = client.Manifests.Single().Key; var bicep = $@" module empty 'br:{registry}/{repository}@{digest}' = {{ name: 'empty' }} "; var restoreBicepFilePath = Path.Combine(tempDirectory, "restored.bicep"); File.WriteAllText(restoreBicepFilePath, bicep); var(output, error, result) = await Bicep(settings, "restore", restoreBicepFilePath); using (new AssertionScope()) { result.Should().Be(0); output.Should().BeEmpty(); error.Should().BeEmpty(); } }
public static MockRegistryAssertions Should(this MockRegistryBlobClient client) => new MockRegistryAssertions(client);