23
23
// OTHER DEALINGS IN THE SOFTWARE.
24
24
#endregion
25
25
26
- using System ;
27
- using System . Collections . Generic ;
28
- using System . IO ;
29
- using System . IO . Abstractions ;
30
- using System . IO . Abstractions . TestingHelpers ;
31
- using System . Linq ;
32
- using System . Text . RegularExpressions ;
33
26
using BridgeVs . DynamicVisualizers ;
34
27
using BridgeVs . DynamicVisualizers . Template ;
35
28
using BridgeVs . Shared . Common ;
36
- using BridgeVs . Shared . FileSystem ;
37
29
using BridgeVs . Shared . Options ;
38
30
using BridgeVs . UnitTest . Model ;
39
31
using Microsoft . VisualStudio . TestTools . UnitTesting ;
32
+ using System ;
33
+ using System . Collections . Generic ;
34
+ using System . IO ;
35
+ using System . IO . Abstractions . TestingHelpers ;
36
+ using System . Linq ;
37
+ using System . Text . RegularExpressions ;
40
38
using TypeMock . ArrangeActAssert ;
39
+ using FS = BridgeVs . Shared . FileSystem . FileSystemFactory ;
41
40
42
41
namespace BridgeVs . UnitTest . DynamicVisualizers
43
42
{
44
43
[ TestClass ]
44
+ [ Isolated ]
45
45
public class DynamicDebuggerVisualizerTest
46
46
{
47
- private readonly Message _message = new Message ( Guid . NewGuid ( ) . ToString ( ) , SerializationOption . BinarySerializer , typeof ( CustomType1 ) ) ;
48
-
49
- private static IFileSystem _fileSystem ;
50
-
47
+ private static readonly Message Message = new Message ( Guid . NewGuid ( ) . ToString ( ) , SerializationOption . BinarySerializer , typeof ( CustomType1 ) ) ;
48
+ private static readonly MockFileSystem MockFileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
51
49
private const string AnonymousListLinqScript = @"
52
50
<Query Kind=""Program"">
53
51
<Namespace>System</Namespace>
@@ -85,27 +83,43 @@ void Main()
85
83
[ ClassInitialize ]
86
84
public static void Init ( TestContext ctx )
87
85
{
88
- _fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData >
89
- {
90
- { @"c:\myfile.txt" , new MockFileData ( "Testing is meh." ) } ,
91
- { @"c:\demo\jQuery.js" , new MockFileData ( "some js" ) } ,
92
- { @"c:\demo\image.gif" , new MockFileData ( new byte [ ] { 0x12 , 0x34 , 0x56 , 0xd2 } ) }
93
- } ) ;
94
- Isolate . WhenCalled ( ( ) => FileSystemFactory . FileSystem ) . WillReturn ( _fileSystem ) ;
86
+ string dstScriptPath = CommonFolderPaths . DefaultLinqPadQueryFolder ;
87
+
88
+ string targetFolder = Path . Combine ( dstScriptPath , Message . AssemblyName ) ;
89
+ MockFileSystem . AddDirectory ( targetFolder ) ;
90
+
91
+ Isolate . WhenCalled ( ( ) => FS . FileSystem ) . WillReturn ( MockFileSystem ) ;
95
92
}
96
93
97
94
[ TestMethod ]
98
95
[ TestCategory ( "UnitTest" ) ]
99
96
public void DeployLinqScriptTest ( )
100
97
{
101
98
DynamicDebuggerVisualizer cVisualizerObjectSource = new DynamicDebuggerVisualizer ( ) ;
102
- cVisualizerObjectSource . DeployLinqScript ( _message , "15.0" ) ;
99
+ cVisualizerObjectSource . DeployLinqScript ( Message , "15.0" ) ;
100
+
101
+ string dstScriptPath = CommonFolderPaths . DefaultLinqPadQueryFolder ;
102
+
103
+ string fileNamePath = Path . Combine ( dstScriptPath , Message . AssemblyName , Message . FileName ) ;
104
+
105
+ Assert . IsTrue ( FS . FileSystem . File . Exists ( fileNamePath + ".linq" ) ) ;
106
+ }
107
+
108
+ [ TestMethod ]
109
+ [ TestCategory ( "UnitTest" ) ]
110
+ public void DeployLinqScriptTest_Duplicate ( )
111
+ {
103
112
104
113
string dstScriptPath = CommonFolderPaths . DefaultLinqPadQueryFolder ;
114
+ string targetFolder = Path . Combine ( dstScriptPath , Message . AssemblyName ) ;
115
+ MockFileSystem . AddFile ( Path . Combine ( targetFolder , Message . FileName + ".linq" ) , new MockFileData ( "" ) ) ;
105
116
106
- string fileNamePath = Path . Combine ( dstScriptPath , _message . AssemblyName , _message . FileName ) ;
117
+ DynamicDebuggerVisualizer cVisualizerObjectSource = new DynamicDebuggerVisualizer ( ) ;
118
+ cVisualizerObjectSource . DeployLinqScript ( Message , "15.0" ) ;
119
+
120
+ string fileNamePath = Path . Combine ( dstScriptPath , Message . AssemblyName , Message . FileName ) ;
107
121
108
- Assert . IsTrue ( _fileSystem . File . Exists ( fileNamePath ) ) ;
122
+ Assert . IsTrue ( FS . FileSystem . File . Exists ( fileNamePath + "_1.linq" ) ) ;
109
123
}
110
124
111
125
[ TestMethod ]
@@ -124,7 +138,7 @@ public void InspectionTransformTest_AnonymousType()
124
138
Inspection linqQuery = new Inspection ( message ) ;
125
139
string linqQueryText = linqQuery . TransformText ( ) ;
126
140
127
- bool linqIsEqual = CompareNormalisedString ( linqQueryText , linqToCompare ) ;
141
+ bool linqIsEqual = CompareNormalizedString ( linqQueryText , linqToCompare ) ;
128
142
Assert . IsTrue ( linqIsEqual ) ;
129
143
}
130
144
@@ -141,11 +155,11 @@ public void InspectionTransformTest_StrongType()
141
155
Inspection linqQuery = new Inspection ( message ) ;
142
156
string linqQueryText = linqQuery . TransformText ( ) ;
143
157
144
- bool linqIsEqual = CompareNormalisedString ( linqQueryText , linqToCompare ) ;
158
+ bool linqIsEqual = CompareNormalizedString ( linqQueryText , linqToCompare ) ;
145
159
Assert . IsTrue ( linqIsEqual ) ;
146
160
}
147
-
148
- private static bool CompareNormalisedString ( string str1 , string str2 )
161
+
162
+ private static bool CompareNormalizedString ( string str1 , string str2 )
149
163
{
150
164
string normalized1 = Regex . Replace ( str1 , @"\s" , "" ) ;
151
165
string normalized2 = Regex . Replace ( str2 , @"\s" , "" ) ;
0 commit comments