-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9048d3f
commit e727fc0
Showing
11 changed files
with
341 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/TemplateValidationException.cs
This file was deleted.
Oops, something went wrong.
145 changes: 145 additions & 0 deletions
145
test/Microsoft.TemplateEngine.Edge.UnitTests/ScannerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.TemplateEngine.Abstractions; | ||
using Microsoft.TemplateEngine.Edge.Settings; | ||
using Microsoft.TemplateEngine.TestHelper; | ||
using Microsoft.TemplateEngine.Tests; | ||
using Xunit; | ||
|
||
namespace Microsoft.TemplateEngine.Edge.UnitTests | ||
{ | ||
public class ScannerTests : TestBase, IClassFixture<EnvironmentSettingsHelper> | ||
{ | ||
private readonly EnvironmentSettingsHelper _settingsHelper; | ||
|
||
public ScannerTests(EnvironmentSettingsHelper environmentSettingsHelper) | ||
{ | ||
_settingsHelper = environmentSettingsHelper; | ||
} | ||
|
||
[Fact] | ||
public async Task CanLogValidationMessagesOnInstall_MissingIdentity() | ||
{ | ||
string templatesLocation = Path.Combine(TestTemplatesLocation, "Invalid", "MissingIdentity"); | ||
|
||
List<(LogLevel Level, string Message)> loggedMessages = new(); | ||
InMemoryLoggerProvider loggerProvider = new(loggedMessages); | ||
|
||
IEngineEnvironmentSettings settings = _settingsHelper.CreateEnvironment(virtualize: true, addLoggerProviders: new[] { loggerProvider }); | ||
|
||
Scanner scanner = new(settings); | ||
|
||
ScanResult result = await scanner.ScanAsync(templatesLocation, default).ConfigureAwait(false); | ||
|
||
Assert.Equal(0, result.Templates.Count); | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
Assert.Equal(0, result.Localizations.Count); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
|
||
string errorMessage = Assert.Single(loggedMessages, l => l.Level is LogLevel.Error).Message; | ||
Assert.Equal($"Failed to load template from {Path.GetFullPath(templatesLocation) + Path.DirectorySeparatorChar}.template.config/template.json.{Environment.NewLine}Details: 'identity' is missing or is an empty string.", errorMessage); | ||
} | ||
|
||
[Fact] | ||
public async Task CanLogValidationMessagesOnInstall_ErrorsInTemplateConfig() | ||
{ | ||
string templatesLocation = Path.Combine(TestTemplatesLocation, "Invalid", "MissingMandatoryConfig"); | ||
|
||
List<(LogLevel Level, string Message)> loggedMessages = new(); | ||
InMemoryLoggerProvider loggerProvider = new(loggedMessages); | ||
|
||
IEngineEnvironmentSettings settings = _settingsHelper.CreateEnvironment(virtualize: true, addLoggerProviders: new[] { loggerProvider }); | ||
|
||
Scanner scanner = new(settings); | ||
|
||
ScanResult result = await scanner.ScanAsync(templatesLocation, default).ConfigureAwait(false); | ||
|
||
Assert.Equal(0, result.Templates.Count); | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
Assert.Equal(0, result.Localizations.Count); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
|
||
List<string> errorMessages = loggedMessages.Where(lm => lm.Level == LogLevel.Error).Select(e => e.Message).ToList(); | ||
Assert.Equal(2, errorMessages.Count); | ||
|
||
List<string> warningMessages = loggedMessages.Where(lm => lm.Level == LogLevel.Warning).Select(e => e.Message).ToList(); | ||
Assert.Empty(warningMessages); | ||
|
||
List<string> debugMessages = loggedMessages.Where(lm => lm.Level == LogLevel.Debug).Select(e => e.Message).ToList(); | ||
Assert.Equal(4, debugMessages.Count); | ||
|
||
Assert.Equal( | ||
""" | ||
The template '<no name>' (MissingConfigTest) has the following validation errors: | ||
[Error][MV002] Missing 'name'. | ||
[Error][MV003] Missing 'shortName'. | ||
""", | ||
errorMessages[0]); | ||
Assert.Equal("Failed to install the template '<no name>' (MissingConfigTest): the template is not valid.", errorMessages[1]); | ||
|
||
Assert.Contains( | ||
""" | ||
The template '<no name>' (MissingConfigTest) has the following validation messages: | ||
[Info][MV005] Missing 'sourceName'. | ||
[Info][MV006] Missing 'author'. | ||
[Info][MV007] Missing 'groupIdentity'. | ||
[Info][MV008] Missing 'generatorVersions'. | ||
[Info][MV009] Missing 'precedence'. | ||
[Info][MV010] Missing 'classifications'. | ||
""", | ||
debugMessages); | ||
} | ||
|
||
[Fact] | ||
public async Task CanLogValidationMessagesOnInstall_Localization() | ||
{ | ||
string templatesLocation = Path.Combine(TestTemplatesLocation, "Invalid", "Localization", "ValidationFailure"); | ||
|
||
List<(LogLevel Level, string Message)> loggedMessages = new(); | ||
InMemoryLoggerProvider loggerProvider = new(loggedMessages); | ||
|
||
IEngineEnvironmentSettings settings = _settingsHelper.CreateEnvironment(virtualize: true, addLoggerProviders: new[] { loggerProvider }); | ||
|
||
Scanner scanner = new(settings); | ||
|
||
ScanResult result = await scanner.ScanAsync(templatesLocation, default).ConfigureAwait(false); | ||
|
||
Assert.Equal(1, result.Templates.Count); | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
Assert.Equal(0, result.Localizations.Count); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
|
||
List<string> errorMessages = loggedMessages.Where(lm => lm.Level == LogLevel.Error).Select(e => e.Message).ToList(); | ||
|
||
Assert.Equal(2, errorMessages.Count); | ||
|
||
List<string> warningMessages = loggedMessages.Where(lm => lm.Level == LogLevel.Warning).Select(e => e.Message).ToList(); | ||
|
||
Assert.Equal(3, warningMessages.Count); | ||
|
||
Assert.Equal( | ||
""" | ||
The template 'name' (TestAssets.Invalid.Localization.ValidationFailure) has the following validation errors in 'de-DE' localization: | ||
[Error][LOC001] In localization file under the post action with id 'pa1', there are localized strings for manual instruction(s) with ids 'do-not-exist'. These manual instructions do not exist in the template.json file and should be removed from localization file. | ||
[Error][LOC002] Post action(s) with id(s) 'pa0' specified in the localization file do not exist in the template.json file. Remove the localized strings from the localization file. | ||
""", | ||
errorMessages[0]); | ||
Assert.Equal( | ||
""" | ||
The template 'name' (TestAssets.Invalid.Localization.ValidationFailure) has the following validation errors in 'tr' localization: | ||
[Error][LOC002] Post action(s) with id(s) 'pa6' specified in the localization file do not exist in the template.json file. Remove the localized strings from the localization file. | ||
""", | ||
errorMessages[1]); | ||
|
||
Assert.Equal($"[{Path.GetFullPath(templatesLocation) + Path.DirectorySeparatorChar}.template.config/template.json]: id of the post action 'pa2' at index '3' is not unique. Only the first post action that uses this id will be localized.", warningMessages[0]); | ||
Assert.Equal("Failed to install the 'de-DE' localization the template 'name' (TestAssets.Invalid.Localization.ValidationFailure): the localization file is not valid. The localization will be skipped.", warningMessages[1]); | ||
Assert.Equal("Failed to install the 'tr' localization the template 'name' (TestAssets.Invalid.Localization.ValidationFailure): the localization file is not valid. The localization will be skipped.", warningMessages[2]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.