private static RequestBodyBuilder PopulateRequestParameters(TroubleshooterAttachmentRequest troubleshooterAttachmentRequest, RequestTypes requestType)
        {
            troubleshooterAttachmentRequest.EnsureValidData(requestType);

            var 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)
        {
            var parameters = PopulateRequestParameters(troubleshooterAttachmentRequest, RequestTypes.Create);

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

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

            return(null);
        }
Exemple #3
0
        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";
            var          parameters = string.Format("troubleshooterstepid=1&filename=test.txt&contents={0}", contents);

            this.kayakoApiRequest.Setup(x => x.ExecutePost <TroubleshooterAttachmentCollection>(apiMethod, parameters)).Returns(this.responseTroubleshooterAttachmentCollection);

            var troubleshooterAttachment = this.troubleshooterController.CreateTroubleshooterAttachment(troubleshooterAttachmentRequest);

            this.kayakoApiRequest.Verify(x => x.ExecutePost <TroubleshooterAttachmentCollection>(apiMethod, parameters), Times.Once());
            Assert.That(troubleshooterAttachment, Is.EqualTo(this.responseTroubleshooterAttachmentCollection.FirstOrDefault()));
        }
Exemple #4
0
        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);
        }