Skip to content

Commit 38ee412

Browse files
committed
#383 - Integrate DlaB Early Bound Generator
1 parent 24fc5ec commit 38ee412

28 files changed

+345
-298
lines changed

spkl/CrmSvcUtilFilteringService/CrmSvcUtil.FilteringService.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.21\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
5656
</Reference>
5757
<Reference Include="Microsoft.CSharp" />
58-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
59-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.4\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
58+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6262
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.25\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>

spkl/CrmSvcUtilFilteringService/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</dependentAssembly>
2525
<dependentAssembly>
2626
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
27-
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
27+
<bindingRedirect oldVersion="0.0.0.0-5.2.8.0" newVersion="5.2.8.0" />
2828
</dependentAssembly>
2929
</assemblyBinding>
3030
</runtime>

spkl/CrmSvcUtilFilteringService/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.21" targetFramework="net462" />
66
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.21" targetFramework="net462" />
77
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.0.25" targetFramework="net462" />
8-
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.4" targetFramework="net462" />
8+
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.8" targetFramework="net462" />
99
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net462" />
1010
<package id="System.Net.Http" version="4.3.4" targetFramework="net462" />
1111
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net462" />

spkl/SparkleXrm.Tasks.Tests/EarlyBoundTypes.cs

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -13,82 +13,6 @@ namespace SparkleXrm.Tasks.Tests
1313
[TestClass]
1414
public class EarlyBoundTypes
1515
{
16-
[TestMethod]
17-
[TestCategory("Integration Tests")]
18-
public void TestEbgGenerateGlobalOptionsets()
19-
{
20-
// Arrange
21-
Guid id = Guid.NewGuid();
22-
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
23-
Directory.CreateDirectory(tempFolder);
24-
try
25-
{
26-
var config = new ConfigFile
27-
{
28-
earlyboundtypes = new List<EarlyBoundTypeConfig>{
29-
new EarlyBoundTypeConfig{
30-
useEarlyBoundGeneratorApi = true,
31-
generateOptionsetEnums = true,
32-
entities ="socialprofile,socialactivity"
33-
}
34-
},
35-
filePath = tempFolder
36-
37-
};
38-
Generate(tempFolder, config);
39-
40-
// Check that there was only a single instance of the global optionsset 'socialprofile_community'
41-
// public enum socialprofile_community
42-
43-
var matches = CountMatches("public enum SocialProfile_Community", tempFolder);
44-
Assert.AreEqual(1, matches, "Global optionset created once only");
45-
}
46-
finally
47-
{
48-
Directory.Delete(tempFolder, true);
49-
}
50-
}
51-
52-
[TestMethod]
53-
[TestCategory("Integration Tests")]
54-
public void TestEbgGenerateGlobalOptionsets_OneTypePerFile()
55-
{
56-
// Arrange
57-
Guid id = Guid.NewGuid();
58-
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
59-
Directory.CreateDirectory(tempFolder);
60-
try
61-
{
62-
var config = new ConfigFile
63-
{
64-
earlyboundtypes = new List<EarlyBoundTypeConfig>{
65-
new EarlyBoundTypeConfig{
66-
generateOptionsetEnums = true,
67-
useEarlyBoundGeneratorApi = true,
68-
entities ="socialprofile,socialactivity",
69-
oneTypePerFile = true
70-
}
71-
},
72-
filePath = tempFolder
73-
74-
};
75-
Generate(tempFolder, config);
76-
77-
78-
Assert.IsFalse(File.Exists(Path.Combine(tempFolder, "entities.cs")));
79-
80-
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialProfile.cs"), "SocialProfile");
81-
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialActivity.cs"), "SocialActivity");
82-
83-
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialprofile_community.cs"), "SocialProfile_Community");
84-
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialactivity_prioritycode.cs"), "SocialActivity_PriorityCode");
85-
}
86-
finally
87-
{
88-
Directory.Delete(tempFolder, true);
89-
}
90-
}
91-
9216
[TestMethod]
9317
[TestCategory("Integration Tests")]
9418
public void TestGenerateGlobalOptionsets()
@@ -351,7 +275,7 @@ private static void Generate(string tempFolder, ConfigFile config)
351275

352276
// Act
353277
var task = new EarlyBoundClassGeneratorTask(ctx, trace);
354-
task.ConectionString = connectionString;
278+
task.ConnectionString = connectionString;
355279

356280
task.CreateEarlyBoundTypes(ctx, config);
357281
}
@@ -370,29 +294,5 @@ private static void EnsureOptionSetsIsCreatedCorrectly(string optionSetsPath, st
370294
var matches = Regex.Matches(code, $"public enum {optionSetsName}");
371295
Assert.AreEqual(1, matches.Count, $"Optionset {optionSetsName} created once only");
372296
}
373-
374-
private static int CountMatches(string matchString, string tempFolder)
375-
{
376-
var path = Path.Combine(tempFolder, "entities.cs");
377-
string code = File.ReadAllText(path);
378-
var matches = Regex.Matches(code, matchString);
379-
var count = matches.Count;
380-
path = Path.Combine(tempFolder, "optionsets.cs");
381-
if (File.Exists(path))
382-
{
383-
code = File.ReadAllText(path);
384-
matches = Regex.Matches(code, matchString);
385-
count += matches.Count;
386-
}
387-
388-
path = Path.Combine(tempFolder, "actions.cs");
389-
if (File.Exists(path))
390-
{
391-
code = File.ReadAllText(path);
392-
matches = Regex.Matches(code, matchString);
393-
count += matches.Count;
394-
}
395-
return count;
396-
}
397297
}
398298
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Microsoft.Xrm.Sdk.Client;
3+
using Microsoft.Xrm.Tooling.Connector;
4+
using SparkleXrm.Tasks.Config;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Configuration;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Text.RegularExpressions;
12+
using System.Threading.Tasks;
13+
14+
namespace SparkleXrm.Tasks.Tests
15+
{
16+
[TestClass]
17+
public class EarlyBoundTypesDlaB
18+
{
19+
[TestMethod]
20+
[TestCategory("Integration Tests")]
21+
public void TestEbgGenerateGlobalOptionsets()
22+
{
23+
// Arrange
24+
Guid id = Guid.NewGuid();
25+
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
26+
Directory.CreateDirectory(tempFolder);
27+
try
28+
{
29+
var config = new ConfigFile
30+
{
31+
earlyboundtypes = new List<EarlyBoundTypeConfig>{
32+
new EarlyBoundTypeConfig{
33+
useEarlyBoundGeneratorApi = true,
34+
generateOptionsetEnums = true,
35+
entities ="socialprofile,socialactivity"
36+
}
37+
},
38+
filePath = tempFolder
39+
40+
};
41+
Generate(tempFolder, config);
42+
43+
// Check that there was only a single instance of the global optionsset 'socialprofile_community'
44+
// public enum socialprofile_community
45+
46+
var matches = CountMatches("public enum SocialProfile_Community", tempFolder);
47+
Assert.AreEqual(1, matches, "Global optionset created once only");
48+
}
49+
finally
50+
{
51+
Directory.Delete(tempFolder, true);
52+
}
53+
}
54+
55+
[TestMethod]
56+
[TestCategory("Integration Tests")]
57+
public void TestEbgGenerateGlobalOptionsets_OneTypePerFile()
58+
{
59+
// Arrange
60+
Guid id = Guid.NewGuid();
61+
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
62+
Directory.CreateDirectory(tempFolder);
63+
try
64+
{
65+
var config = new ConfigFile
66+
{
67+
earlyboundtypes = new List<EarlyBoundTypeConfig>{
68+
new EarlyBoundTypeConfig{
69+
generateOptionsetEnums = true,
70+
useEarlyBoundGeneratorApi = true,
71+
entities ="socialprofile,socialactivity",
72+
oneTypePerFile = true
73+
}
74+
},
75+
filePath = tempFolder
76+
77+
};
78+
Generate(tempFolder, config);
79+
80+
81+
Assert.IsFalse(File.Exists(Path.Combine(tempFolder, "entities.cs")));
82+
83+
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialProfile.cs"), "SocialProfile");
84+
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialActivity.cs"), "SocialActivity");
85+
86+
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialprofile_community.cs"), "SocialProfile_Community");
87+
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialactivity_prioritycode.cs"), "SocialActivity_PriorityCode");
88+
}
89+
finally
90+
{
91+
Directory.Delete(tempFolder, true);
92+
}
93+
}
94+
private static void Generate(string tempFolder, ConfigFile config)
95+
{
96+
var connectionString = ConfigurationManager.ConnectionStrings["integration_testing"].ConnectionString;
97+
CrmServiceClient crmSvc = new CrmServiceClient(connectionString);
98+
var userId = crmSvc.GetMyCrmUserId();
99+
var trace = new TraceLogger();
100+
101+
102+
using (var ctx = new OrganizationServiceContext(crmSvc))
103+
{
104+
ctx.MergeOption = MergeOption.NoTracking;
105+
106+
// Act
107+
var task = new EarlyBoundClassGeneratorTask(ctx, trace);
108+
task.ConnectionString = connectionString;
109+
110+
task.CreateEarlyBoundTypes(ctx, config);
111+
}
112+
}
113+
114+
private static void EnsureClassIsCreatedCorrectly(string classPath, string className)
115+
{
116+
var code = File.ReadAllText(classPath);
117+
var matches = Regex.Matches(code, $"public partial class {className}");
118+
Assert.AreEqual(1, matches.Count, $"Class {className} created once only");
119+
}
120+
121+
private static void EnsureOptionSetsIsCreatedCorrectly(string optionSetsPath, string optionSetsName)
122+
{
123+
var code = File.ReadAllText(optionSetsPath);
124+
var matches = Regex.Matches(code, $"public enum {optionSetsName}");
125+
Assert.AreEqual(1, matches.Count, $"Optionset {optionSetsName} created once only");
126+
}
127+
128+
private static int CountMatches(string matchString, string tempFolder)
129+
{
130+
var path = Path.Combine(tempFolder, "entities.cs");
131+
string code = File.ReadAllText(path);
132+
var matches = Regex.Matches(code, matchString);
133+
var count = matches.Count;
134+
path = Path.Combine(tempFolder, "optionsets.cs");
135+
if (File.Exists(path))
136+
{
137+
code = File.ReadAllText(path);
138+
matches = Regex.Matches(code, matchString);
139+
count += matches.Count;
140+
}
141+
142+
path = Path.Combine(tempFolder, "actions.cs");
143+
if (File.Exists(path))
144+
{
145+
code = File.ReadAllText(path);
146+
matches = Regex.Matches(code, matchString);
147+
count += matches.Count;
148+
}
149+
return count;
150+
}
151+
}
152+
}

spkl/SparkleXrm.Tasks.Tests/SparkleXrm.Tasks.Tests.csproj

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,38 @@
5151
<HintPath>..\packages\FakeItEasy.5.5.0\lib\net45\FakeItEasy.dll</HintPath>
5252
</Reference>
5353
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54-
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.24\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
54+
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.26\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
5555
<Private>True</Private>
5656
</Reference>
5757
<Reference Include="Microsoft.CSharp" />
58-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
59-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
60-
<Private>True</Private>
61-
</Reference>
62-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.19.8.16603, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
63-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
58+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
6460
</Reference>
6561
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.42\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>
67-
<Private>True</Private>
62+
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.44\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>
6863
</Reference>
6964
<Reference Include="Microsoft.VisualBasic" />
7065
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
7166
<Private>False</Private>
7267
</Reference>
7368
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74-
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
69+
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.26\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
7570
<Private>True</Private>
7671
</Reference>
7772
<Reference Include="Microsoft.Xrm.Sdk.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78-
<HintPath>..\packages\Microsoft.CrmSdk.Deployment.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
73+
<HintPath>..\packages\Microsoft.CrmSdk.Deployment.9.0.2.26\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
7974
<Private>True</Private>
8075
</Reference>
8176
<Reference Include="Microsoft.Xrm.Sdk.Workflow, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
82-
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
77+
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.26\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
8378
<Private>True</Private>
8479
</Reference>
8580
<Reference Include="Microsoft.Xrm.Tooling.Connector, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
86-
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.42\lib\net462\Microsoft.Xrm.Tooling.Connector.dll</HintPath>
81+
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.44\lib\net462\Microsoft.Xrm.Tooling.Connector.dll</HintPath>
8782
<Private>True</Private>
8883
</Reference>
89-
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
90-
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
91-
<Private>True</Private>
84+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
85+
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
9286
</Reference>
9387
<Reference Include="PresentationFramework" />
9488
<Reference Include="System" />
@@ -181,6 +175,7 @@
181175
<Compile Include="DeployPluginTests.cs" />
182176
<Compile Include="DownloadWebresourceFiles.cs" />
183177
<Compile Include="EarlyBoundTypes.cs" />
178+
<Compile Include="EarlyBoundTypes_DlaB.cs" />
184179
<Compile Include="GetWebresources.cs" />
185180
<Compile Include="ImportCodeTests.cs" />
186181
<Compile Include="Properties\AssemblyInfo.cs" />

spkl/SparkleXrm.Tasks.Tests/app.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<connectionStrings>
4-
<add name="integration_testing" connectionString="Url=http://dev04/Contoso" />
4+
<add name="integration_testing" connectionString="" />
55
</connectionStrings>
66

77
<runtime>
@@ -73,7 +73,7 @@
7373
</dependentAssembly>
7474
<dependentAssembly>
7575
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
76-
<bindingRedirect oldVersion="0.0.0.0-3.19.8.0" newVersion="3.19.8.0" />
76+
<bindingRedirect oldVersion="0.0.0.0-5.2.8.0" newVersion="5.2.8.0" />
7777
</dependentAssembly>
7878
<dependentAssembly>
7979
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

0 commit comments

Comments
 (0)