public void TestInstall_ExistingLibman_WithPromptForProvider() { var testInputReader = HostEnvironment.InputReader as TestInputReader; testInputReader.Inputs.Add("ProviderId", "cdnjs"); string initialContent = @"{ ""version"": ""1.0"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); var command = new InstallCommand(HostEnvironment); command.Configure(null); int result = command.Execute("[email protected]", "--destination", "wwwroot"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""libraries"": [ { ""library"": ""[email protected]"", ""destination"": ""wwwroot"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text)); }
public void TestInstall_WithInvalidFiles() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); command.Execute("jquery", "--files", "abc.js"); string expectedMessage = @"[LIB018]: ""[email protected]"" does not contain the following: abc.js Valid files are core.js, jquery.js, jquery.min.js, jquery.min.map, jquery.slim.js, jquery.slim.min.js, jquery.slim.min.map"; var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual(expectedMessage, logger.Messages.Last().Value); string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); Assert.AreEqual(StringHelper.NormalizeNewLines(initialContent), StringHelper.NormalizeNewLines(actualText)); }
public void TestInstall_Duplicate() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"" } ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); int result = command.Execute("[email protected]", "--provider", "cdnjs"); var testLogger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("[LIB019]: Cannot restore. Multiple definitions for libraries: jquery", testLogger.Messages.Last().Value); }
public void TestInstall_CleanDirectory() { var command = new InstallCommand(HostEnvironment); command.Configure(null); int result = command.Execute("[email protected]", "--provider", "cdnjs", "--destination", "wwwroot"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""libraries"": [ { ""provider"": ""cdnjs"", ""library"": ""[email protected]"", ""destination"": ""wwwroot"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text)); }
public void TestInstall_WithExistingLibmanJson() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); command.Execute("[email protected]"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText)); }
public void TestUpdateCommand_AlreadyUpToDate() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var installCommand = new InstallCommand(HostEnvironment); installCommand.Configure(null); installCommand.Execute("jquery --files jquery.min.js --files jquery.js".Split(' ')); 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"))); var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value); }