PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Atlassian.Jira.Test/AttachmentTest.cs

https://bitbucket.org/yyo/atlassian.net-sdk-v2.0
C# | 61 lines | 45 code | 10 blank | 6 comment | 0 complexity | ba97cfe112446f6fa230263158a226d6 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Xunit;
  6. using Atlassian.Jira.Remote;
  7. using Moq;
  8. namespace Atlassian.Jira.Test
  9. {
  10. public class AttachmentTest
  11. {
  12. [Fact]
  13. public void Download_ShouldSaveAttachmentToSpecifiedLocation()
  14. {
  15. //arrange
  16. var mockWebClient = new Mock<IWebClient>();
  17. var mockSoapClient = new Mock<IJiraRemoteService>();
  18. mockSoapClient.Setup(j => j.Url).Returns("http://foo:2990/jira/");
  19. var jira = new Jira(null, mockSoapClient.Object, null, "user", "pass");
  20. var attachment = (new RemoteAttachment()
  21. {
  22. id = "attachID",
  23. filename = "attach.txt"
  24. }).ToLocal(jira, mockWebClient.Object);
  25. //act
  26. attachment.Download("C:\\foo\\bar.txt");
  27. //assert
  28. mockWebClient.Verify(c => c.AddQueryString("os_username", "user"));
  29. mockWebClient.Verify(c => c.AddQueryString("os_password", "pass"));
  30. mockWebClient.Verify(c => c.Download("http://foo:2990/jira/secure/attachment/attachID/attach.txt", "C:\\foo\\bar.txt"));
  31. }
  32. [Fact]
  33. public void Download_IfJiraUrlDoesNotEndInSlash_ShouldFixTheUrlBeforeDownloading()
  34. {
  35. //arrange
  36. var mockWebClient = new Mock<IWebClient>();
  37. var mockSoapClient = new Mock<IJiraRemoteService>();
  38. mockSoapClient.Setup(j => j.Url).Returns("http://foo:2990/jira");
  39. var jira = new Jira(null, mockSoapClient.Object, null, "user", "pass");
  40. var attachment = (new RemoteAttachment()
  41. {
  42. id = "attachID",
  43. filename = "attach.txt"
  44. }).ToLocal(jira, mockWebClient.Object);
  45. //act
  46. attachment.Download("C:\\foo\\bar.txt");
  47. //assert
  48. mockWebClient.Verify(c => c.Download("http://foo:2990/jira/secure/attachment/attachID/attach.txt", "C:\\foo\\bar.txt"));
  49. }
  50. }
  51. }