public static string GetName(this TfvcItem source)
        {
            var index = source.Path.LastIndexOf('/');

            if (index <= 0)
            {
                return(source.Path);
            }

            return(source.Path.Substring(index + 1));
        }
        public void Map([Values] bool isFolder)
        {
            var sourceTool = SetUpFake();

            var input = new TfvcItem
            {
                Path     = "testPath",
                IsFolder = isFolder
            };

            var result = sourceTool.Map(input, "repository", "branch");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.SourcePath, Is.EqualTo(input.Path));
            Assert.That(result.IsDirectory, Is.EqualTo(input.IsFolder));
        }
        public void UpdateSourceInformation_Succeeds([Values(true, false)] bool isDirectory)
        {
            var sourceInfo = new SourceInformation(SourceType.TfsVc, "sourcePath", isDirectory);
            var item       = new TfvcItem
            {
                Path = "itemPath"
            };

            var sourceTool = SetUpFake();

            sourceTool.UpdateSourceInformation(sourceInfo, item);

            Assert.That(sourceInfo, Is.Not.Null);
            Assert.That(sourceInfo.GitRepositoryName, Is.EqualTo(sourceInfo.GitRepositoryName));
            Assert.That(sourceInfo.GitBranch, Is.EqualTo(sourceInfo.GitBranch));
            Assert.That(sourceInfo.SourcePath, Is.EqualTo(item.Path));
            Assert.That(sourceInfo.SourceType, Is.EqualTo(sourceInfo.SourceType));
        }
        public static void DeleteItem_Succeeds()
        {
            var vcSourceTool = SetUpMockSourceTool(out var vsTsToolMock, out var tfVcClientMock);

            var sourceInformation = new SourceInformation(SourceType.TfsVc, "$/Apollo/junkPath", true);
            var existingItem      = new TfvcItem();

            Assert.That(() => vcSourceTool.DeleteItem(sourceInformation, existingItem), Throws.Nothing);

            vsTsToolMock.VerifyGet(x => x.TfVcClient);
            tfVcClientMock.Verify(
                x => x.CreateChangesetAsync(
                    It.IsAny <TfvcChangeset>(),
                    It.IsAny <string>(),
                    It.IsAny <object>(),
                    It.IsAny <CancellationToken>()),
                Times.Once);
        }
Ejemplo n.º 5
0
            public TFSWebFileItem(TfvcItem x, VssConnection conn, BuildConfig config, TfvcHttpClient client)
            {
                this.Client = client;
                this.x      = x;
                this.conn   = conn;
                string path = x.Path;

                path        = path.Substring(config.RootFolder.Length);
                Name        = System.IO.Path.GetFileName(path);
                Folder      = path;
                IsDirectory = x.IsFolder;
                if (!x.IsFolder)
                {
                    Folder = Folder.Substring(0, Folder.Length - Name.Length);
                }
                Url          = x.Url;
                this.Version = x.ChangesetVersion.ToString();
                this.Url     = config.RootFolder + "/" + Folder + Name;
            }
        public static async Task <TfvcItem> FindItemAsync(this TfvcHttpClient source, string itemPath, bool throwIfNotFound, CancellationToken cancellationToken)
        {
            TfvcItem item = null;

            try
            {
                item = await source.TryCatchAsync(c => c.GetItemAsync(itemPath, cancellationToken: cancellationToken)).ConfigureAwait(false);
            } catch (VssServiceException e)
            {
                if (!e.IsWarning())
                {
                    throw e;
                }

                /* Ignore because we cannot get the message code from an "item not found" error */
            };

            if (item == null && throwIfNotFound)
            {
                throw new Exception("Item not found.");
            }

            return(item);
        }