Пример #1
0
        public static bool TryCreateUpgrader(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            LocalScalarConfig scalarConfig,
            ICredentialStore credentialStore,
            bool dryRun,
            bool noVerify,
            out ProductUpgrader newUpgrader,
            out string error)
        {
            Dictionary <string, string> entries;

            if (!scalarConfig.TryGetAllConfig(out entries, out error))
            {
                newUpgrader = null;
                return(false);
            }

            bool containsUpgradeFeedUrl     = entries.ContainsKey(ScalarConstants.LocalScalarConfig.UpgradeFeedUrl);
            bool containsUpgradePackageName = entries.ContainsKey(ScalarConstants.LocalScalarConfig.UpgradeFeedPackageName);
            bool containsOrgInfoServerUrl   = entries.ContainsKey(ScalarConstants.LocalScalarConfig.OrgInfoServerUrl);

            if (!containsUpgradeFeedUrl && !containsUpgradePackageName)
            {
                error = "Custom upgrade feed is not configured";
                tracer.RelatedWarning(error);
                newUpgrader = null;
                return(false);
            }

            // We are configured for NuGet - determine if we are using OrgNuGetUpgrader or not
            if (containsOrgInfoServerUrl)
            {
                if (OrgNuGetUpgrader.TryCreate(
                        tracer,
                        fileSystem,
                        scalarConfig,
                        new HttpClient(),
                        credentialStore,
                        dryRun,
                        noVerify,
                        out OrgNuGetUpgrader orgNuGetUpgrader,
                        out error))
                {
                    // We were successfully able to load a NuGetUpgrader - use that.
                    newUpgrader = orgNuGetUpgrader;
                    return(true);
                }
                else
                {
                    tracer.RelatedError($"{nameof(TryCreateUpgrader)}: Could not create organization based upgrader. {error}");
                    newUpgrader = null;
                    return(false);
                }
            }
Пример #2
0
        public void SetUp()
        {
            MockLocalScalarConfig mockGvfsConfig = new MockLocalScalarConfigBuilder(
                DefaultRing,
                DefaultUpgradeFeedUrl,
                DefaultUpgradeFeedPackageName,
                DefaultOrgInfoServerUrl)
                                                   .WithUpgradeRing()
                                                   .WithUpgradeFeedPackageName()
                                                   .WithUpgradeFeedUrl()
                                                   .WithOrgInfoServerUrl()
                                                   .Build();

            this.upgraderConfig = new OrgNuGetUpgrader.OrgNuGetUpgraderConfig(this.tracer, mockGvfsConfig);
            this.upgraderConfig.TryLoad(out _);

            this.tracer = new MockTracer();

            this.mockNuGetFeed = new Mock <NuGetFeed>(
                DefaultUpgradeFeedUrl,
                DefaultUpgradeFeedPackageName,
                this.downloadDirectoryPath,
                null,
                ScalarPlatform.Instance.UnderConstruction.SupportsNuGetEncryption,
                this.tracer,
                this.mockFileSystem);

            this.mockFileSystem = new MockFileSystem(
                new MockDirectory(
                    Path.GetDirectoryName(this.downloadDirectoryPath),
                    new[] { new MockDirectory(this.downloadDirectoryPath, null, null) },
                    null));

            this.mockCredentialManager = new Mock <ICredentialStore>();
            string credentialManagerString = "value";
            string emptyString             = string.Empty;

            this.mockCredentialManager.Setup(foo => foo.TryGetCredential(It.IsAny <ITracer>(), It.IsAny <string>(), out credentialManagerString, out credentialManagerString, out credentialManagerString)).Returns(true);

            this.httpMessageHandlerMock = new Mock <HttpMessageHandler>();

            this.httpMessageHandlerMock.Protected().As <IHttpMessageHandlerProtectedMembers>()
            .Setup(m => m.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(this.ConstructResponseContent(NewerVersion))
            });

            HttpClient httpClient = new HttpClient(this.httpMessageHandlerMock.Object);

            this.upgrader = new OrgNuGetUpgrader(
                CurrentVersion,
                this.tracer,
                this.mockFileSystem,
                httpClient,
                false,
                false,
                this.upgraderConfig,
                "windows",
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object);
        }