From 8ca94c0c9339a4521585ce4a546d97463107a663 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 27 Apr 2016 11:54:48 -0700 Subject: [PATCH 1/2] added 2 section unit tests. Update fails as expected. --- src/Tests/HelpCenter/SectionTests.cs | 41 ++++++++++++++++++++++++++++ src/Tests/Tests.csproj | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/Tests/HelpCenter/SectionTests.cs diff --git a/src/Tests/HelpCenter/SectionTests.cs b/src/Tests/HelpCenter/SectionTests.cs new file mode 100644 index 00000000..98418116 --- /dev/null +++ b/src/Tests/HelpCenter/SectionTests.cs @@ -0,0 +1,41 @@ +using NUnit.Framework; +using ZendeskApi_v2; +using ZendeskApi_v2.Models.Sections; +using ZendeskApi_v2.Requests.HelpCenter; + +namespace Tests.HelpCenter +{ + [TestFixture] + [Category( "HelpCenter" )] + class SectionTests + { + private ZendeskApi api = new ZendeskApi( Settings.Site, Settings.Email, Settings.Password ); + + [Test] + + public void CanGetSections() + { + var res = api.HelpCenter.Sections.GetSections(); + Assert.Greater( res.Count, 0 ); + + var res1 = api.HelpCenter.Sections.GetSectionById( res.Sections[ 0 ].Id.Value ); + Assert.AreEqual( res1.Section.Id, res.Sections[ 0 ].Id.Value ); + } + + [Test] + public void CanCreateUpdateAndDeleteSections() + { + var res = api.HelpCenter.Sections.CreateSection( new Section() + { + Name = "My Test section" + } ); + Assert.Greater( res.Section.Id, 0 ); + + res.Section.Description = "updated description"; + var update = api.HelpCenter.Sections.UpdateSection( res.Section ); + Assert.AreEqual( update.Section.Description, res.Section.Description ); + + Assert.True( api.HelpCenter.Sections.DeleteSection( res.Section.Id.Value ) ); + } + } +} diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 5875fe22..fc55b9c0 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -87,6 +87,7 @@ + From 0fe9ecb1eded385a88daddacee6f621de20d8900 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 27 Apr 2016 12:25:33 -0700 Subject: [PATCH 2/2] Fixed CreateSection API call Updated Section unit test to include category ID --- src/Tests/HelpCenter/SectionTests.cs | 6 +++++- src/ZendeskApi_v2/Requests/HelpCenter/Sections.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Tests/HelpCenter/SectionTests.cs b/src/Tests/HelpCenter/SectionTests.cs index 98418116..29638105 100644 --- a/src/Tests/HelpCenter/SectionTests.cs +++ b/src/Tests/HelpCenter/SectionTests.cs @@ -25,9 +25,13 @@ public void CanGetSections() [Test] public void CanCreateUpdateAndDeleteSections() { + //https://csharpapi.zendesk.com/hc/en-us/categories/200382245-Category-1 + long category_id = 200382245; + var res = api.HelpCenter.Sections.CreateSection( new Section() { - Name = "My Test section" + Name = "My Test section", + CategoryId = category_id } ); Assert.Greater( res.Section.Id, 0 ); diff --git a/src/ZendeskApi_v2/Requests/HelpCenter/Sections.cs b/src/ZendeskApi_v2/Requests/HelpCenter/Sections.cs index c07e0b41..0bfe96dc 100644 --- a/src/ZendeskApi_v2/Requests/HelpCenter/Sections.cs +++ b/src/ZendeskApi_v2/Requests/HelpCenter/Sections.cs @@ -57,7 +57,7 @@ public IndividualSectionResponse GetSectionById(long id) public IndividualSectionResponse CreateSection(Section section) { var body = new { section }; - return GenericPost(string.Format("help_center/sections.json"), body); + return GenericPost(string.Format( "help_center/categories/{0}/sections.json", section.CategoryId ), body); } public IndividualSectionResponse UpdateSection(Section section)