Пример #1
0
        public async void GitHubArtifactShouldCallGetSourceWithCorrectParameter()
        {
            using (TestHostContext tc = Setup())
            {
                var gitHubArtifact = new GitHubArtifact();
                gitHubArtifact.Initialize(tc);
                var expectedPath = "expectedLocalPath";

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name          = _githubConnectionName,
                        Url           = new Uri("http://contoso.visualstudio.com"),
                        Authorization = new EndpointAuthorization()
                    }
                });

                await gitHubArtifact.DownloadAsync(_ec.Object, _artifactDefinition, expectedPath);

                // verify github endpoint is set correctly
                _sourceProvider.Verify(
                    x => x.GetSourceAsync(
                        It.IsAny <IExecutionContext>(),
                        It.Is <ServiceEndpoint>(y => y.Url.Equals(new Uri(_expectedGitHubUrl)) && y.Authorization.Scheme.Equals(EndpointAuthorizationSchemes.OAuth) &&
                                                y.Data.ContainsKey(Constants.EndpointData.SourcesDirectory) && y.Data.ContainsKey(Constants.EndpointData.SourceBranch) &&
                                                y.Data.ContainsKey(Constants.EndpointData.SourceVersion)),
                        It.IsAny <CancellationToken>()));
            }
        }
Пример #2
0
        public void GitHubArtifactShouldMapSourceProviderInvalidOperationExceptionToArtifactDownloadException()
        {
            using (TestHostContext tc = Setup())
            {
                var gitHubArtifact = new GitHubArtifact();
                gitHubArtifact.Initialize(tc);

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name          = _githubConnectionName,
                        Url           = new Uri("http://contoso.visualstudio.com"),
                        Authorization = new EndpointAuthorization()
                    }
                });

                _sourceProvider.Setup(
                    x => x.GetSourceAsync(It.IsAny <IExecutionContext>(), It.IsAny <ServiceEndpoint>(), It.IsAny <CancellationToken>()))
                .Returns(() => { throw new InvalidOperationException("InvalidOperationException"); });

                Assert.Throws <ArtifactDownloadException>(
                    () => gitHubArtifact.DownloadAsync(_ec.Object, _artifactDefinition, "localFolderPath").SyncResult());
            }
        }