Skip to content

Commit cc0a850

Browse files
unit test fix and unique identifier implementation
Fixes unit test for Sinjection build task adds unique identifier for the installation
1 parent c50f1c8 commit cc0a850

6 files changed

Lines changed: 71 additions & 13 deletions

File tree

Src/BridgeVs.Build/SInjection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using System.Reflection;
3232
using System.Threading;
3333
using BridgeVs.Build.Util;
34+
using BridgeVs.Shared.Common;
3435
using BridgeVs.Shared.Logging;
3536
using Mono.Cecil;
3637
using Mono.Cecil.Pdb;
@@ -125,6 +126,7 @@ public SInjection(string assemblyLocation, string snkCertificatePath = null, Pat
125126
_assemblyLocation = assemblyLocation;
126127
_snkCertificatePath = snkCertificatePath;
127128
_mode = mode;
129+
128130
Log.Write("Assembly being Injected {0}", assemblyLocation);
129131

130132
// if (IsAssemblyInExcludedList(Path.GetFileName(assemblyLocation))) return;

Src/BridgeVs.Locations/Common/CommonRegistryConfigurations.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class CommonRegistryConfigurations
99
{
1010
private const string ErrorTrackingRegistryValue = "SentryErrorTracking";
1111
private const string SerializationMethodRegistryValue = "SerializationMethod";
12-
public static string LoggingRegistryValue = "Logging";
12+
public const string LoggingRegistryValue = "Logging";
1313

1414
// ReSharper disable once InconsistentNaming
1515
private const string LINQPadInstallationPathRegistryValue = "LINQPadInstallationPath";
1616
// ReSharper disable once InconsistentNaming
1717
private const string LINQPadVersionPathRegistryValue = "LINQPadVersion";
1818

19+
public const string InstallationGuidRegistryValue = "UniqueId";
20+
1921

2022
// ReSharper disable once InconsistentNaming
2123
public static string GetLINQPadInstallationPath(string vsVersion)
@@ -65,7 +67,7 @@ public static void SetErrorTracking(string vsVersion, bool enabled)
6567
public static string GetOriginalAssemblyLocation(Type @type, string vsVersion)
6668
{
6769
bool isSystemAssembly(string name) => name.Contains("Microsoft") || name.Contains("System") || name.Contains("mscorlib");
68-
70+
6971
string registryKeyPath = $@"Software\LINQBridgeVs\{vsVersion}\Solutions";
7072

7173
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryKeyPath))
@@ -145,5 +147,22 @@ public static void SetLogging(string vsVersion, bool enabled)
145147
key?.SetValue(LoggingRegistryValue, enabled);
146148
}
147149
}
150+
151+
public static string GetUniqueGuid(string vsVersion)
152+
{
153+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
154+
{
155+
return key?.GetValue(InstallationGuidRegistryValue) as string;
156+
157+
}
158+
}
159+
160+
public static void SetUniqueGuid(string vsVersion, string guid)
161+
{
162+
using (RegistryKey key = Registry.CurrentUser.CreateSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
163+
{
164+
key?.SetValue(InstallationGuidRegistryValue, guid);
165+
}
166+
}
148167
}
149168
}

Src/BridgeVs.Locations/Logging/RavenWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ private RavenWrapper()
5454
HttpRequester request = req as HttpRequester;
5555
//GDPR compliant, no personal data sent: no server name, no username stored, no ip address
5656
request.Data.JsonPacket.ServerName = "linqbridgevs";
57-
request.Data.JsonPacket.Contexts.Device.Name = "linqbridgevs";
58-
request.Data.JsonPacket.User.Username = "linqbridgevs-" + DateTime.Now.ToLongTimeString();
57+
request.Data.JsonPacket.Contexts.Device.Name = "linqbridgevs";
58+
request.Data.JsonPacket.User.Username = CommonRegistryConfigurations.GetUniqueGuid(VisualStudioVersion);
5959
request.Data.JsonPacket.Release = "1.4.6"; //read it from somewhere
6060
request.Data.JsonPacket.User.IpAddress = "0.0.0.0";
6161
return request;

Src/BridgeVs.VsPackage.Helper/Configuration/PackageConfigurator.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public static class PackageConfigurator
5050
public static List<string> Dependencies => new List<string>
5151
{
5252
"BridgeVs.Grapple.dll",
53-
"BridgeVs.Locations.dll",
5453
"BridgeVs.Shared.dll",
55-
"BridgeVs.Logging.dll",
5654
"Newtonsoft.Json.dll",
5755
"System.IO.Abstractions.dll",
5856
"SharpRaven.dll"
@@ -127,7 +125,7 @@ private static bool IsLINQPadInstalled(string vsVersion)
127125
return false;
128126
}
129127

130-
private static void SetEnvironment(string vsVersion, string vsEdition)
128+
private static void DeployMsBuildTargets(string vsVersion, string vsEdition)
131129
{
132130
string msBuildDir = CreateMsBuildTargetDirectory(vsVersion, vsEdition);
133131
//Copy the CustomAfter and CustomBefore to the default MSbuild v4.0 location
@@ -245,7 +243,9 @@ public static bool Install(string vsVersion, string vsEdition)
245243
//Always check if installation folder has changed
246244
SetInstallationFolder(vsVersion);
247245

248-
SetEnvironment(vsVersion, vsEdition);
246+
DeployMsBuildTargets(vsVersion, vsEdition);
247+
248+
GenerateGuidForCurrentInstallation(vsVersion);
249249

250250
DeleteExistingVisualizers(vsVersion);
251251

@@ -254,6 +254,11 @@ public static bool Install(string vsVersion, string vsEdition)
254254
return true;
255255
}
256256

257+
private static void GenerateGuidForCurrentInstallation(string vsVersion)
258+
{
259+
CommonRegistryConfigurations.SetUniqueGuid(vsVersion, Guid.NewGuid().ToString());
260+
}
261+
257262
public static void DeployDependencies(string vsVersion)
258263
{
259264
string currentLocation = Path.GetDirectoryName(typeof(PackageConfigurator).Assembly.Location);

Src/BridgeVs.VsPackage.Helper/Settings/PackageSettings.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public sealed class PackageSettings : DialogPage
4747

4848
private string _linqPadInstallationPath = Defaults.LINQPadInstallationPath;
4949

50+
[Category("Installation")]
51+
[DisplayName("ID")]
52+
[Description("Unique installation ID. Please if you open a bug refer to this ID.")]
53+
[ReadOnly(true)]
54+
public string InstallationId
55+
{
56+
get
57+
{
58+
var dte = (DTE)GetService(typeof(SDTE));
59+
if (dte != null)
60+
{
61+
return CommonRegistryConfigurations.GetUniqueGuid(dte.Version);
62+
}
63+
64+
return string.Empty;
65+
}
66+
}
67+
5068
[Category("LINQPad")]
5169
[DisplayName("Installation Path")]
5270
[Description("Sets the path to the LINQPad exe")]

Test/BridgeVs.Build.Test/SInjectionBuildTest.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System.IO;
2+
using System.Reflection;
23
using BridgeVs.Build.Tasks;
34
using BridgeVs.Model.Test;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -8,21 +9,34 @@ namespace BridgeVs.Build.Test
89
[TestClass]
910
public class SInjectionBuildTest
1011
{
11-
private static Assembly _assemblyModel;
12+
private static string _assemblyToInjectLocation;
1213

1314
[ClassInitialize]
1415
public static void Init(TestContext context)
1516
{
16-
_assemblyModel = typeof(CustomType1).Assembly;
17+
Assembly assemblyModel = typeof(CustomType1).Assembly;
18+
//need to copy the assembly because it is loaded in the app domain and cannot
19+
//be changed as it's readonly
20+
string fileName = Path.GetFileNameWithoutExtension(assemblyModel.Location);
21+
string newFileName = fileName + "_test";
22+
string location = Path.GetDirectoryName(assemblyModel.Location);
23+
_assemblyToInjectLocation = Path.Combine(location, newFileName) + ".dll";
24+
File.Copy(assemblyModel.Location, _assemblyToInjectLocation, true);
1725
}
18-
26+
27+
[ClassCleanup]
28+
public static void Cleanup()
29+
{
30+
File.Delete(_assemblyToInjectLocation);
31+
}
32+
1933
[TestMethod]
2034
[TestCategory("UnitTest")]
2135
public void SInjection_BuildTask_Test_Should_Succeed()
2236
{
2337
SInjectionBuildTask sInjectionBuildTask = new SInjectionBuildTask
2438
{
25-
Assembly = _assemblyModel.Location
39+
Assembly = _assemblyToInjectLocation
2640
};
2741

2842
bool result = sInjectionBuildTask.Execute();

0 commit comments

Comments
 (0)