public void FallbackToCacheDoesntHappenWhenAggregateIsUsedAndLocalSourceIsAvailable() { // Arrange string localdrive = System.Environment.GetEnvironmentVariable("TEMP"); var userSettings = new Mock<ISettings>(); userSettings.Setup(s => s.GetSettingValues("packageSources", true)).Returns(new[] { new SettingValue("one", @"\\LetsHopeThisDirectory\IsNotAvaialble", false), new SettingValue("two", localdrive, false), new SettingValue("three", @"http://SomeHttpSource/NotAvailable", false), }); userSettings.Setup(s => s.GetValues("activePackageSource")) .Returns(new[] { new KeyValuePair<string, string>("All", @"(All)"), }); var provider = new VsPackageSourceProvider(userSettings.Object, CreateDefaultSourceProvider(userSettings.Object), new Mock<IVsShellInfo>().Object); var activeSource = provider.ActivePackageSource; var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); var vsPackageManager = new MockVsPackageManager(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); var sourceVsPackageManager = new MockVsPackageManager(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Returns(sourceVsPackageManager); //Act var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, repositoryFactory.Object, provider, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, false); cmdlet.Id = "my-id"; cmdlet.Execute(); // Assert Assert.NotEqual(cmdlet.Source, NuGet.MachineCache.Default.Source); }
public void InstallPackageCmdletFallsbackToCacheWhenNetworkIsUnavailable() { // Arrange var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); var vsPackageManager = new MockVsPackageManager(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); var sourceVsPackageManager = new MockVsPackageManager(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Returns(sourceVsPackageManager); var userSettings = new Mock<ISettings>(); userSettings.Setup(s => s.GetSettingValues("packageSources", true)).Returns(new[] { new SettingValue("one", @"\\LetsHopeThisDirectory\IsNotAvaialble", false), }); userSettings.Setup(s => s.GetValues("activePackageSource")) .Returns(new[] { new KeyValuePair<string, string>("one", @"\\LetsHopeThisDirectory\IsNotAvaialble") }); var provider = new VsPackageSourceProvider(userSettings.Object, CreateDefaultSourceProvider(userSettings.Object), new Mock<IVsShellInfo>().Object); var activeSource = provider.ActivePackageSource; //Act var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, repositoryFactory.Object, provider, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, false); cmdlet.Id = "my-id"; cmdlet.Execute(); // Assert Assert.Equal(cmdlet.Source, NuGet.MachineCache.Default.Source); }