1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+ using Moq ;
6+ using Moq . AutoMock ;
7+ using Newtonsoft . Json ;
8+ using Notion . Client ;
9+ using Xunit ;
10+
11+ namespace Notion . UnitTests ;
12+
13+ public class FileUploadClientTests
14+ {
15+ private readonly AutoMocker _mocker = new ( ) ;
16+ private readonly FileUploadsClient _fileUploadClient ;
17+ private readonly Mock < IRestClient > _restClientMock ;
18+
19+ public FileUploadClientTests ( )
20+ {
21+ _restClientMock = _mocker . GetMock < IRestClient > ( ) ;
22+ _fileUploadClient = _mocker . CreateInstance < FileUploadsClient > ( ) ;
23+ }
24+
25+ [ Fact ]
26+ public async Task CreateAsync_ThrowsArgumentNullException_WhenRequestIsNull ( )
27+ {
28+ // Act & Assert
29+ var exception = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _fileUploadClient . CreateAsync ( null ) ) ;
30+ Assert . Equal ( "fileUploadObjectRequest" , exception . ParamName ) ;
31+ Assert . Equal ( "Value cannot be null. (Parameter 'fileUploadObjectRequest')" , exception . Message ) ;
32+ }
33+
34+ [ Fact ]
35+ public async Task CreateAsync_CallsRestClientPostAsync_WithCorrectParameters ( )
36+ {
37+ // Arrange
38+ var request = new CreateFileUploadRequest
39+ {
40+ FileName = "testfile.txt" ,
41+ Mode = FileUploadMode . SinglePart ,
42+ } ;
43+
44+ var expectedResponse = new CreateFileUploadResponse
45+ {
46+ UploadUrl = "https://example.com/upload" ,
47+ Id = Guid . NewGuid ( ) . ToString ( ) ,
48+ } ;
49+
50+ _restClientMock
51+ . Setup ( client => client . PostAsync < CreateFileUploadResponse > (
52+ It . Is < string > ( url => url == ApiEndpoints . FileUploadsApiUrls . Create ( ) ) ,
53+ It . IsAny < ICreateFileUploadBodyParameters > ( ) ,
54+ It . IsAny < IEnumerable < KeyValuePair < string , string > > > ( ) ,
55+ It . IsAny < IDictionary < string , string > > ( ) ,
56+ It . IsAny < JsonSerializerSettings > ( ) ,
57+ It . IsAny < IBasicAuthenticationParameters > ( ) ,
58+ It . IsAny < CancellationToken > ( ) ) )
59+ . ReturnsAsync ( expectedResponse ) ;
60+
61+ // Act
62+ var response = await _fileUploadClient . CreateAsync ( request ) ;
63+
64+ // Assert
65+ Assert . Equal ( expectedResponse . UploadUrl , response . UploadUrl ) ;
66+ Assert . Equal ( expectedResponse . Id , response . Id ) ;
67+
68+ _restClientMock . VerifyAll ( ) ;
69+ }
70+ }
0 commit comments