IssueRelationTests.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Copyright 2011 - 2022 Adrian Popescu
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. using System.Collections.Specialized;
  14. using Padi.RedmineApi.Tests.Infrastructure;
  15. using Redmine.Net.Api;
  16. using Redmine.Net.Api.Exceptions;
  17. using Redmine.Net.Api.Types;
  18. using Xunit;
  19. namespace Padi.RedmineApi.Tests.Tests.Sync
  20. {
  21. [Trait("Redmine-Net-Api", "IssueRelations")]
  22. #if !(NET20 || NET40)
  23. [Collection("RedmineCollection")]
  24. #endif
  25. public class IssueRelationTests
  26. {
  27. public IssueRelationTests(RedmineFixture fixture)
  28. {
  29. this.fixture = fixture;
  30. }
  31. private readonly RedmineFixture fixture;
  32. private const string ISSUE_ID = "96";
  33. private const int RELATED_ISSUE_ID = 94;
  34. private const int RELATION_DELAY = 2;
  35. private const IssueRelationType OPPOSED_RELATION_TYPE = IssueRelationType.Precedes;
  36. [Fact, Order(1)]
  37. public void Should_Add_Issue_Relation()
  38. {
  39. const IssueRelationType RELATION_TYPE = IssueRelationType.Follows;
  40. var relation = new IssueRelation
  41. {
  42. IssueToId = RELATED_ISSUE_ID,
  43. Type = RELATION_TYPE,
  44. Delay = RELATION_DELAY
  45. };
  46. var savedRelation = fixture.RedmineManager.CreateObject(relation, ISSUE_ID);
  47. Assert.NotNull(savedRelation);
  48. Assert.True(savedRelation.IssueId == RELATED_ISSUE_ID, "Related issue id is not valid.");
  49. Assert.True(savedRelation.IssueToId.ToString().Equals(ISSUE_ID), "Issue id is not valid.");
  50. Assert.True(savedRelation.Delay == RELATION_DELAY, "Delay is not valid.");
  51. Assert.True(savedRelation.Type == OPPOSED_RELATION_TYPE, "Relation type is not valid.");
  52. }
  53. [Fact, Order(4)]
  54. public void Should_Delete_Issue_Relation()
  55. {
  56. const string RELATION_ID_TO_DELETE = "23";
  57. var exception =
  58. (RedmineException)
  59. Record.Exception(
  60. () => fixture.RedmineManager.DeleteObject<IssueRelation>(RELATION_ID_TO_DELETE));
  61. Assert.Null(exception);
  62. Assert.Throws<NotFoundException>(
  63. () => fixture.RedmineManager.GetObject<IssueRelation>(RELATION_ID_TO_DELETE, null));
  64. }
  65. [Fact, Order(2)]
  66. public void Should_Get_IssueRelation_By_Id()
  67. {
  68. const string RELATION_ID_TO_GET = "27";
  69. var relation = fixture.RedmineManager.GetObject<IssueRelation>(RELATION_ID_TO_GET, null);
  70. Assert.NotNull(relation);
  71. Assert.True(relation.IssueId == RELATED_ISSUE_ID, "Related issue id is not valid.");
  72. Assert.True(relation.IssueToId.ToString().Equals(ISSUE_ID), "Issue id is not valid.");
  73. Assert.True(relation.Delay == RELATION_DELAY, "Delay is not valid.");
  74. Assert.True(relation.Type == OPPOSED_RELATION_TYPE, "Relation type is not valid.");
  75. }
  76. [Fact, Order(3)]
  77. public void Should_Get_IssueRelations_By_Issue_Id()
  78. {
  79. const int NUMBER_OF_RELATIONS = 1;
  80. var relations =
  81. fixture.RedmineManager.GetObjects<IssueRelation>(new NameValueCollection
  82. {
  83. {RedmineKeys.ISSUE_ID, ISSUE_ID}
  84. });
  85. Assert.NotNull(relations);
  86. Assert.True(relations.Count == NUMBER_OF_RELATIONS, "Number of issue relations ( "+relations.Count+" ) != " + NUMBER_OF_RELATIONS);
  87. }
  88. }
  89. }