fix: provide error message for unknown provider. (#608)
* fix: provide error message for unknown provider. If a provider is given and it is not one of the available providers, output an invalid operation message like "Provider 'foo' is not installed. Closes #134
This commit is contained in:
Родитель
a0c0015617
Коммит
422d40002e
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Web.LibraryManager.Contracts;
|
||||
|
@ -64,6 +65,10 @@ namespace Microsoft.Web.LibraryManager.Tools.Commands
|
|||
Logger.Log(string.Format(Resources.Text.CacheCleanFailed, ex.Message), LogLevel.Error);
|
||||
}
|
||||
}
|
||||
else if (!ManifestDependencies.Providers.Any(p => p.Id == Provider.Value))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(Resources.Text.ProviderNotInstalled, Provider.Value));
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Web.LibraryManager.Tools.Commands;
|
||||
|
||||
|
@ -109,5 +109,15 @@ namespace Microsoft.Web.LibraryManager.Tools.Test
|
|||
|
||||
Assert.IsTrue(File.Exists(Path.Combine(CacheDir, "filesystem", "abc.js")));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestCacheClean_ThrowsIfUnknownProvider()
|
||||
{
|
||||
var cleanCommand = new CacheCleanCommand(HostEnvironment);
|
||||
cleanCommand.Configure();
|
||||
|
||||
var exception = Assert.ThrowsException<AggregateException>(() => cleanCommand.Execute("foo"));
|
||||
Assert.IsInstanceOfType(exception.InnerExceptions.First(), typeof(InvalidOperationException));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче