public void CreateTroubleshooterAttachment()
        {
            var contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the file contents"));

            var troubleshooterAttachmentRequest = new TroubleshooterAttachmentRequest
            {
                TroubleshooterStepId = 1,
                FileName = "test.txt",
                Contents = contents
            };

            const string apiMethod = "/Troubleshooter/Attachment";
            string parameters = string.Format("troubleshooterstepid=1&filename=test.txt&contents={0}", contents);

            _kayakoApiRequest.Setup(x => x.ExecutePost<TroubleshooterAttachmentCollection>(apiMethod, parameters)).Returns(_responseTroubleshooterAttachmentCollection);

            var troubleshooterAttachment = _troubleshooterController.CreateTroubleshooterAttachment(troubleshooterAttachmentRequest);

            _kayakoApiRequest.Verify(x => x.ExecutePost<TroubleshooterAttachmentCollection>(apiMethod, parameters), Times.Once());
            Assert.That(troubleshooterAttachment, Is.EqualTo(_responseTroubleshooterAttachmentCollection.FirstOrDefault()));
        }
        public void CreateDeleteTroubleshooterAttachment()
        {
            string contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the contents"));

            var troubleshooterAttachmentRequest = new TroubleshooterAttachmentRequest
                {
                    TroubleshooterStepId = 1,
                    FileName = "Test.txt",
                    Contents = contents
                };

            var troubleshooterAttachment = TestSetup.KayakoApiService.Troubleshooter.CreateTroubleshooterAttachment(troubleshooterAttachmentRequest);

            Assert.IsNotNull(troubleshooterAttachment);
            Assert.That(troubleshooterAttachment.TroubleshooterStepId, Is.EqualTo(troubleshooterAttachment.TroubleshooterStepId));
            Assert.That(troubleshooterAttachment.FileName, Is.EqualTo(troubleshooterAttachment.FileName));
            Assert.That(troubleshooterAttachment.Contents, Is.EqualTo(contents));

            var deleteSuccess = TestSetup.KayakoApiService.Troubleshooter.DeleteTroubleshooterAttachment(troubleshooterAttachment.TroubleshooterStepId, troubleshooterAttachment.Id);

            Assert.IsTrue(deleteSuccess);
        }
Пример #3
0
 public static TroubleshooterAttachment ToResponseData(TroubleshooterAttachmentRequest requestData)
 {
     return(ToResponseType <TroubleshooterAttachmentRequest, TroubleshooterAttachment>(requestData));
 }
		private RequestBodyBuilder PopulateRequestParameters(TroubleshooterAttachmentRequest troubleshooterAttachmentRequest, RequestTypes requestType)
		{
			troubleshooterAttachmentRequest.EnsureValidData(requestType);

			RequestBodyBuilder parameters = new RequestBodyBuilder();
			parameters.AppendRequestDataNonNegativeInt("troubleshooterstepid", troubleshooterAttachmentRequest.TroubleshooterStepId);
			parameters.AppendRequestDataNonEmptyString("filename", troubleshooterAttachmentRequest.FileName);
			parameters.AppendRequestDataNonEmptyString("contents", troubleshooterAttachmentRequest.Contents);

			return parameters;
		}
		public TroubleshooterAttachment CreateTroubleshooterAttachment(TroubleshooterAttachmentRequest troubleshooterAttachmentRequest)
		{
			RequestBodyBuilder parameters = PopulateRequestParameters(troubleshooterAttachmentRequest, RequestTypes.Create);

			TroubleshooterAttachmentCollection troubleshooterAttachments = Connector.ExecutePost<TroubleshooterAttachmentCollection>(TroubleshooterAttachmentBaseUrl, parameters.ToString());

			if (troubleshooterAttachments != null && troubleshooterAttachments.Count > 0)
			{
				return troubleshooterAttachments[0];
			}

			return null;
		}
		public static TroubleshooterAttachment ToResponseData(TroubleshooterAttachmentRequest requestData)
		{
			return ToResponseType<TroubleshooterAttachmentRequest, TroubleshooterAttachment>(requestData);
		}