Guest User

Untitled

a guest
Aug 25th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. Gallio can't run test from console
  2. using System.Data.Services;
  3. using System.ServiceModel;
  4. using System.ServiceModel.Description;
  5.  
  6. namespace TenForce.Execution.Api2.OData.Tests.IntegrationTests
  7. {
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ServiceModel.Web;
  11. using MbUnit.Framework;
  12. using Objects;
  13. using Helpers;
  14. using Test.Attributes;
  15.  
  16. /// <summary>
  17. /// <para>This class contains all the integration tests to verify the correct working conditions for attachment entities.</para>
  18. /// </summary>
  19. public class AttachmentIntegrationTests : BaseIntegrationTest
  20. {
  21. /// <summary>
  22. /// <para>This test will try to create a new attachment on an item using a local file.</para>
  23. /// </summary>
  24. [Test, MaxDuration]
  25. public void AttachmentUpload()
  26. {
  27. #region Test Preparation
  28.  
  29. // Prepare a Workspace
  30. var workspace = CreateWorkspaceObject();
  31. Assert.IsTrue(Factory.CreateApi().Workspaces.Create(workspace), "Expected the test workspace to be created.");
  32.  
  33. // Prepare a List
  34. var list = CreateList();
  35. list.Workspace = workspace;
  36. list.ItemType = new ItemType {Id = 5};
  37. Assert.IsTrue(Factory.CreateApi().Lists.Create(list), "Expected the test list to be created.");
  38.  
  39. // Prepare an Item.
  40. var itemFields = new List<ItemField>
  41. {
  42. new ItemField {FieldId = "SF19", Type = "List", ValueId = list.Id},
  43. new ItemField {FieldId = "SF2", Type = "Title", Value = string.Format("I {0}", DateTime.Now)},
  44. new ItemField {FieldId = "SF4", Type = "AssignedTo", ValueId = 1}
  45. };
  46. var item = new Item { ItemFields = itemFields.ToArray() };
  47. Assert.IsTrue(Factory.CreateApi().Items.Create(item), "Expected the test item to be created.");
  48.  
  49. #endregion
  50.  
  51. using (var host = new DataServiceHost(typeof (Web.Api), new[] {BaseUri}))
  52. {
  53. // Start the host
  54. host.Open();
  55.  
  56. // Create a new WebClient to create a call to the attachments resource
  57. var client = new ODataClient {BaseUri = BaseUri, Username = "sadmin", Password = string.Empty};
  58.  
  59. // Send the file contents to the service using the correct url.
  60. string response = client.UploadAttachment(GetTestFileLocation("ReportingTest.xls"), item.Id);
  61. var parser = new ODataParser();
  62. parser.LoadResponse(response);
  63.  
  64. // Fetch the Id of the Attachment, this should be greater than 0.
  65. int attachmentId = parser.GetEntityId();
  66. Assert.IsTrue(attachmentId > 0, "Expected the Id to be greater than zero.");
  67.  
  68. // Verify if the item is coupled to the correct Item.
  69. response = client.GetResource(string.Format("Attachments({0})/Item", attachmentId));
  70. parser.LoadResponse(response);
  71. int itemId = parser.GetEntityId();
  72. Assert.IsTrue(itemId == item.Id, "Expected the linked item to have a matching Id.");
  73.  
  74. // Change the filename of the uploaded file and verify whether the file is properly renamed.
  75. client.UpdateProperty(string.Format("Items({0})/Attachments({1})/Filename/$value", itemId, attachmentId), "uploaded_excel.xls");
  76.  
  77. // Verify if the changes made it to the database.
  78. Attachment att = Factory.CreateApi().Attachments.Read(attachmentId);
  79. Assert.AreEqual("uploaded_excel.xls", att.Filename, "Expected the data to be changed on the entity.");
  80. Assert.IsTrue(System.IO.File.Exists(Factory.CreateApi().Attachments.GetAttachmentPath(att, false)), "Expected the file to be present on the hard drive.");
  81.  
  82. // Close the host properly
  83. host.Close();
  84. }
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment