From 4726a71c843aa524d8d32589bba2a5ae99b7a036 Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Sat, 9 Nov 2013 23:34:18 -0500 Subject: [PATCH 1/2] Added support for getting all the available branches for a build type. --- src/TeamCitySharp/ActionTypes/Branches.cs | 26 +++++++++++++++++ src/TeamCitySharp/ActionTypes/IBranches.cs | 14 +++++++++ src/TeamCitySharp/DomainEntities/Branch.cs | 13 +++++++++ .../DomainEntities/BranchesWrapper.cs | 12 ++++++++ src/TeamCitySharp/ITeamCityClient.cs | 7 +++-- src/TeamCitySharp/TeamCityClient.cs | 22 +++++++++----- src/TeamCitySharp/TeamCitySharp.csproj | 4 +++ .../IntegrationTests/SampleBranchesUsage.cs | 29 +++++++++++++++++++ .../TeamCitySharp.IntegrationTests.csproj | 1 + 9 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 src/TeamCitySharp/ActionTypes/Branches.cs create mode 100644 src/TeamCitySharp/ActionTypes/IBranches.cs create mode 100644 src/TeamCitySharp/DomainEntities/Branch.cs create mode 100644 src/TeamCitySharp/DomainEntities/BranchesWrapper.cs create mode 100644 src/Tests/IntegrationTests/SampleBranchesUsage.cs diff --git a/src/TeamCitySharp/ActionTypes/Branches.cs b/src/TeamCitySharp/ActionTypes/Branches.cs new file mode 100644 index 00000000..016ba70e --- /dev/null +++ b/src/TeamCitySharp/ActionTypes/Branches.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TeamCitySharp.Connection; +using TeamCitySharp.DomainEntities; +using TeamCitySharp.Locators; + +namespace TeamCitySharp.ActionTypes +{ + internal class Branches : IBranches + { + private readonly TeamCityCaller _caller; + + internal Branches(TeamCityCaller caller) + { + _caller = caller; + } + + public List ByBuildLocator(BuildTypeLocator locator) + { + var branchesWrapper = _caller.GetFormat("/app/rest/buildTypes/{0}/branches", locator); + return branchesWrapper.Branch; + } + } +} diff --git a/src/TeamCitySharp/ActionTypes/IBranches.cs b/src/TeamCitySharp/ActionTypes/IBranches.cs new file mode 100644 index 00000000..91e298e6 --- /dev/null +++ b/src/TeamCitySharp/ActionTypes/IBranches.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TeamCitySharp.DomainEntities; +using TeamCitySharp.Locators; + +namespace TeamCitySharp.ActionTypes +{ + public interface IBranches + { + List ByBuildLocator(BuildTypeLocator locator); + } +} diff --git a/src/TeamCitySharp/DomainEntities/Branch.cs b/src/TeamCitySharp/DomainEntities/Branch.cs new file mode 100644 index 00000000..0f074c50 --- /dev/null +++ b/src/TeamCitySharp/DomainEntities/Branch.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamCitySharp.DomainEntities +{ + public class Branch + { + public string Name { get; set; } + public bool Default { get; set; } + } +} diff --git a/src/TeamCitySharp/DomainEntities/BranchesWrapper.cs b/src/TeamCitySharp/DomainEntities/BranchesWrapper.cs new file mode 100644 index 00000000..b16e7260 --- /dev/null +++ b/src/TeamCitySharp/DomainEntities/BranchesWrapper.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamCitySharp.DomainEntities +{ + public class BranchesWrapper + { + public List Branch { get; set; } + } +} diff --git a/src/TeamCitySharp/ITeamCityClient.cs b/src/TeamCitySharp/ITeamCityClient.cs index f63f97d3..b84e639f 100644 --- a/src/TeamCitySharp/ITeamCityClient.cs +++ b/src/TeamCitySharp/ITeamCityClient.cs @@ -1,4 +1,4 @@ -using TeamCitySharp.ActionTypes; +using TeamCitySharp.ActionTypes; namespace TeamCitySharp { @@ -7,7 +7,7 @@ public interface ITeamCityClient void Connect(string userName, string password); void ConnectAsGuest(); bool Authenticate(); - + IBuilds Builds { get; } IBuildConfigs BuildConfigs { get; } IProjects Projects { get; } @@ -16,6 +16,7 @@ public interface ITeamCityClient IAgents Agents { get; } IVcsRoots VcsRoots { get; } IChanges Changes { get; } - IBuildArtifacts Artifacts { get; } + IBuildArtifacts Artifacts { get; } + IBranches Branches { get; } } } \ No newline at end of file diff --git a/src/TeamCitySharp/TeamCityClient.cs b/src/TeamCitySharp/TeamCityClient.cs index eeb9bb82..5b993d12 100644 --- a/src/TeamCitySharp/TeamCityClient.cs +++ b/src/TeamCitySharp/TeamCityClient.cs @@ -1,4 +1,4 @@ -using TeamCitySharp.ActionTypes; +using TeamCitySharp.ActionTypes; using TeamCitySharp.Connection; namespace TeamCitySharp @@ -15,6 +15,7 @@ public class TeamCityClient : IClientConnection, ITeamCityClient private IVcsRoots _vcsRoots; private IChanges _changes; private IBuildArtifacts _artifacts; + private IBranches _branches; public TeamCityClient(string hostName, bool useSsl = false) { @@ -37,8 +38,8 @@ public bool Authenticate() } public IBuilds Builds - { - get { return _builds ?? (_builds = new Builds(_caller)); } + { + get { return _builds ?? (_builds = new Builds(_caller)); } } public IBuildConfigs BuildConfigs @@ -55,8 +56,8 @@ public IServerInformation ServerInformation { get { return _serverInformation ?? (_serverInformation = new ServerInformation(_caller)); } } - - public IUsers Users + + public IUsers Users { get { return _users ?? (_users = new Users(_caller)); } } @@ -72,13 +73,18 @@ public IVcsRoots VcsRoots } public IChanges Changes - { - get { return _changes ?? (_changes = new Changes(_caller)); } + { + get { return _changes ?? (_changes = new Changes(_caller)); } } public IBuildArtifacts Artifacts { get { return _artifacts ?? (_artifacts = new BuildArtifacts(_caller)); } } + + public IBranches Branches + { + get { return _branches ?? (_branches = new Branches(_caller)); } + } } -} +} diff --git a/src/TeamCitySharp/TeamCitySharp.csproj b/src/TeamCitySharp/TeamCitySharp.csproj index 2e7df5aa..0f6a6ac3 100644 --- a/src/TeamCitySharp/TeamCitySharp.csproj +++ b/src/TeamCitySharp/TeamCitySharp.csproj @@ -51,11 +51,13 @@ + + @@ -67,6 +69,8 @@ + + diff --git a/src/Tests/IntegrationTests/SampleBranchesUsage.cs b/src/Tests/IntegrationTests/SampleBranchesUsage.cs new file mode 100644 index 00000000..64dd134b --- /dev/null +++ b/src/Tests/IntegrationTests/SampleBranchesUsage.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using TeamCitySharp.Locators; + +namespace TeamCitySharp.IntegrationTests +{ + public class when_interacting_to_get_build_branches + { + private ITeamCityClient _client; + + [SetUp] + public void SetUp() + { + _client = new TeamCityClient("teamcity.codebetter.com"); + _client.Connect("teamcitysharpuser", "qwerty"); + } + + [Test] + public void it_returns_all_branches() + { + var branches = _client.Branches.ByBuildLocator(BuildTypeLocator.WithId("bt787" /*git-tfs*/)); + + Assert.That(branches.Any(), "Could not get any branches from the tfs-git project."); + } + } +} diff --git a/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj b/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj index 95e8426c..5e13066e 100644 --- a/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj +++ b/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj @@ -47,6 +47,7 @@ Code + Code From 109fa0359a7c09852124fb74954dcb16750a6755 Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Tue, 12 Nov 2013 17:40:56 -0500 Subject: [PATCH 2/2] Added support for querying a single build --- src/TeamCitySharp/ActionTypes/Build.cs | 27 ++++++++++++++++ src/TeamCitySharp/ActionTypes/IBuild.cs | 14 +++++++++ src/TeamCitySharp/ITeamCityClient.cs | 1 + src/TeamCitySharp/Locators/BuildLocator.cs | 2 +- src/TeamCitySharp/TeamCityClient.cs | 6 ++++ src/TeamCitySharp/TeamCitySharp.csproj | 2 ++ .../IntegrationTests/SampleBuildUsage.cs | 31 +++++++++++++++++++ .../TeamCitySharp.IntegrationTests.csproj | 1 + 8 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/TeamCitySharp/ActionTypes/Build.cs create mode 100644 src/TeamCitySharp/ActionTypes/IBuild.cs create mode 100644 src/Tests/IntegrationTests/SampleBuildUsage.cs diff --git a/src/TeamCitySharp/ActionTypes/Build.cs b/src/TeamCitySharp/ActionTypes/Build.cs new file mode 100644 index 00000000..da253ef1 --- /dev/null +++ b/src/TeamCitySharp/ActionTypes/Build.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TeamCitySharp.Connection; +using TeamCitySharp.DomainEntities; + +namespace TeamCitySharp.ActionTypes +{ + /// + /// This class is named BuildI to avoid confusion with the Build domain entity + /// + internal class BuildI : IBuild + { + private readonly TeamCityCaller _caller; + + internal BuildI(TeamCityCaller caller) + { + _caller = caller; + } + + public Build ByBuildLocator(Locators.BuildLocator locator) + { + return _caller.GetFormat(string.Format("/app/rest/builds/{0}", locator)); + } + } +} diff --git a/src/TeamCitySharp/ActionTypes/IBuild.cs b/src/TeamCitySharp/ActionTypes/IBuild.cs new file mode 100644 index 00000000..c071d5f1 --- /dev/null +++ b/src/TeamCitySharp/ActionTypes/IBuild.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TeamCitySharp.DomainEntities; +using TeamCitySharp.Locators; + +namespace TeamCitySharp.ActionTypes +{ + public interface IBuild + { + Build ByBuildLocator(BuildLocator locator); + } +} diff --git a/src/TeamCitySharp/ITeamCityClient.cs b/src/TeamCitySharp/ITeamCityClient.cs index b84e639f..a7eda66f 100644 --- a/src/TeamCitySharp/ITeamCityClient.cs +++ b/src/TeamCitySharp/ITeamCityClient.cs @@ -9,6 +9,7 @@ public interface ITeamCityClient bool Authenticate(); IBuilds Builds { get; } + IBuild Build { get; } IBuildConfigs BuildConfigs { get; } IProjects Projects { get; } IServerInformation ServerInformation { get; } diff --git a/src/TeamCitySharp/Locators/BuildLocator.cs b/src/TeamCitySharp/Locators/BuildLocator.cs index 1823d6d7..e8ab9777 100644 --- a/src/TeamCitySharp/Locators/BuildLocator.cs +++ b/src/TeamCitySharp/Locators/BuildLocator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace TeamCitySharp.Locators diff --git a/src/TeamCitySharp/TeamCityClient.cs b/src/TeamCitySharp/TeamCityClient.cs index 5b993d12..a832ff52 100644 --- a/src/TeamCitySharp/TeamCityClient.cs +++ b/src/TeamCitySharp/TeamCityClient.cs @@ -16,6 +16,7 @@ public class TeamCityClient : IClientConnection, ITeamCityClient private IChanges _changes; private IBuildArtifacts _artifacts; private IBranches _branches; + private IBuild _build; public TeamCityClient(string hostName, bool useSsl = false) { @@ -42,6 +43,11 @@ public IBuilds Builds get { return _builds ?? (_builds = new Builds(_caller)); } } + public IBuild Build + { + get { return _build ?? (_build = new BuildI(_caller)); } + } + public IBuildConfigs BuildConfigs { get { return _buildConfigs ?? (_buildConfigs = new BuildConfigs(_caller)); } diff --git a/src/TeamCitySharp/TeamCitySharp.csproj b/src/TeamCitySharp/TeamCitySharp.csproj index 0f6a6ac3..22552a10 100644 --- a/src/TeamCitySharp/TeamCitySharp.csproj +++ b/src/TeamCitySharp/TeamCitySharp.csproj @@ -52,12 +52,14 @@ + + diff --git a/src/Tests/IntegrationTests/SampleBuildUsage.cs b/src/Tests/IntegrationTests/SampleBuildUsage.cs new file mode 100644 index 00000000..01071e80 --- /dev/null +++ b/src/Tests/IntegrationTests/SampleBuildUsage.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using TeamCitySharp.Locators; + +namespace TeamCitySharp.IntegrationTests +{ + public class when_interacting_to_get_a_build + { + private ITeamCityClient _client; + + [SetUp] + public void SetUp() + { + _client = new TeamCityClient("teamcity.codebetter.com"); + _client.Connect("teamcitysharpuser", "qwerty"); + } + + [Test] + public void it_can_returns_details_on_a_single_build() + { + // build http://teamcity.codebetter.com/viewLog.html?buildId=98727&tab=buildResultsDiv&buildTypeId=bt787 + var build = _client.Build.ByBuildLocator(BuildLocator.WithId(98727)); + + Assert.That(build, Is.Not.Null); + Assert.That(build.Id, Is.EqualTo("98727")); + } + } +} diff --git a/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj b/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj index 5e13066e..64c6db5f 100644 --- a/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj +++ b/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj @@ -48,6 +48,7 @@ Code + Code