public void CreateDeleteTicketAttachment()
        {
            string contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the contents"));

            var knowledgebaseAttachmentRequest = new KnowledgebaseAttachmentRequest
            {
                KnowledgebaseArticleId = 1,
                FileName = "Test.txt",
                Contents = contents
            };

            var knowledgebaseAttachment = TestSetup.KayakoApiService.Knowledgebase.CreateKnowledgebaseAttachment(knowledgebaseAttachmentRequest);

            Assert.IsNotNull(knowledgebaseAttachment);
            Assert.That(knowledgebaseAttachment.KnowledgebaseArticleId, Is.EqualTo(knowledgebaseAttachment.KnowledgebaseArticleId));
            Assert.That(knowledgebaseAttachment.FileName, Is.EqualTo(knowledgebaseAttachment.FileName));
            Assert.That(knowledgebaseAttachment.Contents, Is.EqualTo(contents));

            var deleteSuccess = TestSetup.KayakoApiService.Knowledgebase.DeleteKnowledgebaseAttachment(knowledgebaseAttachment.KnowledgebaseArticleId, knowledgebaseAttachment.Id);

            Assert.IsTrue(deleteSuccess);
        }
        public void CreateKnowledgebaseAttachement()
        {
            string contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the contents"));

            var knowledgebaseAttachmentRequest = new KnowledgebaseAttachmentRequest
                {
                    KnowledgebaseArticleId = 1,
                    FileName = "fileName",
                    Contents = contents
                };

            const string apiMethod = "/Knowledgebase/Attachment";
            var parameters = string.Format("kbarticleid=1&filename=fileName&contents={0}", contents);

            _kayakoApiRequest.Setup(x => x.ExecutePost<KnowledgebaseAttachmentCollection>(apiMethod, parameters)).Returns(_responseKnowledgebaseAttachmentCollection);

            var knowledgebaseAttachment = _knowledgebaseController.CreateKnowledgebaseAttachment(knowledgebaseAttachmentRequest);

            _kayakoApiRequest.Verify(x => x.ExecutePost<KnowledgebaseAttachmentCollection>(apiMethod, parameters));

            Assert.That(knowledgebaseAttachment, Is.EqualTo(_responseKnowledgebaseAttachmentCollection.First()));
        }
		public static KnowledgebaseAttachment ToResponseData(KnowledgebaseAttachmentRequest requestData)
		{
			return ToResponseType<KnowledgebaseAttachmentRequest, KnowledgebaseAttachment>(requestData);
		}
示例#4
0
 public static KnowledgebaseAttachment ToResponseData(KnowledgebaseAttachmentRequest requestData)
 {
     return(ToResponseType <KnowledgebaseAttachmentRequest, KnowledgebaseAttachment>(requestData));
 }
		private RequestBodyBuilder PopulateRequestParameters(KnowledgebaseAttachmentRequest knowledgebaseAttachmentRequest, RequestTypes requestType)
		{
			knowledgebaseAttachmentRequest.EnsureValidData(requestType);

			RequestBodyBuilder parameters = new RequestBodyBuilder();
			parameters.AppendRequestDataNonNegativeInt("kbarticleid", knowledgebaseAttachmentRequest.KnowledgebaseArticleId);
			parameters.AppendRequestDataNonEmptyString("filename", knowledgebaseAttachmentRequest.FileName);
			parameters.AppendRequestDataNonEmptyString("contents", knowledgebaseAttachmentRequest.Contents);

			return parameters;
		}
		public KnowledgebaseAttachment CreateKnowledgebaseAttachment(KnowledgebaseAttachmentRequest knowledgebaseAttachmentRequest)
		{
			const string apiMethod = KnowledgebaseAttachmentBaseUrl;
			RequestBodyBuilder parameters = PopulateRequestParameters(knowledgebaseAttachmentRequest, RequestTypes.Create);

			KnowledgebaseAttachmentCollection knowledgebaseAttachments = Connector.ExecutePost<KnowledgebaseAttachmentCollection>(apiMethod, parameters.ToString());

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

			return null;
		}