2323// OTHER DEALINGS IN THE SOFTWARE.
2424#endregion
2525
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 ;
3326using BridgeVs . DynamicVisualizers ;
3427using BridgeVs . DynamicVisualizers . Template ;
3528using BridgeVs . Shared . Common ;
36- using BridgeVs . Shared . FileSystem ;
3729using BridgeVs . Shared . Options ;
3830using BridgeVs . UnitTest . Model ;
3931using 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 ;
4038using TypeMock . ArrangeActAssert ;
39+ using FS = BridgeVs . Shared . FileSystem . FileSystemFactory ;
4140
4241namespace BridgeVs . UnitTest . DynamicVisualizers
4342{
4443 [ TestClass ]
44+ [ Isolated ]
4545 public class DynamicDebuggerVisualizerTest
4646 {
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 > ( ) ) ;
5149 private const string AnonymousListLinqScript = @"
5250 <Query Kind=""Program"">
5351 <Namespace>System</Namespace>
@@ -85,27 +83,43 @@ void Main()
8583 [ ClassInitialize ]
8684 public static void Init ( TestContext ctx )
8785 {
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 ) ;
9592 }
9693
9794 [ TestMethod ]
9895 [ TestCategory ( "UnitTest" ) ]
9996 public void DeployLinqScriptTest ( )
10097 {
10198 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+ {
103112
104113 string dstScriptPath = CommonFolderPaths . DefaultLinqPadQueryFolder ;
114+ string targetFolder = Path . Combine ( dstScriptPath , Message . AssemblyName ) ;
115+ MockFileSystem . AddFile ( Path . Combine ( targetFolder , Message . FileName + ".linq" ) , new MockFileData ( "" ) ) ;
105116
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 ) ;
107121
108- Assert . IsTrue ( _fileSystem . File . Exists ( fileNamePath ) ) ;
122+ Assert . IsTrue ( FS . FileSystem . File . Exists ( fileNamePath + "_1.linq" ) ) ;
109123 }
110124
111125 [ TestMethod ]
@@ -124,7 +138,7 @@ public void InspectionTransformTest_AnonymousType()
124138 Inspection linqQuery = new Inspection ( message ) ;
125139 string linqQueryText = linqQuery . TransformText ( ) ;
126140
127- bool linqIsEqual = CompareNormalisedString ( linqQueryText , linqToCompare ) ;
141+ bool linqIsEqual = CompareNormalizedString ( linqQueryText , linqToCompare ) ;
128142 Assert . IsTrue ( linqIsEqual ) ;
129143 }
130144
@@ -141,11 +155,11 @@ public void InspectionTransformTest_StrongType()
141155 Inspection linqQuery = new Inspection ( message ) ;
142156 string linqQueryText = linqQuery . TransformText ( ) ;
143157
144- bool linqIsEqual = CompareNormalisedString ( linqQueryText , linqToCompare ) ;
158+ bool linqIsEqual = CompareNormalizedString ( linqQueryText , linqToCompare ) ;
145159 Assert . IsTrue ( linqIsEqual ) ;
146160 }
147-
148- private static bool CompareNormalisedString ( string str1 , string str2 )
161+
162+ private static bool CompareNormalizedString ( string str1 , string str2 )
149163 {
150164 string normalized1 = Regex . Replace ( str1 , @"\s" , "" ) ;
151165 string normalized2 = Regex . Replace ( str2 , @"\s" , "" ) ;
0 commit comments