|
10 | 10 | using FluentAssertions;
|
11 | 11 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Commands.Executors;
|
12 | 12 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
|
| 13 | +using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions; |
13 | 14 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Builders;
|
| 15 | +using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Logger.Cache; |
14 | 16 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Policy;
|
15 | 17 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors;
|
16 | 18 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
|
@@ -70,5 +72,64 @@ public async Task GenerateLoggersTemplates_ProperlyLaysTheInformation()
|
70 | 72 | loggerTemplate.TypedResources.Loggers.First().Name.Should().Contain(MockLoggerClient.LoggerName);
|
71 | 73 | loggerTemplate.TypedResources.Loggers.First().Properties.LoggerType.Should().Be(MockDiagnosticClient.DefaultDiagnosticName);
|
72 | 74 | }
|
| 75 | + |
| 76 | + [Fact] |
| 77 | + public async Task GenerateLoggersTemplates_ShouldPopulateCacheWithoutError_GivenItCalledMultipleTimes() |
| 78 | + { |
| 79 | + // arrange |
| 80 | + var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration( |
| 81 | + splitAPIs: "true", |
| 82 | + paramApiLoggerId: "true", |
| 83 | + apiName: string.Empty); |
| 84 | + var extractorParameters = new ExtractorParameters(extractorConfig); |
| 85 | + |
| 86 | + var mockedDiagnosticClient = MockDiagnosticClient.GetMockedApiClientWithDefaultValues(); |
| 87 | + var mockedLoggerClient = MockLoggerClient.GetMockedClientWithDiagnosticDependentValues(); |
| 88 | + var loggerExtractor = new LoggerExtractor( |
| 89 | + this.GetTestLogger<LoggerExtractor>(), |
| 90 | + new TemplateBuilder(), |
| 91 | + mockedLoggerClient, |
| 92 | + mockedDiagnosticClient); |
| 93 | + |
| 94 | + var apisToTest = new List<string>() { |
| 95 | + "echo-api", |
| 96 | + "echo-api-2" |
| 97 | + }; |
| 98 | + |
| 99 | + var diagnosticLoggerBinding = new DiagnosticLoggerBinding |
| 100 | + { |
| 101 | + DiagnosticName = NamingHelper.GenerateValidParameterName(MockDiagnosticClient.DefaultDiagnosticName, ParameterPrefix.Diagnostic), |
| 102 | + LoggerId = MockDiagnosticClient.LoggerIdValue |
| 103 | + }; |
| 104 | + |
| 105 | + var expectedApiDiagnosticLoggerBingingsValues = new Dictionary<string, ISet<DiagnosticLoggerBinding>>() |
| 106 | + { |
| 107 | + { |
| 108 | + NamingHelper.GenerateValidParameterName("echo-api", ParameterPrefix.Api), |
| 109 | + new HashSet<DiagnosticLoggerBinding>() { diagnosticLoggerBinding } |
| 110 | + }, |
| 111 | + { |
| 112 | + NamingHelper.GenerateValidParameterName("echo-api-2", ParameterPrefix.Api), |
| 113 | + new HashSet<DiagnosticLoggerBinding>() { diagnosticLoggerBinding } |
| 114 | + } |
| 115 | + }; |
| 116 | + |
| 117 | + // act |
| 118 | + await loggerExtractor.GenerateLoggerTemplateAsync(apisToTest, null, extractorParameters); |
| 119 | + foreach(var api in apisToTest) |
| 120 | + { |
| 121 | + await loggerExtractor.GenerateLoggerTemplateAsync(new List<string>() { api }, null, extractorParameters); |
| 122 | + } |
| 123 | + |
| 124 | + // assert |
| 125 | + loggerExtractor.Cache.ServiceLevelDiagnosticLoggerBindings.Count.Should().Be(1); |
| 126 | + loggerExtractor.Cache.ApiDiagnosticLoggerBindings.Count.Should().Be(2); |
| 127 | + |
| 128 | + foreach (var (apiName, diagnosticLoggerBindings) in expectedApiDiagnosticLoggerBingingsValues) |
| 129 | + { |
| 130 | + loggerExtractor.Cache.ApiDiagnosticLoggerBindings[apiName].Count.Should().Be(1); |
| 131 | + loggerExtractor.Cache.ApiDiagnosticLoggerBindings[apiName].First().Equals(diagnosticLoggerBindings.First()).Should().BeTrue(); |
| 132 | + } |
| 133 | + } |
73 | 134 | }
|
74 | 135 | }
|
0 commit comments