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/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/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/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/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..a7eda66f 100644 --- a/src/TeamCitySharp/ITeamCityClient.cs +++ b/src/TeamCitySharp/ITeamCityClient.cs @@ -1,4 +1,4 @@ -using TeamCitySharp.ActionTypes; +using TeamCitySharp.ActionTypes; namespace TeamCitySharp { @@ -7,8 +7,9 @@ public interface ITeamCityClient void Connect(string userName, string password); void ConnectAsGuest(); bool Authenticate(); - + IBuilds Builds { get; } + IBuild Build { get; } IBuildConfigs BuildConfigs { get; } IProjects Projects { get; } IServerInformation ServerInformation { get; } @@ -16,6 +17,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/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 eeb9bb82..a832ff52 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,8 @@ public class TeamCityClient : IClientConnection, ITeamCityClient private IVcsRoots _vcsRoots; private IChanges _changes; private IBuildArtifacts _artifacts; + private IBranches _branches; + private IBuild _build; public TeamCityClient(string hostName, bool useSsl = false) { @@ -37,8 +39,13 @@ public bool Authenticate() } public IBuilds Builds - { - get { return _builds ?? (_builds = new Builds(_caller)); } + { + get { return _builds ?? (_builds = new Builds(_caller)); } + } + + public IBuild Build + { + get { return _build ?? (_build = new BuildI(_caller)); } } public IBuildConfigs BuildConfigs @@ -55,8 +62,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 +79,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..22552a10 100644 --- a/src/TeamCitySharp/TeamCitySharp.csproj +++ b/src/TeamCitySharp/TeamCitySharp.csproj @@ -51,11 +51,15 @@ + + + + @@ -67,6 +71,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/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 95e8426c..64c6db5f 100644 --- a/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj +++ b/src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj @@ -47,6 +47,8 @@ Code + + Code