33using InertiaCore . Models ;
44using InertiaCore . Utils ;
55using Microsoft . AspNetCore . Builder ;
6+ using Microsoft . AspNetCore . Http ;
7+ using Microsoft . AspNetCore . Mvc ;
68using Microsoft . Extensions . Options ;
79using Moq ;
810
@@ -14,8 +16,6 @@ public partial class Tests
1416 [ Description ( "Test if the Vite configuration registers properly the service." ) ]
1517 public void TestViteConfiguration ( )
1618 {
17- Assert . Throws < NullReferenceException > ( ( ) => Vite . ReactRefresh ( ) ) ;
18-
1919 var builder = WebApplication . CreateBuilder ( ) ;
2020 builder . Services . AddInertia ( ) ;
2121
@@ -72,7 +72,8 @@ public void TestNotHot()
7272 }
7373
7474 [ Test ]
75- [ Description ( "Test if the Vite Helper handles generating HTML tags for both JS and CSS from HMR and the manifest properly." ) ]
75+ [ Description (
76+ "Test if the Vite Helper handles generating HTML tags for both JS and CSS from HMR and the manifest properly." ) ]
7677 public void TestViteInput ( )
7778 {
7879 var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
@@ -209,4 +210,47 @@ public void TestViteFacade()
209210 "<script src=\" http://127.0.0.1:5174/@vite/client\" type=\" module\" ></script>\n \t " +
210211 "<script src=\" http://127.0.0.1:5174/index.scss\" type=\" module\" ></script>\n \t " ) ) ;
211212 }
213+
214+ [ Test ]
215+ [ Description ( "Test if the vite version is read properly." ) ]
216+ public async Task TestViteVersion ( )
217+ {
218+ var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
219+ var options = new Mock < IOptions < ViteOptions > > ( ) ;
220+ options . SetupGet ( x => x . Value ) . Returns ( new ViteOptions ( ) ) ;
221+
222+ var mock = new Mock < ViteBuilder > ( options . Object ) ;
223+ mock . Object . UseFileSystem ( fileSystem ) ;
224+ Vite . UseBuilder ( mock . Object ) ;
225+
226+ fileSystem . AddFile ( @"/wwwroot/build/manifest.json" ,
227+ new MockFileData ( "{\" app.tsx\" : {\" file\" : \" assets/main-19038c6a.js\" }}" ) ) ;
228+
229+ _factory . Version ( Vite . GetManifestHash ) ;
230+
231+ var response = _factory . Render ( "Test/Page" , new
232+ {
233+ Test = "Test"
234+ } ) ;
235+
236+ var headers = new HeaderDictionary
237+ {
238+ { "X-Inertia" , "true" }
239+ } ;
240+
241+ var context = PrepareContext ( headers ) ;
242+
243+ response . SetContext ( context ) ;
244+ await response . ProcessResponse ( ) ;
245+
246+ var result = response . GetResult ( ) ;
247+
248+ Assert . Multiple ( ( ) =>
249+ {
250+ Assert . That ( result , Is . InstanceOf < JsonResult > ( ) ) ;
251+
252+ var json = ( result as JsonResult ) ? . Value ;
253+ Assert . That ( ( json as Page ) ? . Version , Is . EqualTo ( "bba1afd1066309f4a69430e0c446ba8d" ) ) ;
254+ } ) ;
255+ }
212256}
0 commit comments