Skip to content

Commit 10e7f81

Browse files
changes the generation logif for linq scripts
1 parent f60d507 commit 10e7f81

File tree

3 files changed

+48
-41
lines changed

3 files changed

+48
-41
lines changed

Src/BridgeVs.DynamicVisualizers/DynamicDebuggerVisualizer.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ internal void DeployLinqScript(Message message, string vsVersion)
7070
FS.FileSystem.Directory.CreateDirectory(targetFolder);
7171

7272
string fileName = FindAvailableFileName(targetFolder, message.FileName);
73-
74-
string linqPadScriptFilePath = Path.Combine(targetFolder, message.FileName);
75-
Log.Write("linqPadScriptPath: {0}", linqPadScriptFilePath);
73+
74+
Log.Write("linqPadScriptPath: {0}", fileName);
7675

7776
Inspection linqQuery = new Inspection(message);
7877
string linqQueryText = linqQuery.TransformText();
7978

80-
FS.FileSystem.File.WriteAllText(linqPadScriptFilePath, linqQueryText);
79+
FS.FileSystem.File.WriteAllText(fileName, linqQueryText);
8180

8281
Log.Write("LinqQuery Successfully deployed");
8382
}
@@ -89,7 +88,7 @@ internal void DeployLinqScript(Message message, string vsVersion)
8988
}
9089
}
9190

92-
private string FindAvailableFileName(string targetFolder, string fileName)
91+
private static string FindAvailableFileName(string targetFolder, string fileName)
9392
{
9493
int fileCount = 0;
9594
string path = Path.Combine(targetFolder, fileName);

Test/BridgeVs.UnitTest/Build/Tasks/MapperBuildTest.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public class MapperBuildTest
4848
private const string VsVersion15 = "15.0";
4949

5050
private static readonly MockFileSystem MockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
51-
{
52-
{ DebuggerVisualizerAssemblyLocation, new MockFileData(DebuggerVisualizerAssemblyByte) }
53-
});
51+
{
52+
{DebuggerVisualizerAssemblyLocation, new MockFileData(DebuggerVisualizerAssemblyByte)}
53+
});
5454

5555
private static string AssemblyModelLocation => typeof(CustomType1).Assembly.Location;
5656

@@ -110,13 +110,7 @@ public void Init()
110110
Isolate.WhenCalled(() => CommonRegistryConfigurations.IsErrorTrackingEnabled("")).WillReturn(false);
111111
Isolate.WhenCalled(() => CommonRegistryConfigurations.IsLoggingEnabled("")).WillReturn(false);
112112
}
113-
114-
//[TestCleanup]
115-
//public void TestCleanup()
116-
//{
117-
118-
//}
119-
113+
120114
[TestMethod]
121115
[TestCategory("UnitTest")]
122116
public void Mapper_Build_Test_V11_Should_Succeed()

Test/BridgeVs.UnitTest/DynamicVisualizers/DynamicDebuggerVisualizerTest.cs

+40-26
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@
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;
3326
using BridgeVs.DynamicVisualizers;
3427
using BridgeVs.DynamicVisualizers.Template;
3528
using BridgeVs.Shared.Common;
36-
using BridgeVs.Shared.FileSystem;
3729
using BridgeVs.Shared.Options;
3830
using BridgeVs.UnitTest.Model;
3931
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;
4038
using TypeMock.ArrangeActAssert;
39+
using FS = BridgeVs.Shared.FileSystem.FileSystemFactory;
4140

4241
namespace 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

Comments
 (0)