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

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name          = _expectedRepositoryId,
                        Url           = new Uri(_expectedUrl),
                        Authorization = new EndpointAuthorization
                        {
                            Scheme = EndpointAuthorizationSchemes.OAuth
                        }
                    }
                });

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

                // verify TfsGit endpoint is set correctly
                _sourceProvider.Verify(
                    x => x.GetSourceAsync(
                        It.IsAny <IExecutionContext>(),
                        It.Is <ServiceEndpoint>(y => y.Url.Equals(new Uri(_expectedUrl)) && y.Authorization.Scheme.Equals(EndpointAuthorizationSchemes.OAuth) && y.Name.Equals(_expectedRepositoryId) && y.Data.ContainsKey(Constants.EndpointData.SourcesDirectory) && y.Data.ContainsKey(Constants.EndpointData.SourceBranch) &&
                                                y.Data.ContainsKey(Constants.EndpointData.SourceVersion) && y.Data.ContainsKey("fetchDepth") && y.Data.ContainsKey("GitLfsSupport") && y.Data.ContainsKey(EndpointData.CheckoutSubmodules)),
                        It.IsAny <CancellationToken>()));
            }
        }
Пример #2
0
        public void TfsGitArtifactShouldMapSourceProviderInvalidOperationExceptionToArtifactDownloadException()
        {
            using (TestHostContext tc = Setup())
            {
                var tfsGitArtifact = new TfsGitArtifact();
                tfsGitArtifact.Initialize(tc);

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name          = _expectedRepositoryId,
                        Url           = new Uri(_expectedUrl),
                        Authorization = new EndpointAuthorization
                        {
                            Scheme = EndpointAuthorizationSchemes.OAuth
                        }
                    }
                });

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

                Assert.Throws <ArtifactDownloadException>(
                    () => tfsGitArtifact.DownloadAsync(_ec.Object, _artifactDefinition, "localFolderPath").SyncResult());
            }
        }
Пример #3
0
        public void ShouldThrowIfEndpointsDoNotContainTfsGitEndpoint()
        {
            using (TestHostContext tc = Setup())
            {
                var artifact = new TfsGitArtifact();

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

                Assert.Throws <InvalidOperationException>(
                    () => artifact.DownloadAsync(_ec.Object, _artifactDefinition, "temp").SyncResult());
            }
        }