IssueCategoryTests.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System.Collections.Specialized;
  2. using Padi.RedmineApi.Tests.Infrastructure;
  3. using Redmine.Net.Api;
  4. using Redmine.Net.Api.Exceptions;
  5. using Redmine.Net.Api.Types;
  6. using Xunit;
  7. namespace Padi.RedmineApi.Tests.Tests.Sync
  8. {
  9. [Trait("Redmine-Net-Api", "IssueCategories")]
  10. #if !(NET20 || NET40)
  11. [Collection("RedmineCollection")]
  12. #endif
  13. public class IssueCategoryTests
  14. {
  15. private readonly RedmineFixture fixture;
  16. private const string PROJECT_ID = "redmine-net-testq";
  17. private const string NEW_ISSUE_CATEGORY_NAME = "Test category";
  18. private const int NEW_ISSUE_CATEGORY_ASIGNEE_ID = 1;
  19. private static string createdIssueCategoryId;
  20. public IssueCategoryTests(RedmineFixture fixture)
  21. {
  22. this.fixture = fixture;
  23. }
  24. [Fact, Order(1)]
  25. public void Should_Create_IssueCategory()
  26. {
  27. var issueCategory = new IssueCategory
  28. {
  29. Name = NEW_ISSUE_CATEGORY_NAME,
  30. AssignTo = IdentifiableName.Create<IdentifiableName>(NEW_ISSUE_CATEGORY_ASIGNEE_ID)
  31. };
  32. var savedIssueCategory = fixture.RedmineManager.CreateObject(issueCategory, PROJECT_ID);
  33. createdIssueCategoryId = savedIssueCategory.Id.ToString();
  34. Assert.NotNull(savedIssueCategory);
  35. Assert.True(savedIssueCategory.Name.Equals(NEW_ISSUE_CATEGORY_NAME), "Saved issue category name is invalid.");
  36. }
  37. [Fact, Order(99)]
  38. public void Should_Delete_IssueCategory()
  39. {
  40. var exception =
  41. (RedmineException)
  42. Record.Exception(
  43. () => fixture.RedmineManager.DeleteObject<IssueCategory>(createdIssueCategoryId));
  44. Assert.Null(exception);
  45. Assert.Throws<NotFoundException>(
  46. () => fixture.RedmineManager.GetObject<IssueCategory>(createdIssueCategoryId, null));
  47. }
  48. [Fact, Order(2)]
  49. public void Should_Get_All_IssueCategories_By_ProjectId()
  50. {
  51. const int NUMBER_OF_ISSUE_CATEGORIES = 3;
  52. var issueCategories =
  53. fixture.RedmineManager.GetObjects<IssueCategory>(new NameValueCollection
  54. {
  55. {RedmineKeys.PROJECT_ID, PROJECT_ID}
  56. });
  57. Assert.NotNull(issueCategories);
  58. Assert.True(issueCategories.Count == NUMBER_OF_ISSUE_CATEGORIES,
  59. "Number of issue categories ( "+issueCategories.Count+" ) != " + NUMBER_OF_ISSUE_CATEGORIES);
  60. }
  61. [Fact, Order(3)]
  62. public void Should_Get_IssueCategory_By_Id()
  63. {
  64. const string ISSUE_CATEGORY_PROJECT_NAME_TO_GET = "Redmine tests";
  65. const string ISSUE_CATEGORY_ASIGNEE_NAME_TO_GET = "Redmine";
  66. var issueCategory = fixture.RedmineManager.GetObject<IssueCategory>(createdIssueCategoryId, null);
  67. Assert.NotNull(issueCategory);
  68. Assert.True(issueCategory.Name.Equals(NEW_ISSUE_CATEGORY_NAME), "Issue category name is invalid.");
  69. Assert.NotNull(issueCategory.AssignTo);
  70. Assert.True(issueCategory.AssignTo.Name.Contains(ISSUE_CATEGORY_ASIGNEE_NAME_TO_GET),
  71. "Asignee name is invalid.");
  72. Assert.NotNull(issueCategory.Project);
  73. Assert.True(issueCategory.Project.Name.Equals(ISSUE_CATEGORY_PROJECT_NAME_TO_GET),
  74. "Project name is invalid.");
  75. }
  76. [Fact, Order(4)]
  77. public void Should_Update_IssueCategory()
  78. {
  79. const string ISSUE_CATEGORY_NAME_TO_UPDATE = "Category updated";
  80. const int ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE = 2;
  81. var issueCategory = fixture.RedmineManager.GetObject<IssueCategory>(createdIssueCategoryId, null);
  82. issueCategory.Name = ISSUE_CATEGORY_NAME_TO_UPDATE;
  83. issueCategory.AssignTo = IdentifiableName.Create<IdentifiableName>(ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE);
  84. fixture.RedmineManager.UpdateObject(createdIssueCategoryId, issueCategory);
  85. var updatedIssueCategory = fixture.RedmineManager.GetObject<IssueCategory>(createdIssueCategoryId, null);
  86. Assert.NotNull(updatedIssueCategory);
  87. Assert.True(updatedIssueCategory.Name.Equals(ISSUE_CATEGORY_NAME_TO_UPDATE),
  88. "Issue category name was not updated.");
  89. Assert.NotNull(updatedIssueCategory.AssignTo);
  90. Assert.True(updatedIssueCategory.AssignTo.Id == ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE,
  91. "Issue category asignee was not updated.");
  92. }
  93. [Fact, Order(5)]
  94. public void Should_Reassign_Issue_After_Issue_Category_Is_Deleted()
  95. {
  96. const string ISSUE_CATEGORY_ID_TO_DELETE = "8";
  97. const string ISSUE_CATEGORY_ID_TO_REASSIGN = "10";
  98. const string ISSUE_ID_REASSIGNED = "9";
  99. var exception =
  100. (RedmineException)
  101. Record.Exception(
  102. () => fixture.RedmineManager.DeleteObject<IssueCategory>(ISSUE_CATEGORY_ID_TO_DELETE, new NameValueCollection{{RedmineKeys.REASSIGN_TO_ID, ISSUE_CATEGORY_ID_TO_REASSIGN}}));
  103. Assert.Null(exception);
  104. Assert.Throws<NotFoundException>(
  105. () => fixture.RedmineManager.GetObject<IssueCategory>(ISSUE_CATEGORY_ID_TO_DELETE, null));
  106. var issue = fixture.RedmineManager.GetObject<Issue>(ISSUE_ID_REASSIGNED, null);
  107. Assert.NotNull(issue.Category);
  108. Assert.True(ISSUE_CATEGORY_ID_TO_REASSIGN.Equals(issue.Category.Id.ToString()), string.Format("Issue was not reassigned. Issue category id {0} != {1}", issue.Category.Id, ISSUE_CATEGORY_ID_TO_REASSIGN));
  109. }
  110. }
  111. }