Esempio n. 1
0
 public static TicketRequest FromResponseData(Ticket responseData)
 {
     return(TicketRequest.FromResponseType <Ticket, TicketRequest>(responseData));
 }
Esempio n. 2
0
 public static Ticket ToResponseData(TicketRequest requestData)
 {
     return(TicketRequest.ToResponseType <TicketRequest, Ticket>(requestData));
 }
        public void Setup()
        {
            _kayakoApiRequest = new Mock<IKayakoApiRequest>();

            _ticketController = new TicketController(_kayakoApiRequest.Object);

            _responseTicketCollection = new TicketCollection
                {
                    new Ticket()
                };

            _createTicketRequestRequiredFields = new TicketRequest
                {
                    Subject = "Subject",
                    FullName = "Fullname",
                    Email = "*****@*****.**",
                    Contents = "Contents",
                    DepartmentId = 1,
                    TicketStatusId = 2,
                    TicketPriorityId = 3,
                    TicketTypeId = 4
                };

            _createTicketRequiredFieldsParameters = "subject=Subject&fullname=Fullname&[email protected]&contents=Contents&departmentid=1&ticketstatusid=2&ticketpriorityid=3&tickettypeid=4";

            _responseTicketCustomFields = new TicketCustomFields
                {
                    FieldGroups = new List<TicketCustomFieldGroup>
                        {
                            new TicketCustomFieldGroup
                                {
                                    Id = 1,
                                    Title = "Title",
                                    Fields = new[]
                                        {
                                            new TicketCustomField
                                                {
                                                    Type = TicketCustomFieldType.Text,
                                                    Name = "FieldName1",
                                                    FieldContent = "content1"
                                                },
                                            new TicketCustomField
                                                {
                                                    Type = TicketCustomFieldType.Text,
                                                    Name = "FieldName2",
                                                    FieldContent = "content2"
                                                }
                                        }
                                }
                        }
                };
        }
 public static Ticket ToResponseData(TicketRequest requestData)
 {
     return TicketRequest.ToResponseType<TicketRequest, Ticket>(requestData);
 }
        public void UpdateTicket_TemplateGroupName()
        {
            var ticketRequest = new TicketRequest
            {
                Id = 39,
                TemplateGroupName = "templatename"
            };

            const string parameters = "templategroup=templatename";

            UpdateTicketRequest(parameters, ticketRequest);
        }
        private void UpdateTicketRequest(string parameters, TicketRequest ticketRequest)
        {
            string apiMethod = String.Format("/Tickets/Ticket/{0}", ticketRequest.Id);

            _kayakoApiRequest.Setup(x => x.ExecutePut<TicketCollection>(apiMethod, parameters)).Returns(_responseTicketCollection);

            Ticket ticket = _ticketController.UpdateTicket(ticketRequest);

            _kayakoApiRequest.Verify(x => x.ExecutePut<TicketCollection>(apiMethod, parameters), Times.Once());

            Assert.That(ticket, Is.EqualTo(_responseTicketCollection.FirstOrDefault()));
        }
        public void UpdateTicket_TemplateGroupId()
        {
            var ticketRequest = new TicketRequest
                {
                    Id = 39,
                    TemplateGroupId = 1
                };

            const string parameters = "templategroup=1";

            UpdateTicketRequest(parameters, ticketRequest);
        }
        public void UpdateTicket()
        {
            var ticketRequest = new TicketRequest
                {
                    Id = 39,
                    Subject = "Subject",
                    FullName = "Fullname",
                    Email = "*****@*****.**",
                    DepartmentId = 1,
                    TicketStatusId = 2,
                    TicketPriorityId = 3,
                    TicketTypeId = 4,
                    OwnerStaffId = 5,
                    UserId = 6,
                    TemplateGroupId = 7
                };

            string parameters = "subject=Subject&fullname=Fullname&[email protected]&departmentid=1&ticketstatusid=2&ticketpriorityid=3&tickettypeid=4&ownerstaffid=5&userid=6&templategroup=7";

            UpdateTicketRequest(parameters, ticketRequest);
        }
		public Ticket UpdateTicket(TicketRequest request)
        {
			request.EnsureValidData(RequestTypes.Update);

            RequestBodyBuilder parameters = new RequestBodyBuilder();

			if (!String.IsNullOrEmpty(request.Subject))
            {
				parameters.AppendRequestData("subject", request.Subject);
            }

			if (!String.IsNullOrEmpty(request.FullName))
            {
				parameters.AppendRequestData("fullname", request.FullName);
            }

			if (!String.IsNullOrEmpty(request.Email))
            {
				parameters.AppendRequestData("email", request.Email);
            }

			if (request.DepartmentId != null)
            {
				parameters.AppendRequestData("departmentid", request.DepartmentId);
            }

			if (request.TicketStatusId != null)
            {
				parameters.AppendRequestData("ticketstatusid", request.TicketStatusId);
            }

			if (request.TicketPriorityId != null)
            {
				parameters.AppendRequestData("ticketpriorityid", request.TicketPriorityId);
            }

			if (request.TicketTypeId != null)
            {
				parameters.AppendRequestData("tickettypeid", request.TicketTypeId);
            }

			if (request.OwnerStaffId != null)
            {
				parameters.AppendRequestData("ownerstaffid", request.OwnerStaffId);
            }

			if (request.UserId != null)
            {
				parameters.AppendRequestData("userid", request.UserId);
            }

			if (request.TemplateGroupId != null)
			{
				parameters.AppendRequestData("templategroup", request.TemplateGroupId);
			}
			else if(!string.IsNullOrEmpty(request.TemplateGroupName))
			{
				parameters.AppendRequestData("templategroup", request.TemplateGroupName);
			}

			string apiMethod = String.Format("/Tickets/Ticket/{0}", request.Id);

            TicketCollection tickets = Connector.ExecutePut<TicketCollection>(apiMethod, parameters.ToString());

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

            return null;
        }
        public Ticket CreateTicket(TicketRequest ticketRequest)
        {
			string apiMethod = "/Tickets/Ticket";

            ticketRequest.EnsureValidData(RequestTypes.Create);

            RequestBodyBuilder parameters = new RequestBodyBuilder();

            parameters.AppendRequestData("subject", ticketRequest.Subject);
            parameters.AppendRequestData("fullname", ticketRequest.FullName);
            parameters.AppendRequestData("email", ticketRequest.Email);
            parameters.AppendRequestData("contents", ticketRequest.Contents);
            parameters.AppendRequestData("departmentid", ticketRequest.DepartmentId);
            parameters.AppendRequestData("ticketstatusid", ticketRequest.TicketStatusId);
            parameters.AppendRequestData("ticketpriorityid", ticketRequest.TicketPriorityId);
            parameters.AppendRequestData("tickettypeid", ticketRequest.TicketTypeId);

            if (ticketRequest.AutoUserId != null)
            {
                parameters.AppendRequestData("autouserid", Convert.ToInt32(ticketRequest.AutoUserId));
            }
            else if (ticketRequest.UserId != null)
            {
                parameters.AppendRequestData("userid", ticketRequest.UserId);
            }
            else if (ticketRequest.StaffId != null)
            {
                parameters.AppendRequestData("staffid", ticketRequest.StaffId);
            }

            if (ticketRequest.OwnerStaffId != null)
            {
                parameters.AppendRequestData("ownerstaffid", ticketRequest.OwnerStaffId);
            }

			if (ticketRequest.TemplateGroupId != null)
			{
				parameters.AppendRequestData("templategroup", ticketRequest.TemplateGroupId);
			}
			else if (!string.IsNullOrEmpty(ticketRequest.TemplateGroupName))
			{
				parameters.AppendRequestData("templategroup", ticketRequest.TemplateGroupName);
			}

			if (ticketRequest.IgnoreAutoResponder != null)
			{
				parameters.AppendRequestData("ignoreautoresponder", Convert.ToInt32(ticketRequest.IgnoreAutoResponder));
			}

			if (ticketRequest.CreationType != null)
			{
				parameters.AppendRequestData("type", EnumUtility.ToApiString(ticketRequest.CreationType));
			}

            TicketCollection tickets = Connector.ExecutePost<TicketCollection>(apiMethod, parameters.ToString());

            if (tickets.Count > 0)
            {
                return tickets[0];
            }

            return null;
        }
Esempio n. 11
0
        public void CreateUpdateDeleteTicket()
        {
            string subject = "Ticket Subject";
            string fullname = "Ticket FullName";
            string email = "*****@*****.**";
            string contents = "Contents of the ticket";
            int deptId = 3;
            int statusId = 1;
            int priorityId = 1;
            int typeId = 1;
            int ownerId = 1;
            TicketCreationType type = TicketCreationType.Default;

            TicketRequest request = new TicketRequest()
            {
                Subject = subject,
                FullName = fullname,
                Email = email,
                Contents = contents,
                DepartmentId = deptId,
                TemplateGroupId = 1,
                TicketStatusId = statusId,
                TicketPriorityId = priorityId,
                TicketTypeId = typeId,
                OwnerStaffId = ownerId,
                CreationType = type,
                AutoUserId = true,
            };

            //Ticket createdTicket = TestSetup.KayakoApiService.Tickets.CreateTicket(subject, fullname, email, contents, deptId, statusId, priorityId, typeId, ownerId, type);
            Ticket createdTicket = TestSetup.KayakoApiService.Tickets.CreateTicket(request);

            Assert.IsNotNull(createdTicket);
            Assert.AreEqual(createdTicket.Subject, subject);
            Assert.AreEqual(createdTicket.FullName, fullname);
            Assert.AreEqual(createdTicket.Email, email);
            Assert.AreEqual(createdTicket.DepartmentId, deptId);
            Assert.AreEqual(createdTicket.StatusId, statusId);
            Assert.AreEqual(createdTicket.PriorityId, priorityId);
            Assert.AreEqual(createdTicket.Replies, 0);
            Assert.AreEqual(createdTicket.TypeId, typeId);
            //Assert.AreEqual(createdTicket.OwnerStaffId, ownerId);

            request.Id = createdTicket.Id;
            request.Subject = "Updated " + subject;
            request.FullName = "Updated " + fullname;
            request.Contents = "Updated " + contents;
            request.TemplateGroupId = 1;

            Ticket updatedTicket = TestSetup.KayakoApiService.Tickets.UpdateTicket(request);

            Assert.IsNotNull(updatedTicket);
            //Assert.AreEqual(updatedTicket.Subject, request.Subject);
            //Assert.AreEqual(updatedTicket.FullName, request.FullName);
            //Assert.AreEqual(updatedTicket.Email, request.Email);
            //Assert.AreEqual(updatedTicket.DepartmentId, request.DepartmentId);
            //Assert.AreEqual(updatedTicket.StatusId, request.TicketStatusId);
            //Assert.AreEqual(updatedTicket.PriorityId, request.TicketPriorityId);
            //Assert.AreEqual(updatedTicket.Replies, 0);
            //Assert.AreEqual(updatedTicket.TypeId, request.TicketTypeId);
            //Assert.AreEqual(updatedTicket.OwnerStaffId, request.OwnerStaffId);

            bool success = TestSetup.KayakoApiService.Tickets.DeleteTicket(updatedTicket.Id);

            Assert.IsTrue(success);
        }