private RequestBodyBuilder PopulateRequestParameters(TroubleshooterCategoryRequest troubleshooterCategoryRequest, RequestTypes requestType)
        {
            troubleshooterCategoryRequest.EnsureValidData(requestType);

            var parameters = new RequestBodyBuilder();

            parameters.AppendRequestDataNonEmptyString("title", troubleshooterCategoryRequest.Title);
            parameters.AppendRequestData("categorytype", EnumUtility.ToApiString(troubleshooterCategoryRequest.CategoryType));

            if (requestType == RequestTypes.Create)
            {
                parameters.AppendRequestDataNonNegativeInt("staffid", troubleshooterCategoryRequest.StaffId);
            }

            if (troubleshooterCategoryRequest.DisplayOrder.HasValue)
            {
                parameters.AppendRequestDataNonNegativeInt("displayorder", troubleshooterCategoryRequest.DisplayOrder.Value);
            }

            parameters.AppendRequestDataNonEmptyString("description", troubleshooterCategoryRequest.Description);
            parameters.AppendRequestDataBool("uservisibilitycustom", troubleshooterCategoryRequest.UserVisibilityCustom);
            parameters.AppendRequestDataArrayCommaSeparated("usergroupidlist", troubleshooterCategoryRequest.UserGroupIdList);
            parameters.AppendRequestDataBool("staffvisibilitycustom", troubleshooterCategoryRequest.StaffVisibilityCustom);
            parameters.AppendRequestDataArrayCommaSeparated("staffgroupidlist", troubleshooterCategoryRequest.StaffGroupIdList);

            return(parameters);
        }
Пример #2
0
        public void CreateTroubleshooterCategory()
        {
            var troubleshooterCategoryRequest = new TroubleshooterCategoryRequest
            {
                Title                 = "TitleCategory",
                CategoryType          = TroubleshooterCategoryType.Private,
                StaffId               = 2,
                DisplayOrder          = 1,
                Description           = "Description",
                UserVisibilityCustom  = true,
                UserGroupIdList       = new[] { 1, 2, 3 },
                StaffVisibilityCustom = true,
                StaffGroupIdList      = new[] { 3, 4, 5 }
            };

            const string apiMethod  = "/Troubleshooter/Category";
            const string parameters = "title=TitleCategory&categorytype=3&staffid=2&displayorder=1&description=Description&uservisibilitycustom=1&usergroupidlist=1,2,3&staffvisibilitycustom=1&staffgroupidlist=3,4,5";

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

            var troubleshooterCategory = this.troubleshooterController.CreateTroubleshooterCategory(troubleshooterCategoryRequest);

            this.kayakoApiRequest.Verify(x => x.ExecutePost <TroubleshooterCategoryCollection>(apiMethod, parameters), Times.Once());
            Assert.That(troubleshooterCategory, Is.EqualTo(this.responseTroubleshooterCategoryCollection.FirstOrDefault()));
        }
        public TroubleshooterCategory CreateTroubleshooterCategory(TroubleshooterCategoryRequest troubleshooterCategoryRequest)
        {
            var parameters = this.PopulateRequestParameters(troubleshooterCategoryRequest, RequestTypes.Create);

            var troubleshooterCategories = this.Connector.ExecutePost <TroubleshooterCategoryCollection>(TroubleshooterCategoryBaseUrl, parameters.ToString());

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

            return(null);
        }
        public TroubleshooterCategory UpdateTroubleshooterCategory(TroubleshooterCategoryRequest troubleshooterCategoryRequest)
        {
            var apiMethod  = string.Format("{0}/{1}", TroubleshooterCategoryBaseUrl, troubleshooterCategoryRequest.Id);
            var parameters = this.PopulateRequestParameters(troubleshooterCategoryRequest, RequestTypes.Update);

            var troubleshooterCategories = this.Connector.ExecutePut <TroubleshooterCategoryCollection>(apiMethod, parameters.ToString());

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

            return(null);
        }
Пример #5
0
        public void CreateUpdateDeleteNewsCategory()
        {
            TroubleshooterCategoryRequest troubleshooterCategoryRequest = new TroubleshooterCategoryRequest
            {
                Title                 = "Troubleshooter Category Request",
                CategoryType          = TroubleshooterCategoryType.Public,
                StaffId               = 1,
                DisplayOrder          = 5,
                Description           = "Description of Troubleshooter Category Request",
                UserVisibilityCustom  = false,
                StaffVisibilityCustom = false
            };

            var troubleshooterCategory = TestSetup.KayakoApiService.Troubleshooter.CreateTroubleshooterCategory(troubleshooterCategoryRequest);

            Assert.IsNotNull(troubleshooterCategory);
            Assert.That(troubleshooterCategory.Title, Is.EqualTo(troubleshooterCategoryRequest.Title));
            Assert.That(troubleshooterCategory.CategoryType, Is.EqualTo(troubleshooterCategoryRequest.CategoryType));
            Assert.That(troubleshooterCategory.StaffId, Is.EqualTo(troubleshooterCategoryRequest.StaffId));
            Assert.That(troubleshooterCategory.DisplayOrder, Is.EqualTo(troubleshooterCategoryRequest.DisplayOrder));
            Assert.That(troubleshooterCategory.Description, Is.EqualTo(troubleshooterCategoryRequest.Description));
            Assert.That(troubleshooterCategory.UserVisibilityCustom, Is.EqualTo(troubleshooterCategoryRequest.UserVisibilityCustom));
            Assert.That(troubleshooterCategory.StaffVisibilityCustom, Is.EqualTo(troubleshooterCategoryRequest.StaffVisibilityCustom));

            troubleshooterCategoryRequest.Id           = troubleshooterCategory.Id;
            troubleshooterCategoryRequest.Title       += "_Title";
            troubleshooterCategoryRequest.Description += "_Updated";

            troubleshooterCategory = TestSetup.KayakoApiService.Troubleshooter.UpdateTroubleshooterCategory(troubleshooterCategoryRequest);

            Assert.IsNotNull(troubleshooterCategory);
            Assert.That(troubleshooterCategory.Title, Is.EqualTo(troubleshooterCategoryRequest.Title));
            Assert.That(troubleshooterCategory.Description, Is.EqualTo(troubleshooterCategoryRequest.Description));

            var deleteResult = TestSetup.KayakoApiService.Troubleshooter.DeleteTroubleshooterCategory(troubleshooterCategoryRequest.Id);

            Assert.IsTrue(deleteResult);
        }
        public void UpdateTroubleshooterCategory()
        {
            var troubleshooterCategoryRequest = new TroubleshooterCategoryRequest
            {
                Title                 = "TitleCategory",
                CategoryType          = TroubleshooterCategoryType.Public,
                DisplayOrder          = 1,
                Description           = "Description",
                UserVisibilityCustom  = true,
                UserGroupIdList       = new[] { 1, 2, 3 },
                StaffVisibilityCustom = true,
                StaffGroupIdList      = new[] { 3, 4, 5 }
            };

            var          apiMethod  = string.Format("/Troubleshooter/Category/{0}", troubleshooterCategoryRequest.Id);
            const string parameters = "title=TitleCategory&categorytype=2&displayorder=1&description=Description&uservisibilitycustom=1&usergroupidlist=1,2,3&staffvisibilitycustom=1&staffgroupidlist=3,4,5";

            _kayakoApiRequest.Setup(x => x.ExecutePut <TroubleshooterCategoryCollection>(apiMethod, parameters)).Returns(_responseTroubleshooterCategoryCollection);

            var troubleshooterCategory = _troubleshooterController.UpdateTroubleshooterCategory(troubleshooterCategoryRequest);

            _kayakoApiRequest.Verify(x => x.ExecutePut <TroubleshooterCategoryCollection>(apiMethod, parameters), Times.Once());
            Assert.That(troubleshooterCategory, Is.EqualTo(_responseTroubleshooterCategoryCollection.FirstOrDefault()));
        }