Permalink
Browse files

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

…ted.
  • Loading branch information...
1 parent 9014e6a commit b975a8bed2ec017398877704e58f679f1efb7a38 @Saulis Saulis committed Jun 26, 2012
View
@@ -34,7 +34,7 @@ issue.Summary = "foobar";
```
-## Supported API Features
+## Supported API Features (v0.3.3)
* Issues
* Create New Issue
@@ -45,14 +45,15 @@ issue.Summary = "foobar";
* Attach File to an Issue
* Delete an Issue
+
## Not (yet) Supported API Features
* Issues
* Get Issue History
* 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
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -20,15 +20,23 @@ 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);
}
[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);
}
@@ -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();
}
}
}
@@ -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>());
}
@@ -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>());
+ }
+ }
+}
@@ -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));
+ }
+ }
+}
@@ -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" />
@@ -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>());
+ }
}
}
@@ -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; }
@@ -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();
- }
- }
-}
@@ -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);
@@ -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);
+ }
+}
@@ -7,5 +7,6 @@ public interface IYouTrackClient
IConnection GetConnection();
ISession GetSession();
IIssueRepository GetIssueRepository();
+ IProjectRepository GetProjectRepository();
}
}
View
@@ -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;
}
}
}
Oops, something went wrong.

0 comments on commit b975a8b

Please sign in to comment.