3
3
using InertiaCore . Models ;
4
4
using InertiaCore . Utils ;
5
5
using Microsoft . AspNetCore . Builder ;
6
+ using Microsoft . AspNetCore . Http ;
7
+ using Microsoft . AspNetCore . Mvc ;
6
8
using Microsoft . Extensions . Options ;
7
9
using Moq ;
8
10
@@ -14,8 +16,6 @@ public partial class Tests
14
16
[ Description ( "Test if the Vite configuration registers properly the service." ) ]
15
17
public void TestViteConfiguration ( )
16
18
{
17
- Assert . Throws < NullReferenceException > ( ( ) => Vite . ReactRefresh ( ) ) ;
18
-
19
19
var builder = WebApplication . CreateBuilder ( ) ;
20
20
builder . Services . AddInertia ( ) ;
21
21
@@ -72,7 +72,8 @@ public void TestNotHot()
72
72
}
73
73
74
74
[ 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." ) ]
76
77
public void TestViteInput ( )
77
78
{
78
79
var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
@@ -209,4 +210,47 @@ public void TestViteFacade()
209
210
"<script src=\" http://127.0.0.1:5174/@vite/client\" type=\" module\" ></script>\n \t " +
210
211
"<script src=\" http://127.0.0.1:5174/index.scss\" type=\" module\" ></script>\n \t " ) ) ;
211
212
}
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
+ }
212
256
}
0 commit comments