Skip to content

Commit a29c4a9

Browse files
fixes mapper unit tests for appveyor
1 parent 3aadcd3 commit a29c4a9

File tree

2 files changed

+70
-96
lines changed

2 files changed

+70
-96
lines changed

Src/Logging/Log.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -150,65 +150,5 @@ public static void WriteIf(bool condition, string msg, params object[] args)
150150

151151
InternalWrite(msg, args);
152152
}
153-
154-
public static bool SendLogFileAsEmail(string emailTo)
155-
{
156-
if (_smtpClient == null)
157-
throw new Exception("Set the SmtpClient in the Configure() method to enable the Log sending emails");
158-
159-
try
160-
{
161-
using (var inFile = File.OpenRead(_logTxtFilePath))
162-
{
163-
using (var outFile = new MemoryStream())
164-
{
165-
using (var compress = new GZipStream(outFile,
166-
CompressionMode.Compress))
167-
{
168-
inFile.CopyTo(compress);
169-
}
170-
var attachment = new Attachment(outFile, _logGzipFileName);
171-
var subject = $"Log Report for {_applicationName}";
172-
173-
_smtpClient.Send(BuildMailMessage(emailTo, attachment, subject));
174-
175-
return true;
176-
177-
}
178-
}
179-
}
180-
catch (Exception e)
181-
{
182-
Write(e, "Problem Sending the Email");
183-
return false;
184-
}
185-
186-
187-
188-
}
189-
190-
private static MailMessage BuildMailMessage(string emailTo, Attachment attachment, string subject)
191-
{
192-
193-
var mailAddressTo = new MailAddress(emailTo);
194-
var mailMessage = new MailMessage(MailAddressFrom, mailAddressTo) { Subject = subject };
195-
196-
mailMessage.Attachments.Add(attachment);
197-
198-
return mailMessage;
199-
}
200-
#if NET35
201-
// Only useful before .NET 4
202-
public static void CopyTo(this Stream input, Stream output)
203-
{
204-
byte[] buffer = new byte[16 * 1024]; // Fairly arbitrary size
205-
int bytesRead;
206-
207-
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
208-
{
209-
output.Write(buffer, 0, bytesRead);
210-
}
211-
}
212-
#endif
213153
}
214154
}

Test/LINQBridgeVs.Test/BuildTasks.Test/MapperBuildTest.cs

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,99 +35,133 @@ namespace BridgeVs.Build.UnitTest
3535
[TestClass]
3636
public class MapperBuildTest
3737
{
38-
private static Assembly _assemblyModel;
38+
private const string VsVersion11 = "11.0";
39+
private const string VsVersion12 = "12.0";
40+
private const string VsVersion14 = "14.0";
41+
private const string VsVersion15 = "15.0";
42+
43+
private static string AssemblyModelLocation => typeof(CustomType1).Assembly.Location;
44+
45+
private static string TargetAssemblyName(string vsVersion)
46+
{
47+
return VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(vsVersion, AssemblyModelLocation);
48+
}
49+
50+
private static string TargetInstallationPath(string vsVersion)
51+
{
52+
return VisualStudioOptions.GetVisualizerDestinationFolder(vsVersion);
53+
}
54+
55+
private static string DotNetAssemblyName(string vsVersion)
56+
{
57+
return VisualizerAssemblyNameFormat.GetDotNetVisualizerName(vsVersion);
58+
}
3959

4060
[ClassInitialize]
4161
public static void Init(TestContext context)
4262
{
43-
_assemblyModel = typeof(CustomType1).Assembly;
63+
if (!Directory.Exists(TargetInstallationPath(VsVersion11)))
64+
{
65+
Directory.CreateDirectory(TargetInstallationPath(VsVersion11));
66+
}
67+
68+
if (!Directory.Exists(TargetInstallationPath(VsVersion12)))
69+
{
70+
Directory.CreateDirectory(TargetInstallationPath(VsVersion12));
71+
}
4472

73+
if (!Directory.Exists(TargetInstallationPath(VsVersion14)))
74+
{
75+
Directory.CreateDirectory(TargetInstallationPath(VsVersion14));
76+
}
77+
78+
if (!Directory.Exists(TargetInstallationPath(VsVersion15)))
79+
{
80+
Directory.CreateDirectory(TargetInstallationPath(VsVersion15));
81+
}
82+
}
83+
84+
[ClassCleanup]
85+
public static void Cleanup()
86+
{
87+
//delete the visualizers
88+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion11), TargetAssemblyName(VsVersion11)));
89+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion12), TargetAssemblyName(VsVersion12)));
90+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion14), TargetAssemblyName(VsVersion14)));
91+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion15), TargetAssemblyName(VsVersion15)));
92+
93+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion11), DotNetAssemblyName(VsVersion11)));
94+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion12), DotNetAssemblyName(VsVersion12)));
95+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion14), DotNetAssemblyName(VsVersion14)));
96+
File.Delete(Path.Combine(TargetInstallationPath(VsVersion15), DotNetAssemblyName(VsVersion15)));
4597
}
4698

4799
[TestMethod]
48100
[TestCategory("UnitTest")]
49101
public void Mapper_Build_Test_V11_Should_Succeed()
50102
{
51-
const string vsVersion = "11.0";
52-
string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(vsVersion, _assemblyModel.Location);
53-
string targetInstallationPath = VisualStudioOptions.GetVisualizerDestinationFolder(vsVersion);
54-
55103
MapperBuildTask mapper = new MapperBuildTask
56104
{
57-
Assembly = _assemblyModel.Location,
58-
VisualStudioVer = vsVersion
105+
Assembly = AssemblyModelLocation,
106+
VisualStudioVer = VsVersion11
59107
};
60108

61109
bool result = mapper.Execute();
62110

63111
Assert.IsTrue(result, "Mapper Build Task Execute return false.");
64-
Assert.IsTrue(File.Exists(Path.Combine(targetInstallationPath,targetAssemblyName)));
65-
66-
File.Delete(Path.Combine(targetInstallationPath, targetAssemblyName));
112+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion11), TargetAssemblyName(VsVersion11))), $"Custom Debugger Visualizer {TargetAssemblyName(VsVersion11)} hasn't been created");
113+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion11), DotNetAssemblyName(VsVersion11))), $"DotNet Debugger Visualizer {DotNetAssemblyName(VsVersion11)} hasn't been created ");
67114
}
68115

69116
[TestMethod]
70117
[TestCategory("UnitTest")]
71118
public void Mapper_Build_Test_V12_Should_Succeed()
72119
{
73-
const string vsVersion = "12.0";
74-
string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(vsVersion, _assemblyModel.Location);
75-
string targetInstallationPath = VisualStudioOptions.GetVisualizerDestinationFolder(vsVersion);
76-
77120
MapperBuildTask mapper = new MapperBuildTask
78121
{
79-
Assembly = _assemblyModel.Location,
80-
VisualStudioVer = vsVersion
122+
Assembly = AssemblyModelLocation,
123+
VisualStudioVer = VsVersion12
81124
};
82125

83126
bool result = mapper.Execute();
84127

85128
Assert.IsTrue(result, "Mapper Build Task Execute return false.");
86-
Assert.IsTrue(File.Exists(Path.Combine(targetInstallationPath, targetAssemblyName)));
87-
88-
File.Delete(Path.Combine(targetInstallationPath, targetAssemblyName));
129+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion12), TargetAssemblyName(VsVersion12))), $"Custom Debugger Visualizer {TargetAssemblyName(VsVersion12)} hasn't been created");
130+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion12), DotNetAssemblyName(VsVersion12))), $"DotNet Debugger Visualizer {DotNetAssemblyName(VsVersion12)} hasn't been created ");
89131
}
90132
[TestMethod]
91133
[TestCategory("UnitTest")]
92134
public void Mapper_Build_Test_V14_Should_Succeed()
93135
{
94-
const string vsVersion = "14.0";
95-
string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(vsVersion, _assemblyModel.Location);
96-
string targetInstallationPath = VisualStudioOptions.GetVisualizerDestinationFolder(vsVersion);
97-
98136
MapperBuildTask mapper = new MapperBuildTask
99137
{
100-
Assembly = _assemblyModel.Location,
101-
VisualStudioVer = vsVersion
138+
Assembly = AssemblyModelLocation,
139+
VisualStudioVer = VsVersion14
102140
};
103141

104142
bool result = mapper.Execute();
105143

106144
Assert.IsTrue(result, "Mapper Build Task Execute return false.");
107-
Assert.IsTrue(File.Exists(Path.Combine(targetInstallationPath, targetAssemblyName)));
108145

109-
File.Delete(Path.Combine(targetInstallationPath, targetAssemblyName));
146+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion14), TargetAssemblyName(VsVersion14))), $"Custom Debugger Visualizer {TargetAssemblyName(VsVersion14)} hasn't been created");
147+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion14), DotNetAssemblyName(VsVersion14))), $"DotNet Debugger Visualizer {DotNetAssemblyName(VsVersion14)} hasn't been created ");
110148
}
111149
[TestMethod]
112150
[TestCategory("UnitTest")]
113151
public void Mapper_Build_Test_V15_Should_Succeed()
114152
{
115-
const string vsVersion = "15.0";
116-
string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(vsVersion, _assemblyModel.Location);
117-
string targetInstallationPath = VisualStudioOptions.GetVisualizerDestinationFolder(vsVersion);
118-
119153
MapperBuildTask mapper = new MapperBuildTask
120154
{
121-
Assembly = _assemblyModel.Location,
122-
VisualStudioVer = vsVersion
155+
Assembly = AssemblyModelLocation,
156+
VisualStudioVer = VsVersion15
123157
};
124158

125159
bool result = mapper.Execute();
126160

127161
Assert.IsTrue(result, "Mapper Build Task Execute return false.");
128-
Assert.IsTrue(File.Exists(Path.Combine(targetInstallationPath, targetAssemblyName)));
129162

130-
File.Delete(Path.Combine(targetInstallationPath, targetAssemblyName));
163+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion15), TargetAssemblyName(VsVersion15))), $"Custom Debugger Visualizer {TargetAssemblyName(VsVersion15)} hasn't been created");
164+
Assert.IsTrue(File.Exists(Path.Combine(TargetInstallationPath(VsVersion15), DotNetAssemblyName(VsVersion15))), $"DotNet Debugger Visualizer {DotNetAssemblyName(VsVersion15)} hasn't been created ");
131165
}
132166
}
133167
}

0 commit comments

Comments
 (0)