88
99namespace Notion . IntegrationTests ;
1010
11- public class IBlocksClientTests : IntegrationTestBase
11+ public class IBlocksClientTests : IntegrationTestBase , IAsyncLifetime
1212{
13- [ Fact ]
14- public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks ( )
13+ private Page _page = null ! ;
14+
15+ public async Task InitializeAsync ( )
1516 {
16- var page = await Client . Pages . CreateAsync (
17+ _page = await Client . Pages . CreateAsync (
1718 PagesCreateParametersBuilder . Create (
1819 new ParentPageInput { PageId = ParentPageId }
1920 ) . Build ( )
2021 ) ;
22+ }
23+
24+ public async Task DisposeAsync ( )
25+ {
26+ await Client . Pages . UpdateAsync ( _page . Id , new PagesUpdateParameters { Archived = true } ) ;
27+ }
2128
29+ [ Fact ]
30+ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks ( )
31+ {
2232 var blocks = await Client . Blocks . AppendChildrenAsync (
2333 new BlockAppendChildrenRequest
2434 {
25- BlockId = page . Id ,
35+ BlockId = _page . Id ,
2636 Children = new List < IBlock >
2737 {
2838 new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock . Data ( ) } ,
@@ -43,54 +53,35 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
4353 ) ;
4454
4555 blocks . Results . Should ( ) . HaveCount ( 4 ) ;
46-
47- // cleanup
48- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
4956 }
5057
5158 [ Fact ]
5259 public async Task UpdateBlockAsync_UpdatesGivenBlock ( )
5360 {
54- var page = await Client . Pages . CreateAsync (
55- PagesCreateParametersBuilder . Create (
56- new ParentPageInput { PageId = ParentPageId }
57- ) . Build ( )
58- ) ;
59-
6061 var blocks = await Client . Blocks . AppendChildrenAsync (
6162 new BlockAppendChildrenRequest
6263 {
63- BlockId = page . Id ,
64+ BlockId = _page . Id ,
6465 Children = new List < IBlock > { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock . Data ( ) } }
6566 }
6667 ) ;
6768
6869 var blockId = blocks . Results . First ( ) . Id ;
6970 await Client . Blocks . UpdateAsync ( blockId , new BreadcrumbUpdateBlock ( ) ) ;
7071
71- var updatedBlocks = await Client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest
72- {
73- BlockId = page . Id
74- } ) ;
75- updatedBlocks . Results . Should ( ) . HaveCount ( 1 ) ;
72+ var updatedBlocks =
73+ await Client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest { BlockId = _page . Id } ) ;
7674
77- // cleanup
78- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
75+ updatedBlocks . Results . Should ( ) . HaveCount ( 1 ) ;
7976 }
8077
8178 [ Fact ]
8279 public async Task DeleteAsync_DeleteBlockWithGivenId ( )
8380 {
84- var page = await Client . Pages . CreateAsync (
85- PagesCreateParametersBuilder . Create (
86- new ParentPageInput { PageId = ParentPageId }
87- ) . Build ( )
88- ) ;
89-
9081 var blocks = await Client . Blocks . AppendChildrenAsync (
9182 new BlockAppendChildrenRequest
9283 {
93- BlockId = page . Id ,
84+ BlockId = _page . Id ,
9485 Children = new List < IBlock >
9586 {
9687 new DividerBlock { Divider = new DividerBlock . Data ( ) } ,
@@ -100,45 +91,32 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
10091 ) ;
10192
10293 blocks . Results . Should ( ) . HaveCount ( 2 ) ;
103-
104- // cleanup
105- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
10694 }
10795
10896 [ Theory ]
10997 [ MemberData ( nameof ( BlockData ) ) ]
11098 public async Task UpdateAsync_UpdatesGivenBlock (
11199 IBlock block , IUpdateBlock updateBlock , Action < IBlock , INotionClient > assert )
112100 {
113- var page = await Client . Pages . CreateAsync (
114- PagesCreateParametersBuilder . Create (
115- new ParentPageInput { PageId = ParentPageId }
116- ) . Build ( )
117- ) ;
118-
119101 var blocks = await Client . Blocks . AppendChildrenAsync (
120102 new BlockAppendChildrenRequest
121103 {
122- BlockId = page . Id ,
104+ BlockId = _page . Id ,
123105 Children = new List < IBlock > { block }
124106 }
125107 ) ;
126108
127109 var blockId = blocks . Results . First ( ) . Id ;
128110 await Client . Blocks . UpdateAsync ( blockId , updateBlock ) ;
129111
130- var updatedBlocks = await Client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest
131- {
132- BlockId = page . Id
133- } ) ;
112+ var updatedBlocks =
113+ await Client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest { BlockId = _page . Id } ) ;
114+
134115 updatedBlocks . Results . Should ( ) . HaveCount ( 1 ) ;
135116
136117 var updatedBlock = updatedBlocks . Results . First ( ) ;
137118
138119 assert . Invoke ( updatedBlock , Client ) ;
139-
140- // cleanup
141- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
142120 }
143121
144122 private static IEnumerable < object [ ] > BlockData ( )
@@ -169,7 +147,7 @@ private static IEnumerable<object[]> BlockData()
169147 }
170148 }
171149 } ,
172- new Action < IBlock , INotionClient > ( ( block , client ) =>
150+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
173151 {
174152 var updatedBlock = ( BookmarkBlock ) block ;
175153 Assert . Equal ( "https://github.com/notion-dotnet/notion-sdk-net" , updatedBlock . Bookmark . Url ) ;
@@ -180,20 +158,20 @@ private static IEnumerable<object[]> BlockData()
180158 {
181159 new EquationBlock { Equation = new EquationBlock . Info { Expression = "e=mc^3" } } ,
182160 new EquationUpdateBlock { Equation = new EquationUpdateBlock . Info { Expression = "e=mc^2" } } ,
183- new Action < IBlock , INotionClient > ( ( block , client ) =>
161+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
184162 {
185163 var updatedBlock = ( EquationBlock ) block ;
186164 Assert . Equal ( "e=mc^2" , updatedBlock . Equation . Expression ) ;
187165 } )
188166 } ,
189167 new object [ ]
190168 {
191- new DividerBlock { Divider = new DividerBlock . Data ( ) } , new DividerUpdateBlock ( ) , new Action < IBlock > (
192- block =>
193- {
194- Assert . NotNull ( block ) ;
195- _ = Assert . IsType < DividerBlock > ( block ) ;
196- } )
169+ new DividerBlock { Divider = new DividerBlock . Data ( ) } , new DividerUpdateBlock ( ) ,
170+ new Action < IBlock , INotionClient > ( ( block , client ) =>
171+ {
172+ Assert . NotNull ( block ) ;
173+ _ = Assert . IsType < DividerBlock > ( block ) ;
174+ } )
197175 } ,
198176 new object [ ]
199177 {
@@ -217,7 +195,7 @@ private static IEnumerable<object[]> BlockData()
217195 }
218196 }
219197 } ,
220- new Action < IBlock , INotionClient > ( ( block , client ) =>
198+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
221199 {
222200 block . Should ( ) . NotBeNull ( ) ;
223201
@@ -257,7 +235,7 @@ private static IEnumerable<object[]> BlockData()
257235 }
258236 }
259237 } ,
260- new Action < IBlock , INotionClient > ( ( block , client ) =>
238+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
261239 {
262240 Assert . NotNull ( block ) ;
263241 var calloutBlock = Assert . IsType < CalloutBlock > ( block ) ;
@@ -287,7 +265,7 @@ private static IEnumerable<object[]> BlockData()
287265 }
288266 }
289267 } ,
290- new Action < IBlock , INotionClient > ( ( block , client ) =>
268+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
291269 {
292270 Assert . NotNull ( block ) ;
293271 var quoteBlock = Assert . IsType < QuoteBlock > ( block ) ;
@@ -318,7 +296,7 @@ private static IEnumerable<object[]> BlockData()
318296 }
319297 }
320298 } ,
321- new Action < IBlock , INotionClient > ( ( block , client ) =>
299+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
322300 {
323301 Assert . NotNull ( block ) ;
324302 var imageBlock = Assert . IsType < ImageBlock > ( block ) ;
@@ -344,7 +322,7 @@ private static IEnumerable<object[]> BlockData()
344322 Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
345323 }
346324 } ,
347- new Action < IBlock , INotionClient > ( ( block , client ) =>
325+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
348326 {
349327 Assert . NotNull ( block ) ;
350328 var embedBlock = Assert . IsType < EmbedBlock > ( block ) ;
@@ -354,51 +332,6 @@ private static IEnumerable<object[]> BlockData()
354332 } )
355333 } ,
356334 new object [ ]
357- {
358- new TemplateBlock
359- {
360- Template = new TemplateBlock . Data
361- {
362- RichText = new List < RichTextBase >
363- {
364- new RichTextText { Text = new Text { Content = "Test Template" } }
365- } ,
366- Children = new List < ITemplateChildrenBlock >
367- {
368- new EmbedBlock
369- {
370- Embed = new EmbedBlock . Info
371- {
372- Url
373- = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg"
374- }
375- }
376- }
377- }
378- } ,
379- new TemplateUpdateBlock
380- {
381- Template = new TemplateUpdateBlock . Info
382- {
383- RichText = new List < RichTextBaseInput >
384- {
385- new RichTextTextInput { Text = new Text { Content = "Test Template 2" } }
386- }
387- }
388- } ,
389- new Action < IBlock , INotionClient > ( ( block , client ) =>
390- {
391- Assert . NotNull ( block ) ;
392- var templateBlock = Assert . IsType < TemplateBlock > ( block ) ;
393-
394- Assert . Single ( templateBlock . Template . RichText ) ;
395- Assert . Null ( templateBlock . Template . Children ) ;
396-
397- Assert . Equal ( "Test Template 2" ,
398- templateBlock . Template . RichText . OfType < RichTextText > ( ) . First ( ) . Text . Content ) ;
399- } )
400- } ,
401- new object [ ]
402335 {
403336 new LinkToPageBlock
404337 {
@@ -412,13 +345,13 @@ private static IEnumerable<object[]> BlockData()
412345 {
413346 LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" }
414347 } ,
415- new Action < IBlock , INotionClient > ( ( block , client ) =>
348+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
416349 {
417350 Assert . NotNull ( block ) ;
418351 var linkToPageBlock = Assert . IsType < LinkToPageBlock > ( block ) ;
419352
420353 var pageParent = Assert . IsType < PageParent > ( linkToPageBlock . LinkToPage ) ;
421-
354+
422355 // TODO: Currently the api doesn't allow to update the link_to_page block type
423356 // This will change to updated ID once api start to support
424357 Assert . Equal ( Guid . Parse ( "533578e3edf14c0a91a9da6b09bac3ee" ) , Guid . Parse ( pageParent . PageId ) ) ;
@@ -452,9 +385,9 @@ private static IEnumerable<object[]> BlockData()
452385 var tableBlock = block . Should ( ) . NotBeNull ( ) . And . BeOfType < TableBlock > ( ) . Subject ;
453386 tableBlock . HasChildren . Should ( ) . BeTrue ( ) ;
454387
455- var children = client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest {
456- BlockId = tableBlock . Id
457- } ) . GetAwaiter ( ) . GetResult ( ) ;
388+ var children = client . Blocks
389+ . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest { BlockId = tableBlock . Id } )
390+ . GetAwaiter ( ) . GetResult ( ) ;
458391
459392 children . Results . Should ( ) . ContainSingle ( )
460393 . Subject . Should ( ) . BeOfType < TableRowBlock > ( )
0 commit comments