@@ -67,4 +67,115 @@ public async Task CreateAsync_CallsRestClientPostAsync_WithCorrectParameters()
6767
6868 _restClientMock . VerifyAll ( ) ;
6969 }
70- }
70+
71+ [ Fact ]
72+ public async Task SendAsync_ThrowsArgumentNullException_WhenRequestIsNull ( )
73+ {
74+ // Act & Assert
75+ var exception = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _fileUploadClient . SendAsync ( null ) ) ;
76+ Assert . Equal ( "sendFileUploadRequest" , exception . ParamName ) ;
77+ Assert . Equal ( "Value cannot be null. (Parameter 'sendFileUploadRequest')" , exception . Message ) ;
78+ }
79+
80+ [ Fact ]
81+ public async Task SendAsync_ThrowsArgumentNullException_WhenFileUploadIdIsNullOrEmpty ( )
82+ {
83+ // Arrange
84+ var request = SendFileUploadRequest . Create ( fileUploadId : null , file : new FileData { FileName = "testfile.txt" , Data = new System . IO . MemoryStream ( ) , ContentType = "text/plain" } ) ;
85+
86+ // Act & Assert
87+ var exception = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _fileUploadClient . SendAsync ( request ) ) ;
88+ Assert . Equal ( "FileUploadId" , exception . ParamName ) ;
89+ Assert . Equal ( "Value cannot be null. (Parameter 'FileUploadId')" , exception . Message ) ;
90+ }
91+
92+ [ Theory ]
93+ [ InlineData ( "0" ) ]
94+ [ InlineData ( "1001" ) ]
95+ [ InlineData ( "-5" ) ]
96+ [ InlineData ( "abc" ) ]
97+ public async Task SendAsync_ThrowsArgumentOutOfRangeException_WhenPartNumberIsInvalid ( string partNumber )
98+ {
99+ // Arrange
100+ var request = SendFileUploadRequest . Create ( fileUploadId : "valid-id" , file : new FileData { FileName = "testfile.txt" , Data = new System . IO . MemoryStream ( ) , ContentType = "text/plain" } , partNumber : partNumber ) ;
101+
102+ // Act & Assert
103+ var exception = await Assert . ThrowsAsync < ArgumentOutOfRangeException > ( ( ) => _fileUploadClient . SendAsync ( request ) ) ;
104+ Assert . Equal ( "PartNumber" , exception . ParamName ) ;
105+ Assert . Contains ( "PartNumber must be between 1 and 1000." , exception . Message ) ;
106+ }
107+
108+ [ Theory ]
109+ [ InlineData ( "1" ) ]
110+ [ InlineData ( "500" ) ]
111+ [ InlineData ( "1000" ) ]
112+ public async Task SendAsync_DoesNotThrow_WhenPartNumberIsValid ( string partNumber )
113+ {
114+ // Arrange
115+ var request = SendFileUploadRequest . Create ( fileUploadId : "valid-id" , file : new FileData { FileName = "testfile.txt" , Data = new System . IO . MemoryStream ( ) , ContentType = "text/plain" } , partNumber : partNumber ) ;
116+
117+ var expectedResponse = new SendFileUploadResponse
118+ {
119+ Id = "valid-id" ,
120+ Status = "uploaded" ,
121+ } ;
122+
123+ _restClientMock
124+ . Setup ( client => client . PostAsync < SendFileUploadResponse > (
125+ It . Is < string > ( url => url == ApiEndpoints . FileUploadsApiUrls . Send ( "valid-id" ) ) ,
126+ It . IsAny < ISendFileUploadFormDataParameters > ( ) ,
127+ It . IsAny < IEnumerable < KeyValuePair < string , string > > > ( ) ,
128+ It . IsAny < IDictionary < string , string > > ( ) ,
129+ It . IsAny < JsonSerializerSettings > ( ) ,
130+ It . IsAny < IBasicAuthenticationParameters > ( ) ,
131+ It . IsAny < CancellationToken > ( ) ) )
132+ . ReturnsAsync ( expectedResponse ) ;
133+
134+ // Act
135+ var exception = await Record . ExceptionAsync ( ( ) => _fileUploadClient . SendAsync ( request ) ) ;
136+
137+ // Assert
138+ Assert . Null ( exception ) ;
139+ _restClientMock . VerifyAll ( ) ;
140+ }
141+
142+ [ Fact ]
143+ public async Task SendAsync_CallsRestClientPostAsync_WithCorrectParameters ( )
144+ {
145+ // Arrange
146+ var fileUploadId = Guid . NewGuid ( ) . ToString ( ) ;
147+ var request = SendFileUploadRequest . Create (
148+ fileUploadId : fileUploadId ,
149+ file : new FileData
150+ {
151+ FileName = "testfile.txt" ,
152+ Data = new System . IO . MemoryStream ( ) ,
153+ ContentType = "text/plain"
154+ }
155+ ) ;
156+
157+ var expectedResponse = new SendFileUploadResponse
158+ {
159+ Id = fileUploadId . ToString ( ) ,
160+ Status = "uploaded" ,
161+ } ;
162+
163+ _restClientMock
164+ . Setup ( client => client . PostAsync < SendFileUploadResponse > (
165+ It . Is < string > ( url => url == ApiEndpoints . FileUploadsApiUrls . Send ( fileUploadId ) ) ,
166+ It . IsAny < ISendFileUploadFormDataParameters > ( ) ,
167+ It . IsAny < IEnumerable < KeyValuePair < string , string > > > ( ) ,
168+ It . IsAny < IDictionary < string , string > > ( ) ,
169+ It . IsAny < JsonSerializerSettings > ( ) ,
170+ It . IsAny < IBasicAuthenticationParameters > ( ) ,
171+ It . IsAny < CancellationToken > ( ) ) )
172+ . ReturnsAsync ( expectedResponse ) ;
173+ // Act
174+ var response = await _fileUploadClient . SendAsync ( request ) ;
175+
176+ // Assert
177+ Assert . Equal ( expectedResponse . Status , response . Status ) ;
178+ Assert . Equal ( expectedResponse . Id , response . Id ) ;
179+ _restClientMock . VerifyAll ( ) ;
180+ }
181+ }
0 commit comments