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

Commit 3c4fa9c

Browse files
committed
Implement statistics for builds (based on ewilde pull request on 19 Aug 2014, commit 0c773ee)
Allows retrieval of properties such as no. of passed tests in a given
1 parent 4fc8e0c commit 3c4fa9c

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using TeamCitySharp.DomainEntities;
3+
4+
namespace TeamCitySharp.ActionTypes
5+
{
6+
public interface IStatistics
7+
{
8+
List<Property> GetByBuildId(string buildId);
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using TeamCitySharp.Connection;
3+
using TeamCitySharp.DomainEntities;
4+
5+
namespace TeamCitySharp.ActionTypes
6+
{
7+
public class Statistics : IStatistics
8+
{
9+
private readonly TeamCityCaller _caller;
10+
11+
internal Statistics(TeamCityCaller caller)
12+
{
13+
_caller = caller;
14+
}
15+
16+
public List<Property> GetByBuildId(string buildId)
17+
{
18+
return _caller.GetFormat<Properties>("/app/rest/builds/id:{0}/statistics", buildId).Property;
19+
}
20+
}
21+
}

src/TeamCitySharp/ITeamCityClient.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using TeamCitySharp.ActionTypes;
1+
using TeamCitySharp.ActionTypes;
22

33
namespace TeamCitySharp
44
{
@@ -7,7 +7,7 @@ public interface ITeamCityClient
77
void Connect(string userName, string password);
88
void ConnectAsGuest();
99
bool Authenticate();
10-
10+
1111
IBuilds Builds { get; }
1212
IBuildConfigs BuildConfigs { get; }
1313
IProjects Projects { get; }
@@ -16,7 +16,8 @@ public interface ITeamCityClient
1616
IAgents Agents { get; }
1717
IVcsRoots VcsRoots { get; }
1818
IChanges Changes { get; }
19-
IBuildArtifacts Artifacts { get; }
20-
ITestOccurrences TestOccurrences { get; }
19+
IBuildArtifacts Artifacts { get; }
20+
ITestOccurrences TestOccurrences { get; }
21+
IStatistics Statistics { get; }
2122
}
2223
}

src/TeamCitySharp/TeamCityClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class TeamCityClient : IClientConnection, ITeamCityClient
1616
private IChanges _changes;
1717
private IBuildArtifacts _artifacts;
1818
private ITestOccurrences _testOccurrences;
19+
private IStatistics _statistics;
1920

2021
public TeamCityClient(string hostName, bool useSsl = false)
2122
{
@@ -86,5 +87,10 @@ public ITestOccurrences TestOccurrences
8687
{
8788
get { return _testOccurrences ?? (_testOccurrences = new TestOccurrences(_caller)); }
8889
}
90+
91+
public IStatistics Statistics
92+
{
93+
get { return _statistics ?? (_statistics = new Statistics(_caller)); }
94+
}
8995
}
9096
}

src/TeamCitySharp/TeamCitySharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@
6363
<Compile Include="ActionTypes\IChanges.cs" />
6464
<Compile Include="ActionTypes\IProjects.cs" />
6565
<Compile Include="ActionTypes\IServerInformation.cs" />
66+
<Compile Include="ActionTypes\IStatistics.cs" />
6667
<Compile Include="ActionTypes\ITestOccurrences.cs" />
6768
<Compile Include="ActionTypes\IUsers.cs" />
6869
<Compile Include="ActionTypes\IVcsRoots.cs" />
6970
<Compile Include="ActionTypes\Projects.cs" />
7071
<Compile Include="ActionTypes\ServerInformation.cs" />
72+
<Compile Include="ActionTypes\Statistics.cs" />
7173
<Compile Include="ActionTypes\TestOccurrences.cs" />
7274
<Compile Include="Connection\ITeamCityCaller.cs" />
7375
<Compile Include="DomainEntities\TestOccurrence.cs" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using NUnit.Framework;
2+
using System.Linq;
3+
4+
namespace TeamCitySharp.IntegrationTests
5+
{
6+
[TestFixture]
7+
public class when_interacting_to_get_build_statistics
8+
{
9+
private ITeamCityClient _client;
10+
11+
[SetUp]
12+
public void SetUp()
13+
{
14+
_client = new TeamCityClient("teamcity.codebetter.com");
15+
_client.Connect("teamcitysharpuser", "qwerty");
16+
}
17+
18+
[Test]
19+
public void it_returns_no_of_tests_from_last_successful_build()
20+
{
21+
var proj = _client.Projects.ById("AutoFixture");
22+
var build = _client.Builds.LastSuccessfulBuildByBuildConfigId(proj.BuildTypes.BuildType[0].Id);
23+
var stats = _client.Statistics.GetByBuildId(build.Id);
24+
25+
Assert.That(stats.Any(property => property.Name.Equals("PassedTestCount")));
26+
}
27+
}
28+
}

src/Tests/IntegrationTests/TeamCitySharp.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="SampleServerUsage.cs">
6161
<SubType>Code</SubType>
6262
</Compile>
63+
<Compile Include="SampleStatisticsUsage.cs" />
6364
<Compile Include="SampleUserUsage.cs">
6465
<SubType>Code</SubType>
6566
</Compile>

0 commit comments

Comments
 (0)