@@ -247,4 +247,98 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem()
247247
248248 await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
249249 }
250+
251+ [ Fact ]
252+ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothing ( )
253+ {
254+ // Arrange
255+ var databaseCreateRequest = new DatabasesCreateParameters
256+ {
257+ Title =
258+ new List < RichTextBaseInput >
259+ {
260+ new RichTextTextInput ( ) { Text = new Text { Content = "Test Database" } }
261+ } ,
262+ Parent = new ParentPageInput ( ) { PageId = ParentPageId } ,
263+ Properties = new Dictionary < string , IPropertySchema >
264+ {
265+ {
266+ "title" , new TitlePropertySchema
267+ {
268+ Title = new Dictionary < string , object > ( )
269+ }
270+ } ,
271+ {
272+ "Colors1" ,
273+ new SelectPropertySchema
274+ {
275+ Select = new OptionWrapper < SelectOptionSchema >
276+ {
277+ Options = new List < SelectOptionSchema >
278+ {
279+ new ( ) { Name = "Red" } ,
280+ new ( ) { Name = "Green" } ,
281+ new ( ) { Name = "Blue" }
282+ }
283+ }
284+ }
285+ } ,
286+ {
287+ "Colors2" ,
288+ new SelectPropertySchema
289+ {
290+ Select = new OptionWrapper < SelectOptionSchema >
291+ {
292+ Options = new List < SelectOptionSchema >
293+ {
294+ new ( ) { Name = "Red" } ,
295+ new ( ) { Name = "Green" } ,
296+ new ( ) { Name = "Blue" }
297+ }
298+ }
299+ }
300+ } ,
301+ }
302+ } ;
303+
304+ var database = await Client . Databases . CreateAsync ( databaseCreateRequest ) ;
305+
306+ var pagesCreateParameters = PagesCreateParametersBuilder
307+ . Create ( new DatabaseParentInput { DatabaseId = database . Id } )
308+ . AddProperty ( "title" ,
309+ new TitlePropertyValue
310+ {
311+ Title = new List < RichTextBase >
312+ {
313+ new RichTextTextInput { Text = new Text { Content = "Test" } }
314+ }
315+ } )
316+ . AddProperty ( "Colors1" , new SelectPropertyValue { Select = new SelectOption { Name = "Red" } } )
317+ . AddProperty ( "Colors2" , new SelectPropertyValue { Select = new SelectOption { Name = "Green" } } )
318+ . Build ( ) ;
319+
320+ // Act
321+ var page = await Client . Pages . CreateAsync ( pagesCreateParameters ) ;
322+
323+ var updatePageRequest = new PagesUpdateParameters
324+ {
325+ Properties = new Dictionary < string , PropertyValue >
326+ {
327+ { "Colors1" , new SelectPropertyValue { Select = new SelectOption { Name = "Blue" } } } ,
328+ { "Colors2" , new SelectPropertyValue { Select = null } }
329+ }
330+ } ;
331+
332+ var updatedPage = await Client . Pages . UpdateAsync ( page . Id , updatePageRequest ) ;
333+
334+ // Assert
335+ page . Properties [ "Colors1" ] . As < SelectPropertyValue > ( ) . Select . Name . Should ( ) . Be ( "Red" ) ;
336+ page . Properties [ "Colors2" ] . As < SelectPropertyValue > ( ) . Select . Name . Should ( ) . Be ( "Green" ) ;
337+
338+ updatedPage . Properties [ "Colors1" ] . As < SelectPropertyValue > ( ) . Select . Name . Should ( ) . Be ( "Blue" ) ;
339+ updatedPage . Properties [ "Colors2" ] . As < SelectPropertyValue > ( ) . Select . Should ( ) . BeNull ( ) ;
340+
341+ await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
342+ await Client . Databases . UpdateAsync ( database . Id , new DatabasesUpdateParameters { Archived = true } ) ;
343+ }
250344}
0 commit comments