Improve error message in wizard when installing an invalid library name (#651)
Addresses #508
This commit is contained in:
Родитель
cabf77c356
Коммит
a8f81f6a59
|
@ -69,6 +69,15 @@ namespace Microsoft.Web.LibraryManager.Vsix.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The library {0} did not match the naming scheme for provider {1}. {2}.
|
||||
/// </summary>
|
||||
public static string BadLibraryId {
|
||||
get {
|
||||
return ResourceManager.GetString("BadLibraryId", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to _Cancel.
|
||||
/// </summary>
|
||||
|
|
|
@ -271,4 +271,8 @@ Do you want to continue?</value>
|
|||
<data name="NoMatchesFound" xml:space="preserve">
|
||||
<value>No matches found</value>
|
||||
</data>
|
||||
<data name="BadLibraryId" xml:space="preserve">
|
||||
<value>The library {0} did not match the naming scheme for provider {1}. {2}</value>
|
||||
<comment>Used in an error message popup. {2} is the provider's example text (already localized elsewhere).</comment>
|
||||
</data>
|
||||
</root>
|
|
@ -403,6 +403,12 @@ namespace Microsoft.Web.LibraryManager.Vsix.UI.Models
|
|||
|
||||
public async Task<bool> IsLibraryInstallationStateValidAsync()
|
||||
{
|
||||
if (!LibraryIdToNameAndVersionConverter.Instance.IsWellFormedLibraryId(LibraryId, SelectedProvider.Id))
|
||||
{
|
||||
ErrorMessage = string.Format(Text.BadLibraryId, LibraryId, SelectedProvider.Id, SelectedProvider.LibraryIdHintText);
|
||||
return false;
|
||||
}
|
||||
|
||||
(string name, string version) = LibraryIdToNameAndVersionConverter.Instance.GetLibraryNameAndVersion(LibraryId, SelectedProvider.Id);
|
||||
LibraryInstallationState libraryInstallationState = new LibraryInstallationState
|
||||
{
|
||||
|
|
|
@ -8,6 +8,14 @@ namespace Microsoft.Web.LibraryManager.LibraryNaming
|
|||
/// </summary>
|
||||
internal interface ILibraryNamingScheme
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns whether the given library identifier matches the naming scheme
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The library ID to validate.</param>
|
||||
/// <returns>Returns true if the library ID matches the naming scheme; false otherwise.</returns>
|
||||
/// <remarks>This does not indicate that the library ID is valid, but only that it is well-formed.</remarks>
|
||||
bool IsValidLibraryId(string libraryId);
|
||||
|
||||
/// <summary>
|
||||
/// Splits libraryId into name and version.
|
||||
/// </summary>
|
||||
|
|
|
@ -110,6 +110,14 @@ namespace Microsoft.Web.LibraryManager.LibraryNaming
|
|||
return GetSchemeForProvider(providerId).GetLibraryId(name, version);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given library ID is of a valid form for the given provider
|
||||
/// </summary>
|
||||
public bool IsWellFormedLibraryId(string libraryId, string providerId)
|
||||
{
|
||||
return GetSchemeForProvider(providerId).IsValidLibraryId(libraryId);
|
||||
}
|
||||
|
||||
private ILibraryNamingScheme GetSchemeForProvider(string providerId)
|
||||
{
|
||||
lock (_syncObject)
|
||||
|
|
|
@ -19,5 +19,11 @@ namespace Microsoft.Web.LibraryManager.LibraryNaming
|
|||
{
|
||||
return (libraryId ?? string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsValidLibraryId(string libraryId)
|
||||
{
|
||||
return !string.IsNullOrEmpty(libraryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,5 +66,18 @@ namespace Microsoft.Web.LibraryManager.LibraryNaming
|
|||
: $"{name}{Separator}{version}";
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsValidLibraryId(string libraryId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(libraryId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int separator = libraryId.LastIndexOf(Separator);
|
||||
|
||||
return separator > 1 && separator < libraryId.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,5 +42,20 @@ namespace Microsoft.Web.LibraryManager.Test
|
|||
|
||||
Assert.AreEqual(expectedLibraryId, libraryId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(null, false)]
|
||||
[DataRow("", false)]
|
||||
[DataRow("foobarbaz", true)]
|
||||
[DataRow(":@#/\\|", true)]
|
||||
[DataRow(" \t\r\n", true)]
|
||||
public void IsValidLibraryId(string libraryId, bool expected)
|
||||
{
|
||||
var namingScheme = new SimpleLibraryNamingScheme();
|
||||
|
||||
bool result = namingScheme.IsValidLibraryId(libraryId);
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,5 +47,25 @@ namespace Microsoft.Web.LibraryManager.Test
|
|||
|
||||
Assert.AreEqual(expectedLibraryId, libraryId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(null, false)]
|
||||
[DataRow("", false)]
|
||||
[DataRow("@", false)]
|
||||
[DataRow("test", false)]
|
||||
[DataRow("test@1", true)]
|
||||
[DataRow("@test1", false)]
|
||||
[DataRow("@test/1.0", false)]
|
||||
[DataRow("@test1@1.0", true)]
|
||||
[DataRow("test@input", true)]
|
||||
[DataRow("@@@1.0", true)] // kind of an odd case, but this translates to "@@" as the name
|
||||
public void IsValidLibraryId(string libraryId, bool expected)
|
||||
{
|
||||
var namingScheme = new VersionedLibraryNamingScheme();
|
||||
|
||||
bool result = namingScheme.IsValidLibraryId(libraryId);
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче