本文整理汇总了C#中TestInstallCommand.ExecuteCommand方法的典型用法代码示例。如果您正苦于以下问题:C# TestInstallCommand.ExecuteCommand方法的具体用法?C# TestInstallCommand.ExecuteCommand怎么用?C# TestInstallCommand.ExecuteCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestInstallCommand
的用法示例。
在下文中一共展示了TestInstallCommand.ExecuteCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallCommandInstallsPackageIfArgumentIsNotPackageReferenceFile
public void InstallCommandInstallsPackageIfArgumentIsNotPackageReferenceFile()
{
// Arrange
var fileSystem = new MockFileSystem();
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(@"Foo.1.0\Foo.1.0.nupkg", fileSystem.Paths.Single().Key);
}
示例2: InstallCommandResolvesSourceName
public void InstallCommandResolvesSourceName()
{
// Arrange
var fileSystem = new MockFileSystem();
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
installCommand.Source.Add("Some source name");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(@"Foo.1.0\Foo.1.0.nupkg", fileSystem.Paths.Single().Key);
}
示例3: InstallCommandForPackageReferenceFileDoesNotThrowIfThereIsNoPackageToInstall
public void InstallCommandForPackageReferenceFileDoesNotThrowIfThereIsNoPackageToInstall()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
</packages>".AsStream());
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, allowPackageRestore: false);
installCommand.Arguments.Add(@"x:\test\packages.config");
// Act & Assert
installCommand.ExecuteCommand();
}
示例4: InstallCommandInstallsPackageSuccessfullyIfCacheRepositoryIsNotSet
public void InstallCommandInstallsPackageSuccessfullyIfCacheRepositoryIsNotSet()
{
// Arrange
var fileSystem = new MockFileSystem();
var packageManager = new Mock<IPackageManager>(MockBehavior.Strict);
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(@"Foo.1.0\Foo.1.0.nupkg", fileSystem.Paths.Single().Key);
}
示例5: InstallCommandUsesInstallOperationIfArgumentIsNotPackageReferenceFile
public void InstallCommandUsesInstallOperationIfArgumentIsNotPackageReferenceFile()
{
// Arrange
var fileSystem = new MockFileSystem();
var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") };
var mockFactory = new Mock<IPackageRepositoryFactory>();
mockFactory.Setup(r => r.CreateRepository(It.IsAny<string>())).Returns(mockRepo);
var installCommand = new TestInstallCommand(mockFactory.Object, GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(RepositoryOperationNames.Install, mockRepo.LastOperation);
}
示例6: InstallCommandForPackageReferenceFileThrowIfThereIsPackageToInstallAndConsentIsNotGranted
public void InstallCommandForPackageReferenceFileThrowIfThereIsPackageToInstallAndConsentIsNotGranted()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""Foo"" version=""1.0"" />
<package id=""Baz"" version=""0.7"" />
</packages>");
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, allowPackageRestore: false);
installCommand.Arguments.Add(@"x:\test\packages.config");
// Act & Assert
Assert.Throws<InvalidOperationException>(() => installCommand.ExecuteCommand());
Assert.Equal(1, fileSystem.Paths.Count);
Assert.Equal(@"x:\test\packages.config", fileSystem.Paths.ElementAt(0).Key);
}
示例7: InstallCommandWorksIfExcludedVersionsAndPackageIsNotFoundInRemoteRepository
public void InstallCommandWorksIfExcludedVersionsAndPackageIsNotFoundInRemoteRepository()
{
// Arrange
var fileSystem = new MockFileSystem();
var packages = new List<IPackage> { PackageUtility.CreatePackage("A", "0.5") };
var repository = new Mock<IPackageRepository>();
repository.Setup(c => c.GetPackages()).Returns(packages.AsQueryable());
repository.Setup(c => c.AddPackage(It.IsAny<IPackage>())).Throws(new Exception("Method should not be called"));
repository.Setup(c => c.RemovePackage(It.IsAny<IPackage>())).Throws(new Exception("Method should not be called"));
var packageManager = new PackageManager(GetFactory().CreateRepository("Some source"), new DefaultPackagePathResolver(fileSystem), fileSystem, repository.Object);
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, packageManager);
installCommand.ExcludeVersion = true;
installCommand.Arguments.Add("A");
// Act and Assert
ExceptionAssert.Throws<InvalidOperationException>(() => installCommand.ExecuteCommand(), "Unable to find package 'A'.");
// Ensure packages were not removed.
Assert.Equal(1, packages.Count);
}
示例8: InstallCommandInstallsPrereleasePackageIfFlagIsSpecified
public void InstallCommandInstallsPrereleasePackageIfFlagIsSpecified()
{
// Arrange
var fileSystem = new MockFileSystem();
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem) { Prerelease = true };
installCommand.Arguments.Add("Baz");
installCommand.Source.Add("Some Source name");
installCommand.Source.Add("Some other Source");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(@"Baz.0.8.1-alpha\Baz.0.8.1-alpha.nupkg", fileSystem.Paths.Single().Key);
}
示例9: InstallCommandInstallsPackageFromAllSourcesIfArgumentIsNotPackageReferenceFile
public void InstallCommandInstallsPackageFromAllSourcesIfArgumentIsNotPackageReferenceFile()
{
// Arrange
var fileSystem = new MockFileSystem();
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
// Act
installCommand.ExecuteCommand();
installCommand.Arguments.Clear();
installCommand.Arguments.Add("Bar");
installCommand.Version = "0.5";
installCommand.ExecuteCommand();
// Assert
Assert.Equal(@"Foo.1.0\Foo.1.0.nupkg", fileSystem.Paths.First().Key);
Assert.Equal(@"Bar.0.5\Bar.0.5.nupkg", fileSystem.Paths.Last().Key);
}
示例10: InstallCommandPromptsForConsentIfRequireConsentIsSet
public void InstallCommandPromptsForConsentIfRequireConsentIsSet()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""Abc"" version=""1.0.0"" />
</packages>");
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var packageManager = new Mock<IPackageManager>(MockBehavior.Strict);
var repository = new MockPackageRepository { PackageUtility.CreatePackage("Abc") };
packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver);
packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem));
packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem);
packageManager.SetupGet(p => p.SourceRepository).Returns(repository);
var repositoryFactory = new Mock<IPackageRepositoryFactory>();
repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository);
var packageSourceProvider = Mock.Of<IPackageSourceProvider>();
var console = new MockConsole();
var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false);
installCommand.Arguments.Add(@"X:\test\packages.config");
installCommand.Console = console;
installCommand.RequireConsent = true;
// Act
var exception = Assert.Throws<AggregateException>(() => installCommand.ExecuteCommand());
// Assert
#pragma warning disable 0219
// mono compiler complains that innerException is assigned but not used.
var innerException = Assert.IsAssignableFrom<InvalidOperationException>(exception.InnerException);
#pragma warning restore 0219
// The culture can't be forced to en-US as the error message is generated in another thread.
// Hence, only check the error message if the language is english.
var culture = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
if (culture == "en" || culture == "iv") // english or invariant
{
string message = string.Format(
CultureInfo.CurrentCulture,
NuGetResources.InstallCommandPackageRestoreConsentNotFound,
NuGet.Resources.NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", ""));
Assert.Equal(message, exception.InnerException.Message);
}
}
示例11: InstallCommandInstallsAllPackagesUsePackagesConfigByDefaultIfNoArgumentIsSpecified
public void InstallCommandInstallsAllPackagesUsePackagesConfigByDefaultIfNoArgumentIsSpecified()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\test");
fileSystem.AddFile(@"packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""Foo"" version=""1.0"" />
<package id=""Baz"" version=""0.7"" />
</packages>");
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(3, fileSystem.Paths.Count);
Assert.Equal(@"packages.config", fileSystem.Paths.ElementAt(0).Key);
Assert.Contains(@"Foo.1.0\Foo.1.0.nupkg", fileSystem.Paths.Keys);
Assert.Contains(@"Baz.0.7\Baz.0.7.nupkg", fileSystem.Paths.Keys);
}
示例12: InstallCommandUsesRestoreOperationIfArgumentIsPackageReferenceFile
public void InstallCommandUsesRestoreOperationIfArgumentIsPackageReferenceFile()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""Foo"" version=""1.0"" />
</packages>");
var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") };
var mockFactory = new Mock<IPackageRepositoryFactory>();
mockFactory.Setup(r => r.CreateRepository(It.IsAny<string>())).Returns(mockRepo);
var installCommand = new TestInstallCommand(mockFactory.Object, GetSourceProvider(), fileSystem);
installCommand.Arguments.Add(@"x:\test\packages.config");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.Equal(RepositoryOperationNames.Restore, mockRepo.LastOperation);
}
示例13: InstallCommandNotUseLocalCacheIfVersionNotSpecified
public void InstallCommandNotUseLocalCacheIfVersionNotSpecified()
{
// Arrange
var fileSystem = new MockFileSystem();
var localCache = new Mock<IPackageRepository>(MockBehavior.Strict);
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, machineCacheRepository: localCache.Object)
{
NoCache = false
};
installCommand.Arguments.Add("Baz");
installCommand.Source.Add("Some Source name");
installCommand.Source.Add("Some other Source");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.True(fileSystem.FileExists(@"Baz.0.7\Baz.0.7.nupkg"));
localCache.Verify(c => c.GetPackages(), Times.Never());
}
示例14: InstallCommandInstallsPackageSuccessfullyIfCacheRepositoryIsNotSet
public void InstallCommandInstallsPackageSuccessfullyIfCacheRepositoryIsNotSet()
{
// Arrange
var fileSystem = new MockFileSystem();
var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem);
installCommand.Arguments.Add("Foo");
// Act
installCommand.ExecuteCommand();
// Assert
Assert.True(fileSystem.FileExists(@"Foo.1.0\Foo.1.0.nupkg"));
}
示例15: InstallCommandFromConfigPerformsQuickCheckForFiles
public void InstallCommandFromConfigPerformsQuickCheckForFiles()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""Foo"" version=""1.8.0"" />
<package id=""Qux"" version=""2.3.56-beta"" />
</packages>");
fileSystem.AddFile("Foo.1.8.nupkg");
var package = PackageUtility.CreatePackage("Qux", "2.3.56-beta");
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var packageManager = new Mock<IPackageManager>(MockBehavior.Strict);
var repository = new MockPackageRepository { package };
packageManager.Setup(p => p.InstallPackage(package, true, true, true)).Verifiable();
packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver);
packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem));
packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem);
packageManager.SetupGet(p => p.SourceRepository).Returns(repository);
var repositoryFactory = new Mock<IPackageRepositoryFactory>();
repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository);
var packageSourceProvider = Mock.Of<IPackageSourceProvider>();
// Act
var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object)
{
Console = new MockConsole()
};
installCommand.Arguments.Add(@"X:\test\packages.config");
installCommand.ExecuteCommand();
// Assert
packageManager.Verify();
}