22{
33 using System ;
44 using System . Collections . Generic ;
5+ using System . Linq ;
56 using System . Threading . Tasks ;
67 using Xunit ;
78 using Microsoft . Graph . Models ;
89 using Microsoft . Kiota . Abstractions ;
910
1011 public class PlannerTests : GraphTestBase
1112 {
12- private readonly Group testGroup = new ( ) ;
13+ private Group testGroup = new ( ) ;
1314
1415 private async void TestCleanUp ( )
1516 {
@@ -115,7 +116,7 @@ public async Task PlannerGetPlannerTasks()
115116 Assert . Fail ( $ "Something happened, check out a trace. Error: { e . Message } ") ;
116117 }
117118 }
118- /*
119+
119120 // Successful 4/27/2017 - Creates a task without a bucket.
120121 [ Fact ( Skip = "No CI set up for functional tests" ) ]
121122 //https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/planner_post_tasks
@@ -131,18 +132,21 @@ public async Task PlannerTaskCreate()
131132 taskToCreate . PlanId = plannerPlan . Id ;
132133 taskToCreate . Title = "New task title" ;
133134 taskToCreate . Assignments = new PlannerAssignments ( ) ;
134- taskToCreate.Assignments.AddAssignee("me");
135+ taskToCreate . Assignments . AdditionalData [ "me" ] = new PlannerAssignment
136+ {
137+ OrderHint = " !"
138+ } ;
135139 taskToCreate . AppliedCategories = new PlannerAppliedCategories ( ) ;
136- taskToCreate.AppliedCategories.Category3 = true;
140+ taskToCreate . AppliedCategories . AdditionalData [ "category3" ] = true ;
137141 taskToCreate . DueDateTime = DateTimeOffset . UtcNow . AddDays ( 3 ) ;
138142
139143 PlannerTask createdTask = await graphClient . Planner . Tasks . PostAsync ( taskToCreate ) ;
140144
141145 Assert . NotNull ( createdTask ) ;
146+ Assert . NotNull ( createdTask . Assignments ) ;
142147 Assert . Equal ( taskToCreate . Title , createdTask . Title ) ;
143- Assert.Equal(1, createdTask.Assignments.Count);
144- Assert.Equal(createdTask.Assignments.Assignees.First(), createdTask.Assignments.First().Value.AssignedBy.User.Id);
145- Assert.Equal(true, createdTask.AppliedCategories.Category3);
148+ Assert . Single ( createdTask . Assignments . AdditionalData ) ;
149+ Assert . Equal ( true , createdTask . AppliedCategories . AdditionalData [ "category3" ] ) ;
146150 Assert . Equal ( taskToCreate . DueDateTime , createdTask . DueDateTime ) ;
147151 }
148152
@@ -162,25 +166,40 @@ public async Task PlannerTaskDetailsUpdate()
162166
163167 PlannerTaskDetails taskDetailsToUpdate = new PlannerTaskDetails ( ) ;
164168 taskDetailsToUpdate . Checklist = new PlannerChecklistItems ( ) ;
165- string checklistItemId1 = taskDetailsToUpdate.Checklist.AddChecklistItem("Do something");
166- string checklistItemId2 = taskDetailsToUpdate.Checklist.AddChecklistItem("Do something else");
167-
169+ string checklistItemId1 = Guid . NewGuid ( ) . ToString ( ) ;
170+ taskDetailsToUpdate . Checklist . AdditionalData [ checklistItemId1 ] = new PlannerCheckListItem ( )
171+ {
172+ Title = "Do Something"
173+ } ;
174+ string checklistItemId2 = Guid . NewGuid ( ) . ToString ( ) ;
175+ taskDetailsToUpdate . Checklist . AdditionalData [ checklistItemId1 ] = new PlannerCheckListItem ( )
176+ {
177+ Title = "Do Something else"
178+ } ;
168179 taskDetailsToUpdate . References = new PlannerExternalReferences ( ) ;
169- taskDetailsToUpdate.References.AddReference("http://developer.microsoft.com", "Developer resources");
180+ taskDetailsToUpdate . References . AdditionalData [ "http://developer.microsoft.com" ] = new PlannerExternalReference ( )
181+ {
182+ Alias = "Developer resources"
183+ } ;
170184
171185 taskDetailsToUpdate . PreviewType = PlannerPreviewType . Checklist ;
172186 taskDetailsToUpdate . Description = "Description of the task" ;
173187
174- string etag = taskDetails.GetEtag();
175- PlannerTaskDetails updatedTaskDetails = await graphClient.Planner.Tasks[createdTask.Id].Details.Header("If-Match", etag).Header("Prefer", "return=representation").UpdateAsync(taskDetailsToUpdate);
188+ string etag = taskDetails . AdditionalData [ "@odata.etag" ] . ToString ( ) ;
189+ PlannerTaskDetails updatedTaskDetails = await graphClient . Planner . Tasks [ createdTask . Id ] . Details
190+ . PatchAsync ( taskDetailsToUpdate , requestConfiguration =>
191+ {
192+ requestConfiguration . Headers . Add ( "If-Match" , etag ) ;
193+ requestConfiguration . Headers . Add ( "Prefer" , "return=representation" ) ;
194+ } ) ;
176195
177196 Assert . Equal ( "Description of the task" , updatedTaskDetails . Description ) ;
178197 Assert . Equal ( PlannerPreviewType . Checklist , updatedTaskDetails . PreviewType ) ;
179- Assert.Equal(2, updatedTaskDetails.Checklist.Count());
180- Assert.Equal("Do something", updatedTaskDetails.Checklist[checklistItemId1]?.Title);
181- Assert.Equal("Do something else", updatedTaskDetails.Checklist[checklistItemId2]?.Title);
182- Assert.Equal(1, updatedTaskDetails.References.Count());
183- Assert.Equal("Developer resources", updatedTaskDetails.References["http://developer.microsoft.com"]?.Alias);
198+ Assert . Equal ( 2 , updatedTaskDetails . Checklist . AdditionalData . Count ( ) ) ;
199+ Assert . Equal ( "Do something" , ( ( PlannerCheckListItem ) updatedTaskDetails . Checklist . AdditionalData [ checklistItemId1 ] ) ? . Title ) ;
200+ Assert . Equal ( "Do something else" , ( ( PlannerCheckListItem ) updatedTaskDetails . Checklist . AdditionalData [ checklistItemId2 ] ) ? . Title ) ;
201+ Assert . Equal ( 1 , updatedTaskDetails . References . AdditionalData . Count ( ) ) ;
202+ Assert . Equal ( "Developer resources" , ( ( PlannerExternalReference ) updatedTaskDetails . References . AdditionalData [ "http://developer.microsoft.com" ] ) ? . Alias ) ;
184203 }
185204
186205 [ Fact ( Skip = "No CI set up for functional tests" ) ]
@@ -193,21 +212,25 @@ public async Task PlannerPlanDetailsUpdate()
193212
194213 PlannerPlanDetails planDetails = await graphClient . Planner . Plans [ plannerPlan . Id ] . Details . GetAsync ( ) ;
195214
196- string etag = planDetails.GetEtag ();
215+ string etag = planDetails . AdditionalData [ "@odata.etag" ] . ToString ( ) ;
197216 PlannerPlanDetails planDetailsToUpdate = new PlannerPlanDetails ( ) ;
198217 planDetailsToUpdate . CategoryDescriptions = new PlannerCategoryDescriptions ( ) ;
199218 planDetailsToUpdate . CategoryDescriptions . Category1 = "First category" ;
200219 planDetailsToUpdate . CategoryDescriptions . Category4 = "Category 4" ;
201220 planDetailsToUpdate . SharedWith = new PlannerUserIds ( ) ;
202- planDetailsToUpdate.SharedWith.Add( "me") ;
221+ planDetailsToUpdate . SharedWith . AdditionalData [ "me" ] = true ;
203222
204- PlannerPlanDetails updatedPlanDetails = await graphClient.Planner.Plans[plannerPlan.Id].Details.Header("If-Match", etag).Header("Prefer", "return=representation").UpdateAsync(planDetailsToUpdate);
223+ PlannerPlanDetails updatedPlanDetails = await graphClient . Planner . Plans [ plannerPlan . Id ] . Details . PatchAsync ( planDetailsToUpdate , requestConfiguration =>
224+ {
225+ requestConfiguration . Headers . Add ( "If-Match" , etag ) ;
226+ requestConfiguration . Headers . Add ( "Prefer" , "return=representation" ) ;
227+ } ) ;
205228
206229 Assert . Equal ( "First category" , updatedPlanDetails . CategoryDescriptions . Category1 ) ;
207230 Assert . Equal ( "Category 4" , updatedPlanDetails . CategoryDescriptions . Category4 ) ;
208231
209232 // plan creator is the current user as well, we can get the id from there.
210- Assert.True(updatedPlanDetails.SharedWith.Contains (plannerPlan.CreatedBy.User.Id));
233+ Assert . True ( updatedPlanDetails . SharedWith . AdditionalData . ContainsKey ( plannerPlan . CreatedBy . User . Id ) ) ;
211234 }
212235
213236 [ Fact ( Skip = "No CI set up for functional tests" ) ]
@@ -221,23 +244,32 @@ public async Task PlannerTaskAssignedToTaskBoardFormatUpdate()
221244 taskToCreate . PlanId = plannerPlan . Id ;
222245 taskToCreate . Title = "Top" ;
223246 taskToCreate . Assignments = new PlannerAssignments ( ) ;
224- taskToCreate.Assignments.AddAssignee("me");
247+ taskToCreate . Assignments . AdditionalData [ "me" ] = new PlannerAssignment ( )
248+ {
249+ OrderHint = " !"
250+ } ;
225251
226252 PlannerTask topTask = await graphClient . Planner . Tasks . PostAsync ( taskToCreate ) ;
227253
228254 taskToCreate = new PlannerTask ( ) ;
229255 taskToCreate . PlanId = plannerPlan . Id ;
230256 taskToCreate . Title = "Bottom" ;
231257 taskToCreate . Assignments = new PlannerAssignments ( ) ;
232- taskToCreate.Assignments.AddAssignee("me");
258+ taskToCreate . Assignments . AdditionalData [ "me" ] = new PlannerAssignment ( )
259+ {
260+ OrderHint = " !"
261+ } ;
233262
234263 PlannerTask bottomTask = await graphClient . Planner . Tasks . PostAsync ( taskToCreate ) ;
235264
236265 taskToCreate = new PlannerTask ( ) ;
237266 taskToCreate . PlanId = plannerPlan . Id ;
238267 taskToCreate . Title = "Middle" ;
239268 taskToCreate . Assignments = new PlannerAssignments ( ) ;
240- taskToCreate.Assignments.AddAssignee("me");
269+ taskToCreate . Assignments . AdditionalData [ "me" ] = new PlannerAssignment ( )
270+ {
271+ OrderHint = " !"
272+ } ;
241273
242274 PlannerTask middleTask = await graphClient . Planner . Tasks . PostAsync ( taskToCreate ) ;
243275
@@ -247,43 +279,49 @@ public async Task PlannerTaskAssignedToTaskBoardFormatUpdate()
247279 var myUserId = plannerPlan . CreatedBy . User . Id ;
248280
249281 // get assigned to task board formats of the tasks in plan.
250- var taskIdsWithTaskBoardFormats = await graphClient.Planner.Plans[plannerPlan.Id].Tasks.Request().Select("id").Expand("assignedToTaskBoardFormat").GetAsync();
251- IDictionary<string, PlannerAssignedToTaskBoardTaskFormat> formatsByTasks = taskIdsWithTaskBoardFormats.ToDictionary(item => item.Id, item => item.AssignedToTaskBoardFormat);
282+ var taskIdsWithTaskBoardFormats = await graphClient . Planner . Plans [ plannerPlan . Id ] . Tasks . GetAsync ( requestConfiguration =>
283+ {
284+ requestConfiguration . QueryParameters . Select = new [ ] { "id" } ;
285+ requestConfiguration . QueryParameters . Expand = new [ ] { "assignedToTaskBoardFormat" } ;
286+ } ) ;
287+ IDictionary < string , PlannerAssignedToTaskBoardTaskFormat > formatsByTasks = taskIdsWithTaskBoardFormats . Value . ToDictionary ( item => item . Id , item => item . AssignedToTaskBoardFormat ) ;
252288
253289 var bottomTaskFormatUpdate = new PlannerAssignedToTaskBoardTaskFormat ( ) ;
254290 bottomTaskFormatUpdate . OrderHintsByAssignee = new PlannerOrderHintsByAssignee ( ) ;
255- bottomTaskFormatUpdate.OrderHintsByAssignee[myUserId] = $"{formatsByTasks[topTask.Id].GetOrderHintForAssignee( myUserId) } !"; // after top task.
291+ bottomTaskFormatUpdate . OrderHintsByAssignee . AdditionalData [ myUserId ] = $ "{ formatsByTasks [ topTask . Id ] . OrderHintsByAssignee . AdditionalData [ myUserId ] } !"; // after top task.
256292
257293 var middleTaskFormatUpdate = new PlannerAssignedToTaskBoardTaskFormat ( ) ;
258294 middleTaskFormatUpdate . OrderHintsByAssignee = new PlannerOrderHintsByAssignee ( ) ;
259- middleTaskFormatUpdate.OrderHintsByAssignee[myUserId] = $"{formatsByTasks[topTask.Id].GetOrderHintForAssignee( myUserId) } {bottomTaskFormatUpdate.GetOrderHintForAssignee( myUserId) }!"; // after top task, before bottom task's client side new value.
295+ middleTaskFormatUpdate . OrderHintsByAssignee . AdditionalData [ myUserId ] = $ "{ formatsByTasks [ topTask . Id ] . OrderHintsByAssignee . AdditionalData [ myUserId ] } { bottomTaskFormatUpdate . OrderHintsByAssignee . AdditionalData [ myUserId ] } !"; // after top task, before bottom task's client side new value.
260296
261- string etag = formatsByTasks[bottomTask.Id].GetEtag ();
297+ string etag = formatsByTasks [ bottomTask . Id ] . AdditionalData [ "@odata.etag" ] . ToString ( ) ;
262298 formatsByTasks [ bottomTask . Id ] = await graphClient
263299 . Planner
264300 . Tasks [ bottomTask . Id ]
265301 . AssignedToTaskBoardFormat
266- .Request()
267- .Header("If-Match", etag)
268- .Header("Prefer", "return=representation")
269- .UpdateAsync(bottomTaskFormatUpdate);
302+ . PatchAsync ( bottomTaskFormatUpdate , requestConfiguration =>
303+ {
304+ requestConfiguration . Headers . Add ( "If-Match" , etag ) ;
305+ requestConfiguration . Headers . Add ( "Prefer" , "return=representation" ) ;
306+ } ) ;
270307
271- etag = formatsByTasks[middleTask.Id].GetEtag ();
308+ etag = formatsByTasks [ middleTask . Id ] . AdditionalData [ "@odata.etag" ] . ToString ( ) ;
272309 formatsByTasks [ middleTask . Id ] = await graphClient
273310 . Planner
274311 . Tasks [ middleTask . Id ]
275312 . AssignedToTaskBoardFormat
276- .Request()
277- .Header("If-Match", etag)
278- .Header("Prefer", "return=representation")
279- .UpdateAsync(middleTaskFormatUpdate);
313+ . PatchAsync ( middleTaskFormatUpdate , requestConfiguration =>
314+ {
315+ requestConfiguration . Headers . Add ( "If-Match" , etag ) ;
316+ requestConfiguration . Headers . Add ( "Prefer" , "return=representation" ) ;
317+ } ) ;
280318
281319 // verify final order
282- var orderedTaskFormats = formatsByTasks.OrderBy(kvp => kvp.Value.GetOrderHintForAssignee( myUserId), StringComparer.Ordinal).ToList();
320+ var orderedTaskFormats = formatsByTasks . OrderBy ( kvp => kvp . Value . OrderHintsByAssignee . AdditionalData [ myUserId ] . ToString ( ) , StringComparer . Ordinal ) . ToList ( ) ;
283321 Assert . Equal ( topTask . Id , orderedTaskFormats [ 0 ] . Key ) ;
284322 Assert . Equal ( middleTask . Id , orderedTaskFormats [ 1 ] . Key ) ;
285323 Assert . Equal ( bottomTask . Id , orderedTaskFormats [ 2 ] . Key ) ;
286324 }
287- */
325+
288326 }
289327}
0 commit comments