public void TestRestoreErrors() { var command = new RestoreCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""core123.js"" ] } ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), contents); int result = command.Execute(); Assert.AreEqual(0, result); Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); var logger = HostEnvironment.Logger as TestLogger; Assert.IsTrue(logger.Messages.Any(m => m.Key == LibraryManager.Contracts.LogLevel.Error)); }
public void TestRestore() { var command = new RestoreCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""core.js"" ] } ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), contents); int result = command.Execute(); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); }
public void TestUpdateCommand() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""jquery.js"" ] } ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null); restoreCommand.Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); int result = command.Execute("jquery"); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); string actualText = File.ReadAllText(libmanjsonPath); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""jquery.js"" ] } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText)); }
public void TestUninstall_NoLibraryToUninstall() { var command = new UninstallCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""provider"": ""cdnjs"", ""library"": ""[email protected]"", ""destination"": ""wwwroot"", ""files"": [ ""jquery.min.js"", ""core.js"" ] } ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null); restoreCommand.Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); int result = command.Execute("[email protected]"); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("Library \"[email protected]\" is not installed. Nothing to uninstall", logger.Messages[logger.Messages.Count - 1].Value); string actualText = File.ReadAllText(libmanjsonPath); Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText)); }
public void TestUpdateCommand_InvalidLibraryName() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""jquery.js"" ] } ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null); restoreCommand.Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); int result = command.Execute("[email protected]"); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); var logger = HostEnvironment.Logger as TestLogger; string message = "No library found with name \"[email protected]\" to update.\r\nPlease specify a library name without the version information to update."; Assert.AreEqual(StringHelper.NormalizeNewLines(message), StringHelper.NormalizeNewLines(logger.Messages.Last().Value)); string actualText = File.ReadAllText(libmanjsonPath); Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText)); }
public void TestUpdateCommand_InvalidUpdatedLibrary() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""jquery.js"" ] } ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null); restoreCommand.Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); int result = command.Execute("jquery", "--to", "[email protected]"); Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); string actualText = File.ReadAllText(libmanjsonPath); Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText)); var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual(LogLevel.Error, logger.Messages.Last().Key); string expectedMessage = "Failed to update \"jquery\" to \"[email protected]\""; Assert.IsTrue(logger.Messages.Any(m => m.Value == expectedMessage)); }
public void TestCacheClean_ForProvider() { string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""core.js"" ] } ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), contents); Directory.CreateDirectory(Path.Combine(CacheDir, "filesystem")); File.WriteAllText(Path.Combine(CacheDir, "filesystem", "abc.js"), ""); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null).Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); Assert.IsTrue(File.Exists(Path.Combine(CacheDir, "cdnjs", "jquery", "3.2.1", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(CacheDir, "cdnjs", "jquery", "3.2.1", "core.js"))); var cleanCommand = new CacheCleanCommand(HostEnvironment); cleanCommand.Configure(); cleanCommand.Execute("cdnjs"); // Should not delete files in the project. Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "core.js"))); // Should delete files in the cache. Assert.IsFalse(File.Exists(Path.Combine(CacheDir, "cdnjs", "jquery", "3.2.1", "jquery.min.js"))); Assert.IsFalse(File.Exists(Path.Combine(CacheDir, "cdnjs", "jquery", "3.2.1", "core.js"))); Assert.IsTrue(File.Exists(Path.Combine(CacheDir, "fileSystem", "abc.js"))); }
public void TestUpdateCommand_AlreadyUpToDate() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"", ""files"": [ ""jquery.min.js"", ""jquery.js"" ] } ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var restoreCommand = new RestoreCommand(HostEnvironment); restoreCommand.Configure(null); restoreCommand.Execute(); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); int result = command.Execute("jquery"); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); string actualText = File.ReadAllText(libmanjsonPath); Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText)); var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value); }