Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Agent pool #112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/TeamCitySharp/ActionTypes/AgentPools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using TeamCitySharp.Connection;
using TeamCitySharp.DomainEntities;

namespace TeamCitySharp.ActionTypes
{
internal class AgentPools : IAgentPools
{
private readonly TeamCityCaller _caller;

internal AgentPools(TeamCityCaller caller)
{
_caller = caller;
}

public List<AgentPool> All()
{
var agentPoolWrapper = _caller.Get<AgentPoolWrapper>("/app/rest/agentPools");

return agentPoolWrapper.AgentPool;
}

public List<Agent> AgentsByAgentPoolId(string id)
{
var agentWrapper = _caller.GetFormat<AgentWrapper>("/app/rest/agentPools/id:{0}/agents", id);

return agentWrapper?.Agent;
}

public List<Project> ProjectsByAgentPoolId(string id)
{
var projectWrapper = _caller.GetFormat<ProjectWrapper>("/app/rest/agentPools/id:{0}/projects", id);
return projectWrapper?.Project;
}
}
}
14 changes: 14 additions & 0 deletions src/TeamCitySharp/ActionTypes/IAgentPools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using TeamCitySharp.DomainEntities;

namespace TeamCitySharp.ActionTypes
{
public interface IAgentPools
{
List<AgentPool> All();

List<Agent> AgentsByAgentPoolId(string id);

List<Project> ProjectsByAgentPoolId(string id);
}
}
15 changes: 15 additions & 0 deletions src/TeamCitySharp/DomainEntities/AgentPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TeamCitySharp.DomainEntities
{
public class AgentPool
{
public string Name { get; set; }
public string Id { get; set; }
public string Href { get; set; }


public override string ToString()
{
return Name;
}
}
}
9 changes: 9 additions & 0 deletions src/TeamCitySharp/DomainEntities/AgentPoolWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace TeamCitySharp.DomainEntities
{
public class AgentPoolWrapper
{
public List<AgentPool> AgentPool { get; set; }
}
}
37 changes: 19 additions & 18 deletions src/TeamCitySharp/DomainEntities/Project.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
namespace TeamCitySharp.DomainEntities
{
public class Project
{
public override string ToString()
{
return Name;
}

public bool Archived { get; set; }
public string Description { get; set; }
public string Href { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public string WebUrl { get; set; }

namespace TeamCitySharp.DomainEntities
{
public class Project
{
public override string ToString()
{
return Name;
}

public bool Archived { get; set; }
public string Description { get; set; }
public string Href { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public string WebUrl { get; set; }
public string ParentProjectId { get; set; }

public BuildTypeWrapper BuildTypes { get; set; }
public Parameters Parameters { get; set; }
}
public Parameters Parameters { get; set; }
}
}
18 changes: 9 additions & 9 deletions src/TeamCitySharp/DomainEntities/Server.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;

namespace TeamCitySharp.DomainEntities
{
public class Server
{
public string VersonMajor { get; set; }
public string Version { get; set; }
public string BuildNumber { get; set; }
namespace TeamCitySharp.DomainEntities
{
public class Server
{
public string VersonMajor { get; set; }
public string Version { get; set; }
public string BuildNumber { get; set; }
public DateTime CurrentTime { get; set; }
public DateTime StartTime { get; set; }
}
public DateTime StartTime { get; set; }
}
}
7 changes: 4 additions & 3 deletions src/TeamCitySharp/ITeamCityClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using TeamCitySharp.ActionTypes;
using TeamCitySharp.ActionTypes;

namespace TeamCitySharp
{
Expand All @@ -7,15 +7,16 @@ public interface ITeamCityClient
void Connect(string userName, string password);
void ConnectAsGuest();
bool Authenticate();

IBuilds Builds { get; }
IBuildConfigs BuildConfigs { get; }
IProjects Projects { get; }
IServerInformation ServerInformation { get; }
IUsers Users { get; }
IAgents Agents { get; }
IAgentPools AgentPools { get; }
IVcsRoots VcsRoots { get; }
IChanges Changes { get; }
IBuildArtifacts Artifacts { get; }
IBuildArtifacts Artifacts { get; }
}
}
2 changes: 1 addition & 1 deletion src/TeamCitySharp/Locators/BuildLocator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace TeamCitySharp.Locators
Expand Down
21 changes: 13 additions & 8 deletions src/TeamCitySharp/TeamCityClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using TeamCitySharp.ActionTypes;
using TeamCitySharp.ActionTypes;
using TeamCitySharp.Connection;

namespace TeamCitySharp
Expand All @@ -12,6 +12,7 @@ public class TeamCityClient : IClientConnection, ITeamCityClient
private IServerInformation _serverInformation;
private IUsers _users;
private IAgents _agents;
private IAgentPools _agentPools;
private IVcsRoots _vcsRoots;
private IChanges _changes;
private IBuildArtifacts _artifacts;
Expand All @@ -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
Expand All @@ -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)); }
}
Expand All @@ -66,19 +67,23 @@ public IAgents Agents
get { return _agents ?? (_agents = new Agents(_caller)); }
}

public IAgentPools AgentPools
{
get { return _agentPools ?? (_agentPools = new AgentPools(_caller)); }
}
public IVcsRoots VcsRoots
{
get { return _vcsRoots ?? (_vcsRoots = new VcsRoots(_caller)); }
}

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)); }
}
}
}
}
4 changes: 4 additions & 0 deletions src/TeamCitySharp/TeamCitySharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActionTypes\AgentPools.cs" />
<Compile Include="ActionTypes\Agents.cs" />
<Compile Include="ActionTypes\BackupOptions.cs" />
<Compile Include="ActionTypes\BuildArtifacts.cs" />
<Compile Include="ActionTypes\BuildConfigs.cs" />
<Compile Include="ActionTypes\Builds.cs" />
<Compile Include="ActionTypes\Changes.cs" />
<Compile Include="ActionTypes\IAgentPools.cs" />
<Compile Include="ActionTypes\IAgents.cs" />
<Compile Include="ActionTypes\IBuildArtifacts.cs" />
<Compile Include="ActionTypes\IBuildConfigs.cs" />
Expand All @@ -70,6 +72,8 @@
<Compile Include="ActionTypes\Projects.cs" />
<Compile Include="ActionTypes\ServerInformation.cs" />
<Compile Include="Connection\ITeamCityCaller.cs" />
<Compile Include="DomainEntities\AgentPool.cs" />
<Compile Include="DomainEntities\AgentPoolWrapper.cs" />
<Compile Include="TeamCityClient.cs" />
<Compile Include="ActionTypes\Users.cs" />
<Compile Include="ActionTypes\VcsRoots.cs" />
Expand Down
54 changes: 54 additions & 0 deletions src/Tests/UnitTests/ActionTypes/AgentPoolTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


using System.Diagnostics;
using NUnit.Framework;

namespace TeamCitySharp.ActionTypes
{
[TestFixture]
public class AgentPoolTest
{
private TeamCityClient _client;

[SetUp]
public void SetUp()
{
_client = new TeamCityClient("amcon-tmcityp1.netadds.net:80");
_client.Connect("friedrich.brunzema", "");
}

[Test]
public void ListPools()
{

var pools = _client.AgentPools.All();
foreach (var pool in pools)
{
Debug.WriteLine(pool.Name + " Id:" + pool.Id);
}
Assert.That(pools.Count, Is.GreaterThan(10));
}

[Test]
public void AgentsByAgentPoolId()
{
var agents = _client.AgentPools.AgentsByAgentPoolId("23");
foreach (var agent in agents)
{
Debug.WriteLine(agent.Name + " Id:" + agent.Id);
}
Assert.That(agents.Count, Is.GreaterThan(0));
}

[Test]
public void ProjectsByAgentPoolId()
{
var projects = _client.AgentPools.ProjectsByAgentPoolId("23");
foreach (var project in projects)
{
Debug.WriteLine(project.Name + " Id:" + project.Id + " ParentProjId:" + project.ParentProjectId);
}
Assert.That(projects.Count, Is.GreaterThan(0));
}
}
}
1 change: 1 addition & 0 deletions src/Tests/UnitTests/TeamCitySharp.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActionTypes\AgentPoolTest.cs" />
<Compile Include="ActionTypes\ServerInformationTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down