public async Task FindTemplateSpecByIdAsync_GotUnexpectedRequestFailedException_ConvertsToTemplateSpecException()
        {
            var client = CreateMockClient(templateSpecVersionMock => templateSpecVersionMock
                                          .Setup(x => x.GetAsync(It.IsAny <CancellationToken>()))
                                          .ThrowsAsync(new RequestFailedException("Unexpected error.")));

            var repository = new TemplateSpecRepository(client);

            await Invoking(async() => await repository.FindTemplateSpecByIdAsync(TestTemplateSpecId))
            .Should()
            .ThrowAsync <TemplateSpecException>()
            .WithMessage("Unexpected error.");
        }
        public async Task FindTemplateSpecByIdAsync_TemplateSpecNotFound_ThrowsTemplateSpecException()
        {
            var client = CreateMockClient(templateSpecVersionMock => templateSpecVersionMock
                                          .Setup(x => x.GetAsync(It.IsAny <CancellationToken>()))
                                          .ThrowsAsync(new RequestFailedException(404, "Not found.")));

            var repository = new TemplateSpecRepository(client);

            await Invoking(async() => await repository.FindTemplateSpecByIdAsync(TestTemplateSpecId))
            .Should()
            .ThrowAsync <TemplateSpecException>()
            .WithMessage("The referenced template spec does not exist. Not Found.");
        }
        public async Task FindTemplateSpecByIdAsync_TemlateSpecFound_ReturnsTemplateSpec()
        {
            var data = new TemplateSpecVersionData("westus")
            {
                MainTemplate = "{}"
            };

            var client = CreateMockClient(
                templateSpecVersionMock => templateSpecVersionMock
                .SetupGet(x => x.Data)
                .Returns(data),
                templateSpecVersionMock => templateSpecVersionMock
                .Setup(x => x.GetAsync(It.IsAny <CancellationToken>()))
                .ReturnsAsync(CreateMockResponse(templateSpecVersionMock.Object)));

            var repository = new TemplateSpecRepository(client);

            var templateSpec = await repository.FindTemplateSpecByIdAsync(TestTemplateSpecId);

            templateSpec.MainTemplate.ValueEquals("{}").Should().BeTrue();
        }
Ejemplo n.º 4
0
        public async Task FindTemplateSpecByIdAsync_TemlateSpecFound_ReturnsTemplateSpec()
        {
            var data    = new TemplateSpecVersionData("westus");
            var content = JsonSerializer.Serialize(data, new JsonSerializerOptions {
                WriteIndented = true
            });

            var templateSpecVersionResourceMock = CreateMockTemplateSpecVersionResource(
                mock => mock
                .Setup(x => x.GetAsync(It.IsAny <CancellationToken>()))
                .ReturnsAsync(CreateMockResponse(content)));

            var clientMock = CreateMockClient(templateSpecVersionResourceMock);

            var repository = new TemplateSpecRepository(clientMock);

            var templateSpec = await repository.FindTemplateSpecByIdAsync(TestTemplateSpecId);

            templateSpec.Content.ReplaceLineEndings().Should().Be(@"{
  ""Location"": {
    ""Name"": ""westus"",
    ""DisplayName"": ""West US""
  },
  ""Tags"": {},
  ""Description"": null,
  ""LinkedTemplates"": [],
  ""Metadata"": null,
  ""MainTemplate"": null,
  ""UiFormDefinition"": null,
  ""Id"": null,
  ""Name"": null,
  ""ResourceType"": {
    ""Namespace"": null,
    ""Type"": null
  },
  ""SystemData"": null
}".ReplaceLineEndings());
        }