예제 #1
0
        public void MissingEndpointShouldThrowException()
        {
            using (TestHostContext tc = Setup())
            {
                var artifact = new TfsVCArtifact();

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name = "Some endpoint name"
                    }
                });

                Assert.Throws <InvalidOperationException>(
                    () => artifact.DownloadAsync(_ec.Object, _artifactDefinition, "temp").SyncResult());
            }
        }
예제 #2
0
        public async void TfsVCArtifactShouldCallGetSourceWithCorrectParameter()
        {
            using (TestHostContext tc = Setup())
            {
                var tfsVCArtifact = new TfsVCArtifact();
                tfsVCArtifact.Initialize(tc);
                var workFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                                              $"_work_{Path.GetRandomFileName()}");
                var sourcesDirectory = Path.Combine(workFolder, _buildDirectory, "temp");
                _artifactDefinition.Details = tfsVCArtifact.GetArtifactDetails(
                    _ec.Object,
                    new AgentArtifactDefinition
                {
                    Details = JsonConvert.SerializeObject(new Dictionary <string, string>
                    {
                        { ArtifactDefinitionConstants.ProjectId, _projectId },
                        { ArtifactDefinitionConstants.RepositoryId, _repositoryId }
                    })
                });

                _ec.Setup(x => x.Endpoints)
                .Returns(
                    new List <ServiceEndpoint>
                {
                    new ServiceEndpoint
                    {
                        Name = _repositoryId,
                    }
                });

                await tfsVCArtifact.DownloadAsync(_ec.Object, _artifactDefinition, sourcesDirectory);

                // verify tfsvc endpoint is set correctly
                _sourceProvider.Verify(
                    x => x.GetSourceAsync(
                        It.IsAny <IExecutionContext>(),
                        It.Is <ServiceEndpoint>(y => y.Data.ContainsKey(EndpointData.TfvcWorkspaceMapping) && y.Data.ContainsKey(EndpointData.Clean) &&
                                                y.Data.ContainsKey(Constants.EndpointData.SourcesDirectory) && y.Data.ContainsKey(Constants.EndpointData.SourceVersion)),
                        It.IsAny <CancellationToken>()));
            }
        }