VersionTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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;
  14. using System.Collections.Specialized;
  15. using Padi.RedmineApi.Tests.Infrastructure;
  16. using Redmine.Net.Api;
  17. using Redmine.Net.Api.Exceptions;
  18. using Redmine.Net.Api.Types;
  19. using Xunit;
  20. using Version = Redmine.Net.Api.Types.Version;
  21. namespace Padi.RedmineApi.Tests.Tests.Sync
  22. {
  23. [Trait("Redmine-Net-Api", "Versions")]
  24. #if !(NET20 || NET40)
  25. [Collection("RedmineCollection")]
  26. #endif
  27. public class VersionTests
  28. {
  29. public VersionTests(RedmineFixture fixture)
  30. {
  31. this.fixture = fixture;
  32. }
  33. private readonly RedmineFixture fixture;
  34. private const string PROJECT_ID = "redmine-net-api";
  35. [Fact]
  36. [Order(1)]
  37. public void Should_Create_Version()
  38. {
  39. const string NEW_VERSION_NAME = "VersionTesting";
  40. const VersionStatus NEW_VERSION_STATUS = VersionStatus.Locked;
  41. const VersionSharing NEW_VERSION_SHARING = VersionSharing.Hierarchy;
  42. DateTime newVersionDueDate = DateTime.Now.AddDays(7);
  43. const string NEW_VERSION_DESCRIPTION = "Version description";
  44. var version = new Version
  45. {
  46. Name = NEW_VERSION_NAME,
  47. Status = NEW_VERSION_STATUS,
  48. Sharing = NEW_VERSION_SHARING,
  49. DueDate = newVersionDueDate,
  50. Description = NEW_VERSION_DESCRIPTION
  51. };
  52. var savedVersion = fixture.RedmineManager.CreateObject(version, PROJECT_ID);
  53. Assert.NotNull(savedVersion);
  54. Assert.NotNull(savedVersion.Project);
  55. Assert.True(savedVersion.Name.Equals(NEW_VERSION_NAME), "Version name is invalid.");
  56. Assert.True(savedVersion.Status.Equals(NEW_VERSION_STATUS), "Version status is invalid.");
  57. Assert.True(savedVersion.Sharing.Equals(NEW_VERSION_SHARING), "Version sharing is invalid.");
  58. Assert.NotNull(savedVersion.DueDate);
  59. Assert.True(savedVersion.DueDate.Value.Date.Equals(newVersionDueDate.Date), "Version due date is invalid.");
  60. Assert.True(savedVersion.Description.Equals(NEW_VERSION_DESCRIPTION), "Version description is invalid.");
  61. }
  62. [Fact]
  63. [Order(99)]
  64. public void Should_Delete_Version()
  65. {
  66. const string DELETED_VERSION_ID = "22";
  67. var exception =
  68. (RedmineException)
  69. Record.Exception(() => fixture.RedmineManager.DeleteObject<Version>(DELETED_VERSION_ID));
  70. Assert.Null(exception);
  71. Assert.Throws<NotFoundException>(() => fixture.RedmineManager.GetObject<Version>(DELETED_VERSION_ID, null));
  72. }
  73. [Fact]
  74. [Order(3)]
  75. public void Should_Get_Version_By_Id()
  76. {
  77. const string VERSION_ID = "6";
  78. var version = fixture.RedmineManager.GetObject<Version>(VERSION_ID, null);
  79. Assert.NotNull(version);
  80. }
  81. [Fact]
  82. [Order(2)]
  83. public void Should_Get_Versions_By_Project_Id()
  84. {
  85. const int NUMBER_OF_VERSIONS = 5;
  86. var versions =
  87. fixture.RedmineManager.GetObjects<Version>(new NameValueCollection
  88. {
  89. {RedmineKeys.PROJECT_ID, PROJECT_ID}
  90. });
  91. Assert.NotNull(versions);
  92. Assert.True(versions.Count == NUMBER_OF_VERSIONS, "Versions count ( "+versions.Count+" ) != " + NUMBER_OF_VERSIONS);
  93. }
  94. [Fact]
  95. [Order(4)]
  96. public void Should_Update_Version()
  97. {
  98. const string UPDATED_VERSION_ID = "15";
  99. const string UPDATED_VERSION_NAME = "Updated version";
  100. const VersionStatus UPDATED_VERSION_STATUS = VersionStatus.Closed;
  101. const VersionSharing UPDATED_VERSION_SHARING = VersionSharing.System;
  102. const string UPDATED_VERSION_DESCRIPTION = "Updated description";
  103. DateTime updatedVersionDueDate = DateTime.Now.AddMonths(1);
  104. var version = fixture.RedmineManager.GetObject<Version>(UPDATED_VERSION_ID, null);
  105. version.Name = UPDATED_VERSION_NAME;
  106. version.Status = UPDATED_VERSION_STATUS;
  107. version.Sharing = UPDATED_VERSION_SHARING;
  108. version.DueDate = updatedVersionDueDate;
  109. version.Description = UPDATED_VERSION_DESCRIPTION;
  110. fixture.RedmineManager.UpdateObject(UPDATED_VERSION_ID, version);
  111. var updatedVersion = fixture.RedmineManager.GetObject<Version>(UPDATED_VERSION_ID, null);
  112. Assert.NotNull(version);
  113. Assert.True(updatedVersion.Name.Equals(version.Name), "Version name not updated.");
  114. Assert.True(updatedVersion.Status.Equals(version.Status), "Status not updated");
  115. Assert.True(updatedVersion.Sharing.Equals(version.Sharing), "Sharing not updated");
  116. Assert.True(updatedVersion.DueDate != null && DateTime.Compare(updatedVersion.DueDate.Value.Date, version.DueDate.Value.Date) == 0,
  117. "DueDate not updated");
  118. Assert.True(updatedVersion.Description.Equals(version.Description), "Description not updated");
  119. }
  120. }
  121. }