1
+ using System . Collections . Generic ;
2
+ using System . IO ;
3
+ using MiniMe . JavaScript ;
4
+ using MiniMe . Test . Common ;
5
+ using NUnit . Framework ;
6
+ using Rhino . Mocks ;
7
+
8
+ namespace MiniMe . Test . JavaScript
9
+ {
10
+ [ TestFixture ]
11
+ public class MiniJavaScriptBuilderTester : BaseBuilderTester
12
+ {
13
+ [ Test ]
14
+ public void Render_OutputsTag_ReturnesCorrectTag ( )
15
+ {
16
+ const string jsPath = "/Content/test.js" ,
17
+ cssUnversionedRelativePath = "/content/site_#.js" ,
18
+ tag = "<script src=\" /Content/test.js\" ></script>\r \n " ;
19
+
20
+ HttpRequest . Stub ( r => r . IsLocal ) . Return ( false ) ;
21
+ HttpContext . Stub ( c => c . IsDebuggingEnabled ) . Return ( true ) ;
22
+
23
+
24
+ var subject = new MiniJavaScriptBuilder ( HttpContext , new Mini ( ) , FileSystem , new CacheMock ( ) ) ;
25
+ var result = subject . Add ( jsPath ) . Render ( cssUnversionedRelativePath ) ;
26
+ Assert . That ( result , Is . EqualTo ( tag ) ) ;
27
+ }
28
+
29
+ [ Test ]
30
+ public void Render_WritesCombinedFile_FileIsWritten ( )
31
+ {
32
+ const string jsPath = "/Content/test.js" ,
33
+ jsUnversionedRelativePath = "/Content/site_#.js" ,
34
+ jsVersionedRelativePath = "/Content/site_92223734.js" ,
35
+ jsVersionedFullPath = "c:\\ Content/site_92223734.js" ,
36
+ fileContent = "Hmm" ;
37
+
38
+ HttpRequest . Stub ( r => r . IsLocal ) . Return ( false ) ;
39
+ HttpContext . Stub ( c => c . IsDebuggingEnabled ) . Return ( false ) ;
40
+
41
+ Server . Stub ( s => s . MapPath ( jsVersionedRelativePath ) ) . Return ( jsVersionedFullPath ) ;
42
+
43
+ FileSystem . Stub ( f => f . GetExistingFiles ( new List < string > ( ) ) )
44
+ . Return ( new FileInfo [ ] { new FileInfo ( jsPath ) } ) . IgnoreArguments ( ) ;
45
+
46
+ FileSystem . Stub ( f => f . ReadAllText ( "" ) ) . Return ( fileContent ) . IgnoreArguments ( ) ;
47
+
48
+ var subject = new MiniJavaScriptBuilder ( HttpContext , new Mini ( FileSystem ) , FileSystem , new CacheMock ( ) ) ;
49
+ subject . ReRenders . Always ( ) . Add ( jsPath ) . Render ( jsUnversionedRelativePath ) ;
50
+ FileSystem . AssertWasCalled ( f => f . WriteAllText ( jsVersionedFullPath , fileContent + ";\r \n " ) ) ;
51
+ }
52
+
53
+ [ Test ]
54
+ public void Render_SameInputDifferentOutput_RendersBothOutputs ( )
55
+ {
56
+ const string jsPath = "/Content/test.js" ,
57
+ outputFile1 = "/Content/#/js1.js" ,
58
+ outputFile2 = "/Content/#/js2.js" ,
59
+ jsVersionedRelativePath1 = "/Content/92223734/js1.js" ,
60
+ jsVersionedFullPath1 = "c:\\ Content/92223734/js1.js" ,
61
+ jsVersionedRelativePath2 = "/Content/92223734/js2.js" ,
62
+ jsVersionedFullPath2 = "c:\\ Content/92223734/js2.js" ,
63
+ fileContent = "Hmm" ;
64
+
65
+ HttpRequest . Stub ( r => r . IsLocal ) . Return ( false ) ;
66
+ HttpContext . Stub ( c => c . IsDebuggingEnabled ) . Return ( false ) ;
67
+
68
+ Server . Stub ( s => s . MapPath ( jsVersionedRelativePath1 ) ) . Return ( jsVersionedFullPath1 ) ;
69
+ Server . Stub ( s => s . MapPath ( jsVersionedRelativePath2 ) ) . Return ( jsVersionedFullPath2 ) ;
70
+
71
+ FileSystem . Stub ( f => f . GetExistingFiles ( new List < string > ( ) ) )
72
+ . Return ( new FileInfo [ ] { new FileInfo ( jsPath ) } ) . IgnoreArguments ( ) ;
73
+
74
+ FileSystem . Stub ( f => f . ReadAllText ( "" ) ) . Return ( fileContent ) . IgnoreArguments ( ) ;
75
+
76
+ var subject = new MiniJavaScriptBuilder ( HttpContext , new Mini ( FileSystem ) , FileSystem , new CacheMock ( ) ) ;
77
+ subject . ReRenders . Never ( ) . Add ( jsPath ) . Render ( outputFile1 ) ;
78
+ subject . ReRenders . Never ( ) . Add ( jsPath ) . Render ( outputFile2 ) ;
79
+
80
+
81
+ FileSystem . AssertWasCalled ( f => f . WriteAllText ( jsVersionedFullPath1 , fileContent + ";\r \n " ) ) ;
82
+ FileSystem . AssertWasCalled ( f => f . WriteAllText ( jsVersionedFullPath2 , fileContent + ";\r \n " ) ) ;
83
+ }
84
+ }
85
+ }
0 commit comments