Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ProjectRepository and Proxy added. Get Issues in a project reimplemen…

…ted.
  • Loading branch information...
commit b975a8bed2ec017398877704e58f679f1efb7a38 1 parent 9014e6a
@Saulis Saulis authored
Showing with 253 additions and 50 deletions.
  1. +3 −2 README.markdown
  2. +5 −0 YouTrack.Rest.Features/General/Issues/GetIssuesInAProject.feature
  3. +24 −5 YouTrack.Rest.Features/General/Issues/GetIssuesInAProject.feature.cs
  4. +10 −2 YouTrack.Rest.Features/General/Issues/GetIssuesInAProjectSteps.cs
  5. +16 −2 YouTrack.Rest.Features/Steps/StepHelper.cs
  6. +2 −2 YouTrack.Rest.Tests/IssueTests.cs
  7. +55 −0 YouTrack.Rest.Tests/ProjectProxyTests.cs
  8. +33 −0 YouTrack.Rest.Tests/Repositories/ProjectRepositoryTests.cs
  9. +2 −0  YouTrack.Rest.Tests/YouTrack.Rest.Tests.csproj
  10. +7 −1 YouTrack.Rest.Tests/YouTrackClientTests.cs
  11. +1 −0  YouTrack.Rest/Deserialization/Issue.cs
  12. +0 −15 YouTrack.Rest/Deserialization/IssueCollection.cs
  13. +1 −1  YouTrack.Rest/IIssueProxy.cs
  14. +11 −0 YouTrack.Rest/IProjectProxy.cs
  15. +1 −0  YouTrack.Rest/IYouTrackClient.cs
  16. +4 −4 YouTrack.Rest/Issue.cs
  17. +40 −0 YouTrack.Rest/ProjectProxy.cs
  18. +0 −3  YouTrack.Rest/Repositories/IIssueRepository.cs
  19. +7 −0 YouTrack.Rest/Repositories/IProjectRepository.cs
  20. +0 −10 YouTrack.Rest/Repositories/IssueRepository.cs
  21. +17 −0 YouTrack.Rest/Repositories/ProjectRepository.cs
  22. +6 −1 YouTrack.Rest/Requests/GetIssuesInAProjectRequest.cs
  23. +4 −1 YouTrack.Rest/YouTrack.Rest.csproj
  24. +4 −1 YouTrack.Rest/YouTrackClient.cs
View
5 README.markdown
@@ -34,7 +34,7 @@ issue.Summary = "foobar";
```
-## Supported API Features
+## Supported API Features (v0.3.3)
* Issues
* Create New Issue
@@ -45,6 +45,7 @@ issue.Summary = "foobar";
* Attach File to an Issue
* Delete an Issue
+
## Not (yet) Supported API Features
* Issues
@@ -52,7 +53,7 @@ issue.Summary = "foobar";
* Get Historical Changes of an Issue
* Get Links of an Issue
* Apply Command to an Issue
- * Get Issues in a Project
+ * Get Issues in a Project (next version)
* Get a Number of Issues
* Remove a Comment for an Issue
View
5 YouTrack.Rest.Features/General/Issues/GetIssuesInAProject.feature
@@ -3,6 +3,11 @@
Background:
Given I am authenticated
+Scenario: Get all Issues in a project
+ Given I have created an issue
+ When I search all the issues of the project
+ Then I receive the issue
+
Scenario: Get Issues in a project with search
Given I have created an issue
When I search for the issue with summary filter
View
29 YouTrack.Rest.Features/General/Issues/GetIssuesInAProject.feature.cs
@@ -3,7 +3,7 @@
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.8.1.0
// SpecFlow Generator Version:1.8.0.0
-// Runtime Version:4.0.30319.17379
+// Runtime Version:4.0.30319.269
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -73,10 +73,10 @@ public virtual void FeatureBackground()
}
[NUnit.Framework.TestAttribute()]
- [NUnit.Framework.DescriptionAttribute("Get Issues in a project with search")]
- public virtual void GetIssuesInAProjectWithSearch()
+ [NUnit.Framework.DescriptionAttribute("Get all Issues in a project")]
+ public virtual void GetAllIssuesInAProject()
{
- TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get Issues in a project with search", ((string[])(null)));
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get all Issues in a project", ((string[])(null)));
#line 6
this.ScenarioSetup(scenarioInfo);
#line 3
@@ -84,12 +84,31 @@ public virtual void GetIssuesInAProjectWithSearch()
#line 7
testRunner.Given("I have created an issue");
#line 8
- testRunner.When("I search for the issue with summary filter");
+ testRunner.When("I search all the issues of the project");
#line 9
testRunner.Then("I receive the issue");
#line hidden
this.ScenarioCleanup();
}
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Get Issues in a project with search")]
+ public virtual void GetIssuesInAProjectWithSearch()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get Issues in a project with search", ((string[])(null)));
+#line 11
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 12
+ testRunner.Given("I have created an issue");
+#line 13
+ testRunner.When("I search for the issue with summary filter");
+#line 14
+ testRunner.Then("I receive the issue");
+#line hidden
+ this.ScenarioCleanup();
+ }
}
}
#pragma warning restore
View
12 YouTrack.Rest.Features/General/Issues/GetIssuesInAProjectSteps.cs
@@ -20,7 +20,15 @@ public void GivenIHaveCreatedAnIssue()
[When(@"I search for the issue with summary filter")]
public void WhenISearchForTheIssueWithSummaryFilter()
{
- ICollection<IIssue> issues = StepHelper.GetIssues("SB", "Testing search");
+ IEnumerable<IIssue> issues = StepHelper.GetIssues("SB", "Testing search");
+
+ ScenarioContext.Current.Set(issues);
+ }
+
+ [When(@"I search all the issues of the project")]
+ public void WhenISearchAllTheIssuesOfTheProject()
+ {
+ IEnumerable<IIssue> issues = StepHelper.GetIssues("SB");
ScenarioContext.Current.Set(issues);
}
@@ -28,7 +36,7 @@ public void WhenISearchForTheIssueWithSummaryFilter()
[Then(@"I receive the issue")]
public void ThenIReceiveTheIssue()
{
- ICollection<IIssue> issues = ScenarioContext.Current.Get<ICollection<IIssue>>();
+ IEnumerable<IIssue> issues = ScenarioContext.Current.Get<IEnumerable<IIssue>>();
Assert.That(issues, Is.Not.Empty);
}
View
18 YouTrack.Rest.Features/Steps/StepHelper.cs
@@ -105,9 +105,23 @@ public IIssueProxy GetIssueProxy(string issueId)
return GetIssueRepository().GetIssueProxy(issueId);
}
- public ICollection<IIssue> GetIssues(string project, string filter)
+ public IEnumerable<IIssue> GetIssues(string project, string filter)
{
- return GetIssueRepository().GetIssuesOfAnProject(project, filter);
+ IProjectProxy projectProxy = GetProjectRepository().GetProjectProxy(project);
+
+ return projectProxy.GetIssues(filter);
+ }
+
+ public IEnumerable<IIssue> GetIssues(string project)
+ {
+ IProjectProxy projectProxy = GetProjectRepository().GetProjectProxy(project);
+
+ return projectProxy.GetIssues();
+ }
+
+ private IProjectRepository GetProjectRepository()
+ {
+ return youTrackClient.GetProjectRepository();
}
}
}
View
4 YouTrack.Rest.Tests/IssueTests.cs
@@ -41,7 +41,7 @@ public void CommentsAreFetchedAgainAfterAddingComment()
{
connection.Get<CommentsWrapper>(Arg.Any<GetCommentsOfAnIssueRequest>()).Returns(commentsWrapper);
- ICollection<IComment> comments = Sut.Comments;
+ IEnumerable<IComment> comments = Sut.Comments;
Sut.AddComment("foobar");
comments = Sut.Comments;
@@ -79,7 +79,7 @@ public void ConnectionIsCalledWithGetComments()
{
connection.Get<CommentsWrapper>(Arg.Any<GetCommentsOfAnIssueRequest>()).Returns(commentsWrapper);
- ICollection<IComment> comments = Sut.Comments;
+ IEnumerable<IComment> comments = Sut.Comments;
connection.Received().Get<CommentsWrapper>(Arg.Any<GetCommentsOfAnIssueRequest>());
}
View
55 YouTrack.Rest.Tests/ProjectProxyTests.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NSubstitute;
+using NUnit.Framework;
+using YouTrack.Rest.Deserialization;
+using YouTrack.Rest.Requests;
+using YouTrack.Rest.Tests.Repositories;
+
+namespace YouTrack.Rest.Tests
+{
+ class ProjectProxyTests : TestFor<ProjectProxy>
+ {
+ private IConnection connection;
+ private List<Deserialization.Issue> issues;
+ private const string ProjectId = "FOOBAR";
+
+ protected override ProjectProxy CreateSut()
+ {
+ connection = Mock<IConnection>();
+ return new ProjectProxy(ProjectId, connection);
+ }
+
+ protected override void SetupDependencies()
+ {
+ issues = new List<Deserialization.Issue>();
+ issues.Add(new IssueMock(Mock<IIssue>()));
+
+ connection.Get<List<Deserialization.Issue>>(Arg.Any<GetIssuesInAProjectRequest>()).Returns(issues);
+ }
+
+ [Test]
+ public void IdIsAssigned()
+ {
+ Assert.That(Sut.Id, Is.EqualTo(ProjectId));
+ }
+
+ [Test]
+ public void ConnectionIsCalledOnGetIssues()
+ {
+ Sut.GetIssues();
+
+ connection.Received().Get<List<Deserialization.Issue>>(Arg.Any<GetIssuesInAProjectRequest>());
+ }
+
+ [Test]
+ public void ConnectionIsCalledOnGetIssuesWithFilter()
+ {
+ Sut.GetIssues("filter");
+
+ connection.Received().Get<List<Deserialization.Issue>>(Arg.Any<GetIssuesInAProjectRequest>());
+ }
+ }
+}
View
33 YouTrack.Rest.Tests/Repositories/ProjectRepositoryTests.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using YouTrack.Rest.Repositories;
+
+namespace YouTrack.Rest.Tests.Repositories
+{
+ class ProjectRepositoryTests : TestFor<ProjectRepository>
+ {
+ private const string ProjectId = "projectId";
+
+ protected override ProjectRepository CreateSut()
+ {
+ return new ProjectRepository(Mock<IConnection>());
+ }
+
+ [Test]
+ public void ProjectProxyIsReturned()
+ {
+ Assert.That(Sut.GetProjectProxy(ProjectId), Is.TypeOf<ProjectProxy>());
+ }
+
+ [Test]
+ public void ProjectIdIsAssignedToProxy()
+ {
+ IProjectProxy projectProxy = Sut.GetProjectProxy(ProjectId);
+
+ Assert.That(projectProxy.Id, Is.EqualTo(ProjectId));
+ }
+ }
+}
View
2  YouTrack.Rest.Tests/YouTrack.Rest.Tests.csproj
@@ -52,7 +52,9 @@
<ItemGroup>
<Compile Include="ConnectionTests.cs" />
<Compile Include="IssueTests.cs" />
+ <Compile Include="ProjectProxyTests.cs" />
<Compile Include="Repositories\IssueMock.cs" />
+ <Compile Include="Repositories\ProjectRepositoryTests.cs" />
<Compile Include="Requests\AddCommentToIssueRequestTests.cs" />
<Compile Include="Requests\ApplyCommandToAnIssueRequestTests.cs" />
<Compile Include="Requests\AttachFileToAnIssueRequestTests.cs" />
View
8 YouTrack.Rest.Tests/YouTrackClientTests.cs
@@ -26,9 +26,15 @@ public void ConnectionIsReturned()
}
[Test]
- public void TestMethod()
+ public void SessionIsReturned()
{
Assert.That(Sut.GetSession(), Is.TypeOf<Session>());
}
+
+ [Test]
+ public void ProjectRepositoryIsReturned()
+ {
+ Assert.That(Sut.GetProjectRepository(), Is.TypeOf<ProjectRepository>());
+ }
}
}
View
1  YouTrack.Rest/Deserialization/Issue.cs
@@ -5,6 +5,7 @@
namespace YouTrack.Rest.Deserialization
{
+ //Has to have name Issue for RestSharp deserialization to work properly.
class Issue
{
public string Id { get; set; }
View
15 YouTrack.Rest/Deserialization/IssueCollection.cs
@@ -1,15 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-
-namespace YouTrack.Rest.Deserialization
-{
- class IssueCollection
- {
- public List<Issue> Issues { get; set; }
-
- public ICollection<IIssue> GetIssues(IConnection connection)
- {
- return Issues.Select(i => i.GetIssue(connection)).ToList();
- }
- }
-}
View
2  YouTrack.Rest/IIssueProxy.cs
@@ -8,7 +8,7 @@ public interface IIssueProxy
void AttachFile(string filePath);
IEnumerable<IAttachment> GetAttachments();
void AddComment(string comment);
- ICollection<IComment> Comments { get; }
+ IEnumerable<IComment> Comments { get; }
void SetSubsystem(string subsystem);
void SetType(string type);
void AttachFile(string fileName, byte[] bytes);
View
11 YouTrack.Rest/IProjectProxy.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace YouTrack.Rest
+{
+ public interface IProjectProxy
+ {
+ string Id { get; }
+ IEnumerable<IIssue> GetIssues();
+ IEnumerable<IIssue> GetIssues(string filter);
+ }
+}
View
1  YouTrack.Rest/IYouTrackClient.cs
@@ -7,5 +7,6 @@ public interface IYouTrackClient
IConnection GetConnection();
ISession GetSession();
IIssueRepository GetIssueRepository();
+ IProjectRepository GetProjectRepository();
}
}
View
8 YouTrack.Rest/Issue.cs
@@ -9,7 +9,7 @@ namespace YouTrack.Rest
class Issue : IIssue
{
private readonly IConnection connection;
- private ICollection<IComment> comments;
+ private IEnumerable<IComment> comments;
public string Id { get; private set; }
public string Summary { get; set; }
@@ -33,7 +33,7 @@ public Issue(string issueId, IConnection connection)
this.connection = connection;
}
- public ICollection<IComment> Comments
+ public IEnumerable<IComment> Comments
{
get { return comments ?? (comments = GetComments()); }
internal set { comments = value; }
@@ -89,13 +89,13 @@ public void AddComment(string comment)
comments = null;
}
- private ICollection<IComment> GetComments()
+ private IEnumerable<IComment> GetComments()
{
GetCommentsOfAnIssueRequest getCommentsOfAnIssueRequest = new GetCommentsOfAnIssueRequest(Id);
CommentsWrapper commentsWrapper = connection.Get<CommentsWrapper>(getCommentsOfAnIssueRequest);
- return commentsWrapper.Comments.ToList<IComment>();
+ return commentsWrapper.Comments;
}
}
}
View
40 YouTrack.Rest/ProjectProxy.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+using System.Linq;
+using YouTrack.Rest.Requests;
+
+namespace YouTrack.Rest
+{
+ class ProjectProxy : IProjectProxy
+ {
+ private readonly IConnection connection;
+
+ public ProjectProxy(string projectId, IConnection connection)
+ {
+ Id = projectId;
+ this.connection = connection;
+ }
+
+ public string Id { get; private set; }
+
+ public IEnumerable<IIssue> GetIssues()
+ {
+ GetIssuesInAProjectRequest request = new GetIssuesInAProjectRequest(Id);
+
+ return GetIssues(request);
+ }
+
+ public IEnumerable<IIssue> GetIssues(string filter)
+ {
+ GetIssuesInAProjectRequest request = new GetIssuesInAProjectRequest(Id, filter);
+
+ return GetIssues(request);
+ }
+
+ private IEnumerable<IIssue> GetIssues(GetIssuesInAProjectRequest request)
+ {
+ List<Deserialization.Issue> issues = connection.Get<List<Deserialization.Issue>>(request);
+
+ return issues.Select(i => i.GetIssue(connection));
+ }
+ }
+}
View
3  YouTrack.Rest/Repositories/IIssueRepository.cs
@@ -1,5 +1,3 @@
-using System.Collections.Generic;
-
namespace YouTrack.Rest.Repositories
{
public interface IIssueRepository
@@ -10,6 +8,5 @@ public interface IIssueRepository
void DeleteIssue(string issueId);
bool IssueExists(string issueId);
IIssueProxy GetIssueProxy(string issueId);
- ICollection<IIssue> GetIssuesOfAnProject(string project, string filter);
}
}
View
7 YouTrack.Rest/Repositories/IProjectRepository.cs
@@ -0,0 +1,7 @@
+namespace YouTrack.Rest.Repositories
+{
+ public interface IProjectRepository
+ {
+ IProjectProxy GetProjectProxy(string projectid);
+ }
+}
View
10 YouTrack.Rest/Repositories/IssueRepository.cs
@@ -1,4 +1,3 @@
-using System.Collections.Generic;
using System.Linq;
using YouTrack.Rest.Deserialization;
using YouTrack.Rest.Exceptions;
@@ -41,15 +40,6 @@ public IIssue GetIssue(string issueId)
return issue.GetIssue(connection);
}
- public ICollection<IIssue> GetIssuesOfAnProject(string project, string filter)
- {
- GetIssuesInAProjectRequest request = new GetIssuesInAProjectRequest(project, filter);
-
- List<Deserialization.Issue> issues = connection.Get<List<Deserialization.Issue>>(request);
-
- return issues.Select(i => i.GetIssue(connection)).ToList();
- }
-
public void DeleteIssue(string issueId)
{
DeleteIssueRequest deleteIssueRequest = new DeleteIssueRequest(issueId);
View
17 YouTrack.Rest/Repositories/ProjectRepository.cs
@@ -0,0 +1,17 @@
+namespace YouTrack.Rest.Repositories
+{
+ class ProjectRepository : IProjectRepository
+ {
+ private readonly IConnection connection;
+
+ public ProjectRepository(IConnection connection)
+ {
+ this.connection = connection;
+ }
+
+ public IProjectProxy GetProjectProxy(string projectid)
+ {
+ return new ProjectProxy(projectid, connection);
+ }
+ }
+}
View
7 YouTrack.Rest/Requests/GetIssuesInAProjectRequest.cs
@@ -4,7 +4,12 @@ namespace YouTrack.Rest.Requests
{
internal class GetIssuesInAProjectRequest : YouTrackRequest, IYouTrackGetRequest
{
- public GetIssuesInAProjectRequest(string project, string filter) : base(String.Format("/rest/issue/byproject/{0}", project))
+ public GetIssuesInAProjectRequest(string project)
+ : base(String.Format("/rest/issue/byproject/{0}", project))
+ {
+ }
+
+ public GetIssuesInAProjectRequest(string project, string filter) : this(project)
{
ResourceBuilder.AddParameter("filter", filter);
}
View
5 YouTrack.Rest/YouTrack.Rest.csproj
@@ -51,7 +51,6 @@
<Compile Include="Deserialization\Field.cs" />
<Compile Include="Deserialization\FileUrl.cs" />
<Compile Include="Deserialization\FileUrlsWrapper.cs" />
- <Compile Include="Deserialization\IssueCollection.cs" />
<Compile Include="Deserialization\Issue.cs" />
<Compile Include="Deserialization\Value_.cs" />
<Compile Include="Exceptions\InvalidAcceptHeaderCountException.cs" />
@@ -65,11 +64,15 @@
<Compile Include="IComment.cs" />
<Compile Include="IConnection.cs" />
<Compile Include="IIssueProxy.cs" />
+ <Compile Include="IProjectProxy.cs" />
<Compile Include="ISession.cs" />
<Compile Include="IIssue.cs" />
<Compile Include="Issue.cs" />
+ <Compile Include="ProjectProxy.cs" />
<Compile Include="Repositories\IIssueRepository.cs" />
+ <Compile Include="Repositories\IProjectRepository.cs" />
<Compile Include="Repositories\IssueRepository.cs" />
+ <Compile Include="Repositories\ProjectRepository.cs" />
<Compile Include="Requests\AddCommentToIssueRequest.cs" />
<Compile Include="Requests\ApplyCommandToAnIssueRequest.cs" />
<Compile Include="Requests\AttachFileToAnIssueRequest.cs" />
View
5 YouTrack.Rest/YouTrackClient.cs
@@ -31,6 +31,9 @@ public IIssueRepository GetIssueRepository()
return new IssueRepository(connection);
}
-
+ public IProjectRepository GetProjectRepository()
+ {
+ return new ProjectRepository(connection);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.