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+ }
2123
24+ public async Task DisposeAsync ( )
25+ {
26+ await Client . Pages . UpdateAsync ( _page . Id , new PagesUpdateParameters { Archived = true } ) ;
27+ }
28+
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 ( )
@@ -188,8 +166,7 @@ private static IEnumerable<object[]> BlockData()
188166 } ,
189167 new object [ ]
190168 {
191- new DividerBlock { Divider = new DividerBlock . Data ( ) } ,
192- new DividerUpdateBlock ( ) ,
169+ new DividerBlock { Divider = new DividerBlock . Data ( ) } , new DividerUpdateBlock ( ) ,
193170 new Action < IBlock , INotionClient > ( ( block , client ) =>
194171 {
195172 Assert . NotNull ( block ) ;
@@ -374,7 +351,7 @@ private static IEnumerable<object[]> BlockData()
374351 var linkToPageBlock = Assert . IsType < LinkToPageBlock > ( block ) ;
375352
376353 var pageParent = Assert . IsType < PageParent > ( linkToPageBlock . LinkToPage ) ;
377-
354+
378355 // TODO: Currently the api doesn't allow to update the link_to_page block type
379356 // This will change to updated ID once api start to support
380357 Assert . Equal ( Guid . Parse ( "533578e3edf14c0a91a9da6b09bac3ee" ) , Guid . Parse ( pageParent . PageId ) ) ;
@@ -408,9 +385,9 @@ private static IEnumerable<object[]> BlockData()
408385 var tableBlock = block . Should ( ) . NotBeNull ( ) . And . BeOfType < TableBlock > ( ) . Subject ;
409386 tableBlock . HasChildren . Should ( ) . BeTrue ( ) ;
410387
411- var children = client . Blocks . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest {
412- BlockId = tableBlock . Id
413- } ) . GetAwaiter ( ) . GetResult ( ) ;
388+ var children = client . Blocks
389+ . RetrieveChildrenAsync ( new BlockRetrieveChildrenRequest { BlockId = tableBlock . Id } )
390+ . GetAwaiter ( ) . GetResult ( ) ;
414391
415392 children . Results . Should ( ) . ContainSingle ( )
416393 . Subject . Should ( ) . BeOfType < TableRowBlock > ( )
0 commit comments