8
8
9
9
namespace Notion . IntegrationTests ;
10
10
11
- public class IBlocksClientTests : IntegrationTestBase
11
+ public class IBlocksClientTests : IntegrationTestBase , IAsyncLifetime
12
12
{
13
- [ Fact ]
14
- public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks ( )
13
+ private Page _page = null ! ;
14
+
15
+ public async Task InitializeAsync ( )
15
16
{
16
- var page = await Client . Pages . CreateAsync (
17
+ _page = await Client . Pages . CreateAsync (
17
18
PagesCreateParametersBuilder . Create (
18
19
new ParentPageInput { PageId = ParentPageId }
19
20
) . Build ( )
20
21
) ;
22
+ }
23
+
24
+ public async Task DisposeAsync ( )
25
+ {
26
+ await Client . Pages . UpdateAsync ( _page . Id , new PagesUpdateParameters { Archived = true } ) ;
27
+ }
21
28
29
+ [ Fact ]
30
+ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks ( )
31
+ {
22
32
var blocks = await Client . Blocks . AppendChildrenAsync (
23
33
new BlockAppendChildrenRequest
24
34
{
25
- BlockId = page . Id ,
35
+ BlockId = _page . Id ,
26
36
Children = new List < IBlock >
27
37
{
28
38
new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock . Data ( ) } ,
@@ -43,54 +53,35 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
43
53
) ;
44
54
45
55
blocks . Results . Should ( ) . HaveCount ( 4 ) ;
46
-
47
- // cleanup
48
- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
49
56
}
50
57
51
58
[ Fact ]
52
59
public async Task UpdateBlockAsync_UpdatesGivenBlock ( )
53
60
{
54
- var page = await Client . Pages . CreateAsync (
55
- PagesCreateParametersBuilder . Create (
56
- new ParentPageInput { PageId = ParentPageId }
57
- ) . Build ( )
58
- ) ;
59
-
60
61
var blocks = await Client . Blocks . AppendChildrenAsync (
61
62
new BlockAppendChildrenRequest
62
63
{
63
- BlockId = page . Id ,
64
+ BlockId = _page . Id ,
64
65
Children = new List < IBlock > { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock . Data ( ) } }
65
66
}
66
67
) ;
67
68
68
69
var blockId = blocks . Results . First ( ) . Id ;
69
70
await Client . Blocks . UpdateAsync ( blockId , new BreadcrumbUpdateBlock ( ) ) ;
70
71
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 } ) ;
76
74
77
- // cleanup
78
- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
75
+ updatedBlocks . Results . Should ( ) . HaveCount ( 1 ) ;
79
76
}
80
77
81
78
[ Fact ]
82
79
public async Task DeleteAsync_DeleteBlockWithGivenId ( )
83
80
{
84
- var page = await Client . Pages . CreateAsync (
85
- PagesCreateParametersBuilder . Create (
86
- new ParentPageInput { PageId = ParentPageId }
87
- ) . Build ( )
88
- ) ;
89
-
90
81
var blocks = await Client . Blocks . AppendChildrenAsync (
91
82
new BlockAppendChildrenRequest
92
83
{
93
- BlockId = page . Id ,
84
+ BlockId = _page . Id ,
94
85
Children = new List < IBlock >
95
86
{
96
87
new DividerBlock { Divider = new DividerBlock . Data ( ) } ,
@@ -100,45 +91,32 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
100
91
) ;
101
92
102
93
blocks . Results . Should ( ) . HaveCount ( 2 ) ;
103
-
104
- // cleanup
105
- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
106
94
}
107
95
108
96
[ Theory ]
109
97
[ MemberData ( nameof ( BlockData ) ) ]
110
98
public async Task UpdateAsync_UpdatesGivenBlock (
111
99
IBlock block , IUpdateBlock updateBlock , Action < IBlock , INotionClient > assert )
112
100
{
113
- var page = await Client . Pages . CreateAsync (
114
- PagesCreateParametersBuilder . Create (
115
- new ParentPageInput { PageId = ParentPageId }
116
- ) . Build ( )
117
- ) ;
118
-
119
101
var blocks = await Client . Blocks . AppendChildrenAsync (
120
102
new BlockAppendChildrenRequest
121
103
{
122
- BlockId = page . Id ,
104
+ BlockId = _page . Id ,
123
105
Children = new List < IBlock > { block }
124
106
}
125
107
) ;
126
108
127
109
var blockId = blocks . Results . First ( ) . Id ;
128
110
await Client . Blocks . UpdateAsync ( blockId , updateBlock ) ;
129
111
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
+
134
115
updatedBlocks . Results . Should ( ) . HaveCount ( 1 ) ;
135
116
136
117
var updatedBlock = updatedBlocks . Results . First ( ) ;
137
118
138
119
assert . Invoke ( updatedBlock , Client ) ;
139
-
140
- // cleanup
141
- await Client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters { Archived = true } ) ;
142
120
}
143
121
144
122
private static IEnumerable < object [ ] > BlockData ( )
@@ -169,7 +147,7 @@ private static IEnumerable<object[]> BlockData()
169
147
}
170
148
}
171
149
} ,
172
- new Action < IBlock , INotionClient > ( ( block , client ) =>
150
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
173
151
{
174
152
var updatedBlock = ( BookmarkBlock ) block ;
175
153
Assert . Equal ( "https://github.com/notion-dotnet/notion-sdk-net" , updatedBlock . Bookmark . Url ) ;
@@ -180,20 +158,20 @@ private static IEnumerable<object[]> BlockData()
180
158
{
181
159
new EquationBlock { Equation = new EquationBlock . Info { Expression = "e=mc^3" } } ,
182
160
new EquationUpdateBlock { Equation = new EquationUpdateBlock . Info { Expression = "e=mc^2" } } ,
183
- new Action < IBlock , INotionClient > ( ( block , client ) =>
161
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
184
162
{
185
163
var updatedBlock = ( EquationBlock ) block ;
186
164
Assert . Equal ( "e=mc^2" , updatedBlock . Equation . Expression ) ;
187
165
} )
188
166
} ,
189
167
new object [ ]
190
168
{
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
+ } )
197
175
} ,
198
176
new object [ ]
199
177
{
@@ -217,7 +195,7 @@ private static IEnumerable<object[]> BlockData()
217
195
}
218
196
}
219
197
} ,
220
- new Action < IBlock , INotionClient > ( ( block , client ) =>
198
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
221
199
{
222
200
block . Should ( ) . NotBeNull ( ) ;
223
201
@@ -257,7 +235,7 @@ private static IEnumerable<object[]> BlockData()
257
235
}
258
236
}
259
237
} ,
260
- new Action < IBlock , INotionClient > ( ( block , client ) =>
238
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
261
239
{
262
240
Assert . NotNull ( block ) ;
263
241
var calloutBlock = Assert . IsType < CalloutBlock > ( block ) ;
@@ -287,7 +265,7 @@ private static IEnumerable<object[]> BlockData()
287
265
}
288
266
}
289
267
} ,
290
- new Action < IBlock , INotionClient > ( ( block , client ) =>
268
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
291
269
{
292
270
Assert . NotNull ( block ) ;
293
271
var quoteBlock = Assert . IsType < QuoteBlock > ( block ) ;
@@ -318,7 +296,7 @@ private static IEnumerable<object[]> BlockData()
318
296
}
319
297
}
320
298
} ,
321
- new Action < IBlock , INotionClient > ( ( block , client ) =>
299
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
322
300
{
323
301
Assert . NotNull ( block ) ;
324
302
var imageBlock = Assert . IsType < ImageBlock > ( block ) ;
@@ -344,7 +322,7 @@ private static IEnumerable<object[]> BlockData()
344
322
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
345
323
}
346
324
} ,
347
- new Action < IBlock , INotionClient > ( ( block , client ) =>
325
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
348
326
{
349
327
Assert . NotNull ( block ) ;
350
328
var embedBlock = Assert . IsType < EmbedBlock > ( block ) ;
@@ -354,51 +332,6 @@ private static IEnumerable<object[]> BlockData()
354
332
} )
355
333
} ,
356
334
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 [ ]
402
335
{
403
336
new LinkToPageBlock
404
337
{
@@ -412,13 +345,13 @@ private static IEnumerable<object[]> BlockData()
412
345
{
413
346
LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" }
414
347
} ,
415
- new Action < IBlock , INotionClient > ( ( block , client ) =>
348
+ new Action < IBlock , INotionClient > ( ( block , _ ) =>
416
349
{
417
350
Assert . NotNull ( block ) ;
418
351
var linkToPageBlock = Assert . IsType < LinkToPageBlock > ( block ) ;
419
352
420
353
var pageParent = Assert . IsType < PageParent > ( linkToPageBlock . LinkToPage ) ;
421
-
354
+
422
355
// TODO: Currently the api doesn't allow to update the link_to_page block type
423
356
// This will change to updated ID once api start to support
424
357
Assert . Equal ( Guid . Parse ( "533578e3edf14c0a91a9da6b09bac3ee" ) , Guid . Parse ( pageParent . PageId ) ) ;
@@ -452,9 +385,9 @@ private static IEnumerable<object[]> BlockData()
452
385
var tableBlock = block . Should ( ) . NotBeNull ( ) . And . BeOfType < TableBlock > ( ) . Subject ;
453
386
tableBlock . HasChildren . Should ( ) . BeTrue ( ) ;
454
387
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 ( ) ;
458
391
459
392
children . Results . Should ( ) . ContainSingle ( )
460
393
. Subject . Should ( ) . BeOfType < TableRowBlock > ( )
0 commit comments