RedmineTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Padi.RedmineApi.Tests.Infrastructure;
  2. using Redmine.Net.Api;
  3. using Redmine.Net.Api.Exceptions;
  4. using Xunit;
  5. namespace Padi.RedmineApi.Tests.Tests
  6. {
  7. [Trait("Redmine-api", "Credentials")]
  8. #if !(NET20 || NET40)
  9. [Collection("RedmineCollection")]
  10. #endif
  11. [Order(1)]
  12. public sealed class RedmineTest
  13. {
  14. private static readonly RedmineCredentials Credentials;
  15. static RedmineTest()
  16. {
  17. Credentials = TestHelper.GetApplicationConfiguration();
  18. }
  19. [Fact]
  20. public void Should_Throw_Redmine_Exception_When_Host_Is_Null()
  21. {
  22. Assert.Throws<RedmineException>(() => new RedmineManager(null, Credentials.Username, Credentials.Password));
  23. }
  24. [Fact]
  25. public void Should_Throw_Redmine_Exception_When_Host_Is_Empty()
  26. {
  27. Assert.Throws<RedmineException>(() => new RedmineManager(string.Empty, Credentials.Username, Credentials.Password));
  28. }
  29. [Fact]
  30. public void Should_Throw_Redmine_Exception_When_Host_Is_Invalid()
  31. {
  32. Assert.Throws<RedmineException>(() => new RedmineManager("invalid<>", Credentials.Username, Credentials.Password));
  33. }
  34. [Fact]
  35. public void Should_Connect_With_Username_And_Password()
  36. {
  37. var a = new RedmineManager(Credentials.Uri, Credentials.Username, Credentials.Password);
  38. var currentUser = a.GetCurrentUser();
  39. Assert.NotNull(currentUser);
  40. Assert.True(currentUser.Login.Equals(Credentials.Username), "usernames not equals.");
  41. }
  42. [Fact]
  43. public void Should_Connect_With_Api_Key()
  44. {
  45. var a = new RedmineManager(Credentials.Uri, Credentials.ApiKey);
  46. var currentUser = a.GetCurrentUser();
  47. Assert.NotNull(currentUser);
  48. Assert.True(currentUser.ApiKey.Equals(Credentials.ApiKey),"api keys not equals.");
  49. }
  50. }
  51. }