1616
1717using System ;
1818using System . Collections . Generic ;
19+ using System . IO ;
1920using System . Linq ;
2021using System . Threading . Tasks ;
2122
@@ -32,6 +33,7 @@ public class FilesDownloadTest
3233 private static TestServerProcess ? _server ;
3334 private Client vertexClient ;
3435 private Client geminiClient ;
36+ private string fileUri ;
3537 public TestContext TestContext { get ; set ; }
3638
3739 [ ClassInitialize ]
@@ -76,52 +78,145 @@ public void TestInit()
7678 geminiClient =
7779 new Client ( apiKey : apiKey , vertexAI : false , httpOptions : geminiClientHttpOptions ) ;
7880
81+ // Specific setup for this test class
82+ fileUri = "https://generativelanguage.googleapis.com/v1beta/files/p1crkz5nfru4:download?alt=media" ;
83+
7984 }
8085
8186 [ TestMethod ]
8287 public async Task DownloadFileNameVertexTest ( )
8388 {
84- var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
85- {
86- await vertexClient . Files . DownloadAsync ( fileName : "fileName" ) ;
87- } ) ;
89+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
90+ {
91+ await vertexClient . Files . DownloadAsync ( fileName : "fileName" ) ;
92+ } ) ;
93+
94+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
95+ }
8896
89- StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
97+ [ TestMethod ]
98+ public async Task DownloadFileNameGeminiTest ( )
99+ {
100+ var stream = await geminiClient . Files . DownloadAsync (
101+ fileName : fileUri
102+ ) ;
103+ using ( MemoryStream memoryStream = new MemoryStream ( ) ) {
104+ await stream . CopyToAsync ( memoryStream ) ;
105+ memoryStream . Position = 0 ;
106+ byte [ ] bytes = memoryStream . ToArray ( ) ;
107+ Assert . IsTrue ( bytes . Length > 0 ) ;
108+ }
90109 }
91110
92111 [ TestMethod ]
93112 public async Task DownloadToFileFileNameVertexTest ( )
94113 {
95- var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
96- {
97- await vertexClient . Files . DownloadToFileAsync ( fileName : "fileName" , outputPath : "outputPath" ) ;
98- } ) ;
114+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
115+ {
116+ await vertexClient . Files . DownloadToFileAsync ( fileName : "fileName" , outputPath : "outputPath" ) ;
117+ } ) ;
99118
100- StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
119+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
120+ }
121+
122+ [ TestMethod ]
123+ public async Task DownloadToFileFileNameGeminiTest ( )
124+ {
125+ await geminiClient . Files . DownloadToFileAsync (
126+ fileName : fileUri ,
127+ outputPath : "output.mp4"
128+ ) ;
101129 }
102130
103131 [ TestMethod ]
104132 public async Task DownloadFileVertexTest ( )
105133 {
106- var file = new Google . GenAI . Types . File { Name = "Name" } ;
107- var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
108- {
109- await vertexClient . Files . DownloadAsync ( file : file ) ;
110- } ) ;
134+ var file = new Google . GenAI . Types . File { Name = "Name" } ;
135+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
136+ {
137+ await vertexClient . Files . DownloadAsync ( file : file ) ;
138+ } ) ;
111139
112- StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
140+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
141+ }
142+
143+ [ TestMethod ]
144+ public async Task DownloadFileGeminiTest ( )
145+ {
146+ var file = new Google . GenAI . Types . File {
147+ Name = fileUri
148+ } ;
149+ await geminiClient . Files . DownloadAsync ( file : file ) ;
113150 }
114151
115152 [ TestMethod ]
116153 public async Task DownloadToFileFileVertexTest ( )
117154 {
118- var file = new Google . GenAI . Types . File { Name = "Name" } ;
119- var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
120- {
121- await vertexClient . Files . DownloadToFileAsync ( file : file , outputPath : "outputPath" ) ;
122- } ) ;
155+ var file = new Google . GenAI . Types . File { Name = "Name" } ;
156+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
157+ {
158+ await vertexClient . Files . DownloadToFileAsync ( file : file , outputPath : "outputPath" ) ;
159+ } ) ;
160+
161+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
162+ }
163+
164+ [ TestMethod ]
165+ public async Task DownloadToFileFileGeminiTest ( )
166+ {
167+ var file = new Google . GenAI . Types . File {
168+ Name = fileUri
169+ } ;
170+ await geminiClient . Files . DownloadToFileAsync ( file : file , outputPath : "output.mp4" ) ;
171+ }
123172
124- StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
173+ [ TestMethod ]
174+ public async Task DownloadToFileVideoVertexTest ( )
175+ {
176+ var video = new Google . GenAI . Types . Video {
177+ Uri = fileUri
178+ } ;
179+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
180+ {
181+ await vertexClient . Files . DownloadToFileAsync ( video : video , outputPath : "outputPath" ) ;
182+ } ) ;
183+
184+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
185+ }
186+
187+ [ TestMethod ]
188+ public async Task DownloadToFileVideoGeminiTest ( )
189+ {
190+ var video = new Google . GenAI . Types . Video {
191+ Uri = fileUri
192+ } ;
193+ await geminiClient . Files . DownloadToFileAsync ( video : video , outputPath : "output.mp4" ) ;
194+ }
195+
196+
197+ [ TestMethod ]
198+ public async Task DownloadToFileGeneratedVideoVertexTest ( )
199+ {
200+ var video = new Google . GenAI . Types . Video {
201+ Uri = fileUri
202+ } ;
203+ var generatedVideo = new Google . GenAI . Types . GeneratedVideo { Video = video } ;
204+ var ex = await Assert . ThrowsExceptionAsync < NotSupportedException > ( async ( ) =>
205+ {
206+ await vertexClient . Files . DownloadToFileAsync ( generatedVideo : generatedVideo , outputPath : "outputPath" ) ;
207+ } ) ;
208+
209+ StringAssert . Contains ( ex . Message , "This method is only supported in the Gemini Developer API client" ) ;
210+ }
211+
212+ [ TestMethod ]
213+ public async Task DownloadToFileGeneratedVideoGeminiTest ( )
214+ {
215+ var video = new Google . GenAI . Types . Video {
216+ Uri = fileUri
217+ } ;
218+ var generatedVideo = new Google . GenAI . Types . GeneratedVideo { Video = video } ;
219+ await geminiClient . Files . DownloadToFileAsync ( generatedVideo : generatedVideo , outputPath : "output.mp4" ) ;
125220 }
126221
127222}
0 commit comments