private static List <MockFeed> GetMockFeedsForConfigFile(FilePath?nugetConfig)
 {
     if (nugetConfig.HasValue)
     {
         return(new List <MockFeed>
         {
             new MockFeed
             {
                 Type = MockFeedType.ExplicitNugetConfig,
                 Uri = nugetConfig.Value.Value,
                 Packages = new List <MockFeedPackage>
                 {
                     new MockFeedPackage
                     {
                         PackageId = TestPackageId.ToString(),
                         Version = TestPackageVersion,
                         ToolCommandName = "SimulatorCommand"
                     }
                 }
             }
         });
     }
     else
     {
         return(new List <MockFeed>());
     }
 }
        public void GivenNoFeedInstallFailsWithException(bool testMockBehaviorIsInSync)
        {
            var(store, storeQuery, installer, uninstaller, reporter, fileSystem) = Setup(
                useMock: testMockBehaviorIsInSync,
                feeds: new List <MockFeed>());

            Action a = () => installer.InstallPackage(new PackageLocation(), packageId: TestPackageId,
                                                      versionRange: VersionRange.Parse(TestPackageVersion), targetFramework: _testTargetframework);

            a.ShouldThrow <ToolPackageException>().WithMessage(LocalizableStrings.ToolInstallationRestoreFailed);

            reporter.Lines.Count.Should().Be(1);
            reporter.Lines[0].Should().Contain(TestPackageId.ToString());
        }
Пример #3
0
        public void GivenSecondInstallWithoutATransactionTheFirstShouldNotRollback(bool testMockBehaviorIsInSync)
        {
            var source = GetTestLocalFeedPath();

            var(store, installer, reporter, fileSystem) = Setup(
                useMock: testMockBehaviorIsInSync,
                feeds: GetMockFeedsForSource(source));

            var package = installer.InstallPackage(
                packageId: TestPackageId,
                versionRange: VersionRange.Parse(TestPackageVersion),
                targetFramework: _testTargetframework,
                source: source);

            AssertPackageInstall(reporter, fileSystem, package, store);

            Action secondCall = () => installer.InstallPackage(
                packageId: TestPackageId,
                versionRange: VersionRange.Parse(TestPackageVersion),
                targetFramework: _testTargetframework,
                source: source);

            reporter.Lines.Should().BeEmpty();

            secondCall.ShouldThrow <ToolPackageException>().Where(
                ex => ex.Message ==
                string.Format(
                    CommonLocalizableStrings.ToolPackageConflictPackageId,
                    TestPackageId,
                    TestPackageVersion));

            fileSystem
            .Directory
            .Exists(store.Root.WithSubDirectories(TestPackageId.ToString()).Value)
            .Should()
            .BeTrue();

            package.Uninstall();

            fileSystem
            .Directory
            .EnumerateFileSystemEntries(store.Root.WithSubDirectories(ToolPackageStore.StagingDirectory).Value)
            .Should()
            .BeEmpty();
        }
Пример #4
0
 private static IEnumerable <MockFeed> GetOfflineMockFeed()
 {
     return(new MockFeed[]
     {
         new MockFeed
         {
             Type = MockFeedType.OfflineFeed,
             Uri = GetTestLocalFeedPath(),
             Packages = new List <MockFeedPackage>
             {
                 new MockFeedPackage
                 {
                     PackageId = TestPackageId.ToString(),
                     Version = TestPackageVersion
                 }
             }
         }
     });
 }
Пример #5
0
 private static IEnumerable <MockFeed> GetMockFeedsForSource(string source)
 {
     return(new MockFeed[]
     {
         new MockFeed
         {
             Type = MockFeedType.Source,
             Uri = source,
             Packages = new List <MockFeedPackage>
             {
                 new MockFeedPackage
                 {
                     PackageId = TestPackageId.ToString(),
                     Version = TestPackageVersion
                 }
             }
         }
     });
 }
Пример #6
0
 private static IEnumerable <MockFeed> GetMockFeedsForConfigFile(FilePath nugetConfig)
 {
     return(new MockFeed[]
     {
         new MockFeed
         {
             Type = MockFeedType.ExplicitNugetConfig,
             Uri = nugetConfig.Value,
             Packages = new List <MockFeedPackage>
             {
                 new MockFeedPackage
                 {
                     PackageId = TestPackageId.ToString(),
                     Version = TestPackageVersion
                 }
             }
         }
     });
 }
 private static List <MockFeed> GetOfflineMockFeed()
 {
     return(new List <MockFeed>
     {
         new MockFeed
         {
             Type = MockFeedType.ImplicitAdditionalFeed,
             Uri = GetTestLocalFeedPath(),
             Packages = new List <MockFeedPackage>
             {
                 new MockFeedPackage
                 {
                     PackageId = TestPackageId.ToString(),
                     Version = TestPackageVersion,
                     ToolCommandName = "SimulatorCommand"
                 }
             }
         }
     });
 }
 private static List <MockFeed> GetMockFeedsForSource(string source)
 {
     return(new List <MockFeed>
     {
         new MockFeed
         {
             Type = MockFeedType.ImplicitAdditionalFeed,
             Uri = source,
             Packages = new List <MockFeedPackage>
             {
                 new MockFeedPackage
                 {
                     PackageId = TestPackageId.ToString(),
                     Version = TestPackageVersion,
                     ToolCommandName = "SimulatorCommand"
                 }
             }
         }
     });
 }
        public void GivenAConfigFileRootDirectoryPackageInstallSucceedsViaFindingNugetConfigInParentDir(
            bool testMockBehaviorIsInSync)
        {
            var nugetConfigPath            = GenerateRandomNugetConfigFilePath();
            var subDirUnderNugetConfigPath = nugetConfigPath.GetDirectoryPath().WithSubDirectories("sub");

            var onlyNugetConfigInParentDirHasPackagesFeed = new List <MockFeed>
            {
                new MockFeed
                {
                    Type     = MockFeedType.FeedFromLookUpNugetConfig,
                    Uri      = nugetConfigPath.Value,
                    Packages = new List <MockFeedPackage>
                    {
                        new MockFeedPackage
                        {
                            PackageId       = TestPackageId.ToString(),
                            Version         = TestPackageVersion,
                            ToolCommandName = "SimulatorCommand"
                        }
                    }
                }
            };

            var(store, storeQuery, installer, uninstaller, reporter, fileSystem) = Setup(
                useMock: testMockBehaviorIsInSync,
                writeLocalFeedToNugetConfig: nugetConfigPath,
                feeds: onlyNugetConfigInParentDirHasPackagesFeed);

            fileSystem.Directory.CreateDirectory(subDirUnderNugetConfigPath.Value);

            var package = installer.InstallPackage(
                new PackageLocation(rootConfigDirectory: subDirUnderNugetConfigPath),
                packageId: TestPackageId,
                versionRange: VersionRange.Parse(TestPackageVersion),
                targetFramework: _testTargetframework);

            AssertPackageInstall(reporter, fileSystem, package, store, storeQuery);

            uninstaller.Uninstall(package.PackageDirectory);
        }
Пример #10
0
        public void GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds(bool testMockBehaviorIsInSync)
        {
            IToolPackageInstaller   installer   = null;
            IToolPackageUninstaller uninstaller = null;

            if (testMockBehaviorIsInSync == false)
            {
                var testFeedWithOnlyPreviewPackages =
                    Path.Combine(Path.GetTempPath(),
                                 Path.GetRandomFileName());

                Directory.CreateDirectory(testFeedWithOnlyPreviewPackages);
                var tempFeed = GetTestLocalFeedPath();
                File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.1.0.4.nupkg"),
                          Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.1.0.4.nupkg"));
                File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.2.0.1-preview1.nupkg"),
                          Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.2.0.1-preview1.nupkg"));

                var(store, storeQuery, realInstaller, realUninstaller, reporter, fileSystem) = Setup(
                    useMock: testMockBehaviorIsInSync,
                    offlineFeed: new DirectoryPath(testFeedWithOnlyPreviewPackages),
                    feeds: GetOfflineMockFeed());

                installer   = realInstaller;
                uninstaller = realUninstaller;
            }
            else
            {
                var fileSystem = new FileSystemMockBuilder().Build();
                var root       = new DirectoryPath(_testAssetsManager
                                                   .CreateTestDirectory(nameof(GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds) +
                                                                        testMockBehaviorIsInSync).Path);
                var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem);
                var store      = toolPackageStoreMock;
                var storeQuery = toolPackageStoreMock;
                installer = new ToolPackageInstallerMock(
                    fileSystem: fileSystem,
                    store: toolPackageStoreMock,
                    projectRestorer: new ProjectRestorerMock(
                        fileSystem: fileSystem,
                        reporter: new BufferedReporter(),
                        feeds: new List <MockFeed>
                {
                    new MockFeed
                    {
                        Type     = MockFeedType.ImplicitAdditionalFeed,
                        Packages = new List <MockFeedPackage>
                        {
                            new MockFeedPackage
                            {
                                PackageId       = TestPackageId.ToString(),
                                Version         = "1.0.4",
                                ToolCommandName = "SimulatorCommand"
                            },
                            new MockFeedPackage
                            {
                                PackageId       = TestPackageId.ToString(),
                                Version         = "2.0.1-preview1",
                                ToolCommandName = "SimulatorCommand"
                            }
                        }
                    }
                }));
                uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock);
            }


            var package = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId,
                                                   versionRange: VersionRange.Parse("*-*"), targetFramework: _testTargetframework);

            package.Version.ToNormalizedString().Should().Be("2.0.1-preview1");

            uninstaller.Uninstall(package.PackageDirectory);

            var package2 = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId,
                                                    versionRange: VersionRange.Parse("2.0*-*"), targetFramework: _testTargetframework);

            package2.Version.ToNormalizedString().Should().Be("2.0.1-preview1");

            uninstaller.Uninstall(package.PackageDirectory);
        }