-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
301 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using Harvest.Net.Models; | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Harvest.Net.Tests | ||
{ | ||
public class TaskAssignmentFacts : FactBase, IDisposable | ||
{ | ||
TaskAssignment _todelete = null; | ||
Task _todeletetask = null; | ||
|
||
[Fact] | ||
public void ListTaskAssignments_Returns() | ||
{ | ||
var list = Api.ListTaskAssignments(GetTestId(TestId.ProjectId)); | ||
|
||
Assert.True(list != null, "Result list is null."); | ||
Assert.NotEqual(0, list.First().Id); | ||
} | ||
|
||
[Fact] | ||
public void TaskAssignment_ReturnsTaskAssignment() | ||
{ | ||
var taskAssignment = Api.TaskAssignment(GetTestId(TestId.ProjectId), GetTestId(TestId.TaskAssignmentId)); | ||
|
||
Assert.NotNull(taskAssignment); | ||
Assert.Equal(GetTestId(TestId.TaskId), taskAssignment.TaskId); | ||
Assert.Equal(GetTestId(TestId.ProjectId), taskAssignment.ProjectId); | ||
} | ||
|
||
[Fact] | ||
public void CreateTaskAssignment_ReturnsANewTaskAssignment() | ||
{ | ||
_todelete = Api.CreateTaskAssignment(GetTestId(TestId.ProjectId), GetTestId(TestId.TaskId2)); | ||
|
||
Assert.NotNull(_todelete); | ||
Assert.Equal(GetTestId(TestId.ProjectId), _todelete.ProjectId); | ||
Assert.Equal(GetTestId(TestId.TaskId2), _todelete.TaskId); | ||
} | ||
|
||
[Fact] | ||
public void CreateNewTaskAndAssign_ReturnsANewTaskAssignment() | ||
{ | ||
_todelete = Api.CreateNewTaskAndAssign(GetTestId(TestId.ProjectId), "Create New Task And Assign Test"); | ||
_todeletetask = Api.Task(_todelete.TaskId); | ||
|
||
Assert.NotNull(_todelete); | ||
Assert.Equal(GetTestId(TestId.ProjectId), _todelete.ProjectId); | ||
Assert.Equal("Create New Task And Assign Test", _todeletetask.Name); | ||
} | ||
|
||
[Fact] | ||
public void DeleteTaskAssignment_ReturnsTrue() | ||
{ | ||
var taskAssignment = Api.CreateTaskAssignment(GetTestId(TestId.ProjectId), GetTestId(TestId.TaskId2)); | ||
|
||
var result = Api.DeleteTaskAssignment(taskAssignment.ProjectId, taskAssignment.Id); | ||
|
||
Assert.Equal(true, result); | ||
} | ||
|
||
[Fact] | ||
public void UpdateTaskAssignment_UpdatesOnlyChangedValues() | ||
{ | ||
var projectId = GetTestId(TestId.ProjectId); | ||
|
||
_todelete = Api.CreateTaskAssignment(projectId, GetTestId(TestId.TaskId2)); | ||
var updated = Api.UpdateTaskAssignment(projectId, _todelete.Id, billable: true, hourlyRate: 1); | ||
|
||
// stuff changed | ||
Assert.NotEqual(_todelete.Billable, updated.Billable); | ||
Assert.Equal(false, _todelete.Billable); | ||
Assert.NotEqual(_todelete.HourlyRate, updated.HourlyRate); | ||
Assert.Equal(null, _todelete.HourlyRate); | ||
|
||
// stuff didn't change | ||
Assert.Equal(_todelete.Id, updated.Id); | ||
Assert.Equal(projectId, updated.ProjectId); | ||
Assert.Equal(_todelete.TaskId, updated.TaskId); | ||
Assert.Equal(null, updated.Budget); | ||
Assert.Equal(false, updated.Deactivated); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (_todelete != null) | ||
{ | ||
Api.DeleteTaskAssignment(_todelete.ProjectId, _todelete.Id); | ||
} | ||
|
||
if (_todeletetask != null) | ||
{ | ||
Api.DeleteTask(_todeletetask.Id); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using RestSharp.Serializers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Harvest.Net.Models | ||
{ | ||
[SerializeAs(Name = "task-assignment")] | ||
public class TaskAssignment : IModel | ||
{ | ||
public long Id { get; set; } | ||
|
||
public DateTime CreatedAt { get; set; } | ||
|
||
public DateTime UpdatedAt { get; set; } | ||
|
||
public long TaskId { get; set; } | ||
|
||
public long ProjectId { get; set; } | ||
|
||
public bool Billable { get; set; } | ||
|
||
public bool Deactivated { get; set; } | ||
|
||
public decimal? HourlyRate { get; set; } | ||
|
||
public decimal? Budget { get; set; } | ||
|
||
public decimal? Estimate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using RestSharp.Serializers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Harvest.Net.Models | ||
{ | ||
[SerializeAs(Name = "task")] | ||
internal class TaskAssignmentCreateOptions | ||
{ | ||
public long Id { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using RestSharp.Serializers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Harvest.Net.Models | ||
{ | ||
[SerializeAs(Name = "task-assignment")] | ||
public class TaskAssignmentOptions | ||
{ | ||
public bool? Billable { get; set; } | ||
|
||
public bool? Deactivated { get; set; } | ||
|
||
public decimal? HourlyRate { get; set; } | ||
|
||
public decimal? Budget { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using Harvest.Net.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Harvest.Net | ||
{ | ||
public partial class HarvestRestClient | ||
{ | ||
// https://github.com/harvesthq/api/blob/master/Sections/Task%20Assignment.md | ||
|
||
/// <summary> | ||
/// List all task assignments on a project. Makes a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The Id of the project for which to retrieve assignemnts</param> | ||
/// <param name="updatedSince">An optional filter on the updated-at property</param> | ||
public IList<TaskAssignment> ListTaskAssignments(long projectId, DateTime? updatedSince = null) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments"); | ||
|
||
if (updatedSince != null) | ||
request.AddParameter("updated_since", updatedSince.Value.ToString("yyyy-MM-dd HH:mm")); | ||
|
||
return Execute<List<TaskAssignment>>(request); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve a task assignment on a project. Makes a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The Id of the project for which to retrieve an assignemnt</param> | ||
/// <param name="taskAssignmentId">The Id of the assignment to retrieve</param> | ||
public TaskAssignment TaskAssignment(long projectId, long taskAssignmentId) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments/" + taskAssignmentId); | ||
|
||
return Execute<TaskAssignment>(request); | ||
} | ||
|
||
/// <summary> | ||
/// Assign a task to a project. Makes both a POST and a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The Id of the project to which to add the task</param> | ||
/// <param name="taskId">The Id of the task to add</param> | ||
public TaskAssignment CreateTaskAssignment(long projectId, long taskId) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments", RestSharp.Method.POST); | ||
|
||
request.AddBody(new TaskAssignmentCreateOptions() | ||
{ | ||
Id = taskId | ||
}); | ||
|
||
return Execute<TaskAssignment>(request); | ||
} | ||
|
||
/// <summary> | ||
/// Create a new task and assign it to a project. Makes a POST request to the Projects/Task_Assignments/Add_With_Create_New_Task resource, and a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The ID of th project to which to add the new task</param> | ||
/// <param name="name">The name of the new task</param> | ||
public TaskAssignment CreateNewTaskAndAssign(long projectId, string name) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments/add_with_create_new_task", RestSharp.Method.POST); | ||
|
||
request.AddBody(new TaskOptions() | ||
{ | ||
Name = name | ||
}); | ||
|
||
return Execute<TaskAssignment>(request); | ||
} | ||
|
||
/// <summary> | ||
/// Remove a task from a project. Makes a DELETE request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The Id of the project from which to remove the task</param> | ||
/// <param name="taskAssignmentId">The Id of the task assignment to remove</param> | ||
public bool DeleteTaskAssignment(long projectId, long taskAssignmentId) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments/" + taskAssignmentId, RestSharp.Method.DELETE); | ||
|
||
var result = Execute(request); | ||
|
||
return result.StatusCode == System.Net.HttpStatusCode.OK; | ||
} | ||
|
||
/// <summary> | ||
/// Update a task assignment on a project. Makes a PUT and a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The ID of the project to update</param> | ||
/// <param name="taskAssignmentId">The ID of the task assignment to update</param> | ||
/// <param name="billable">Whether the task assignment is billable</param> | ||
/// <param name="deactivated">Whether the task assignment is inactive</param> | ||
/// <param name="hourlyRate">The hourly rate</param> | ||
/// <param name="budget">The budget</param> | ||
public TaskAssignment UpdateTaskAssignment(long projectId, long taskAssignmentId, bool? billable = null, bool? deactivated = null, decimal? hourlyRate = null, decimal? budget = null) | ||
{ | ||
var options = new TaskAssignmentOptions() | ||
{ | ||
Billable = billable, | ||
Deactivated = deactivated, | ||
HourlyRate = hourlyRate, | ||
Budget = budget, | ||
}; | ||
|
||
return UpdateTaskAssignment(projectId, taskAssignmentId, options); | ||
} | ||
|
||
/// <summary> | ||
/// Update a task assignment on a project. Makes a PUT and a GET request to the Projects/Task_Assignments resource. | ||
/// </summary> | ||
/// <param name="projectId">The ID of the project to update</param> | ||
/// <param name="taskAssignmentId">The ID of the task assignment to update</param> | ||
/// <param name="options">The options to be updated</param> | ||
public TaskAssignment UpdateTaskAssignment(long projectId, long taskAssignmentId, TaskAssignmentOptions options) | ||
{ | ||
var request = Request("projects/" + projectId + "/task_assignments/" + taskAssignmentId, RestSharp.Method.PUT); | ||
|
||
request.AddBody(options); | ||
|
||
return Execute<TaskAssignment>(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters