Skip to content

Updated To use EarlyBoundGenerator.Api. #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ UpgradeLog*.XML
*.ide-shm
*.ide-wal
/.vs
/spkl/.vs/spkl
2 changes: 1 addition & 1 deletion spkl/CrmSvcUtilFilteringService/CodeGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace spkl.CrmSvcUtilExtensions
using Microsoft.Xrm.Sdk.Client;
using System.Reflection;

public class CodeGenerationService : ICodeGenerationService
internal class CodeGenerationService : ICodeGenerationService
{
private ICodeGenerationService _defaultService;

Expand Down
27 changes: 27 additions & 0 deletions spkl/CrmSvcUtilFilteringService/CrmSvcUtil.FilteringService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.CrmSdk.CoreTools.9.0.0.7\content\bin\coretools\CrmSvcUtil.exe</HintPath>
</Reference>
<Reference Include="DLaB.EarlyBoundGenerator.Api, Version=1.2020.4.21, Culture=neutral, PublicKeyToken=915c5118a4c943b9, processorArchitecture=MSIL">
<HintPath>..\packages\DLaB.Xrm.EarlyBoundGenerator.Api.1.2020.4.21\lib\net462\DLaB.EarlyBoundGenerator.Api.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.0.7\lib\net452\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
</Reference>
Expand All @@ -64,6 +67,7 @@
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.0.7\lib\net452\Microsoft.Xrm.Sdk.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -109,6 +113,14 @@
<None Include="app.config" />
<None Include="bin\coretools\CrmSvcUtil.exe.config" />
<None Include="bin\coretools\LicenseTerms.docx" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1031.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1036.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1040.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1044.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1045.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1049.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\alphabets\1058.json" />
<None Include="bin\DLaB.EarlyBoundGenerator\CrmSvcUtil.exe.config" />
<None Include="spkl.crmsvcutil.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
Expand All @@ -130,6 +142,21 @@
<Content Include="bin\coretools\Microsoft.Xrm.Tooling.Ui.Styles.dll" />
<Content Include="bin\coretools\Other Redistributable.txt" />
<Content Include="bin\coretools\SolutionPackager.exe" />
<Content Include="bin\DLaB.EarlyBoundGenerator\CrmSvcUtil.exe" />
<Content Include="bin\DLaB.EarlyBoundGenerator\DLaB.CrmSvcUtilExtensions.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Crm.Sdk.Proxy.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Rest.ClientRuntime.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Client.CodeGeneration.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Client.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Sdk.Deployment.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Sdk.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Tooling.Connector.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Tooling.CrmConnectControl.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Tooling.Ui.Styles.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Microsoft.Xrm.Tooling.WebResourceUtility.dll" />
<Content Include="bin\DLaB.EarlyBoundGenerator\Newtonsoft.Json.dll" />
</ItemGroup>
<ItemGroup>
<Folder Include="bin\Debug\" />
Expand Down
2 changes: 1 addition & 1 deletion spkl/CrmSvcUtilFilteringService/FilteringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// <summary>
/// Allows filtering of the metadata to only generate the entities that we want
/// </summary>
public sealed class FilteringService : ICodeWriterFilterService
internal sealed class FilteringService : ICodeWriterFilterService
{
private List<string> _entities = null;
private string _entityLogicalName = null;
Expand Down
2 changes: 1 addition & 1 deletion spkl/CrmSvcUtilFilteringService/MessageFilteringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// <summary>
/// Allows filtering of the message so that we only generate the actions we want
/// </summary>
public class MessageFilteringService : ICodeWriterMessageFilterService
internal class MessageFilteringService : ICodeWriterMessageFilterService
{
private List<string> _messageFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Globalization;
using System.Xml.Linq;

public sealed class MetadataProviderQueryService : IMetadataProviderQueryService
internal sealed class MetadataProviderQueryService : IMetadataProviderQueryService
{
private static List<string> _excludedNamespaces;
private IDictionary<string, string> _parameters;
Expand Down
4 changes: 4 additions & 0 deletions spkl/CrmSvcUtilFilteringService/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<assemblyIdentity name="Microsoft.Xrm.Tooling.Connector" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.19.8.16603" newVersion="3.19.8.16603" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
1 change: 1 addition & 0 deletions spkl/CrmSvcUtilFilteringService/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DLaB.Xrm.EarlyBoundGenerator.Api" version="1.2020.4.21" targetFramework="net462" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.0.7" targetFramework="net462" />
<package id="Microsoft.CrmSdk.CoreTools" version="9.0.0.7" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.0.7" targetFramework="net462" />
Expand Down
130 changes: 29 additions & 101 deletions spkl/SparkleXrm.Tasks.Tests/EarlyBoundTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SparkleXrm.Tasks.Tests
{
Expand All @@ -18,7 +15,7 @@ public class EarlyBoundTypes
{
[TestMethod]
[TestCategory("Integration Tests")]
public void TestGenerateGlobalOptionsets()
public void TestGenerateOptionsets()
{
// Arrange
Guid id = Guid.NewGuid();
Expand All @@ -31,7 +28,6 @@ public void TestGenerateGlobalOptionsets()
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = true,
generateGlobalOptionsets = true,
entities ="socialprofile,socialactivity",
filename="entities.cs"
}
Expand All @@ -44,103 +40,42 @@ public void TestGenerateGlobalOptionsets()
// Check that there was only a single instance of the global optionsset 'socialprofile_community'
// public enum socialprofile_community

string code = File.ReadAllText(Path.Combine(tempFolder, "entities.cs"));
var matches = Regex.Matches(code, "public enum socialprofile_community");
Assert.AreEqual(1, matches.Count, "Global optionset created once only");
var matches = CountMatches("public enum SocialProfile_Community", tempFolder);
Assert.AreEqual(1, matches, "Global optionset created once only");
}
finally
{
Directory.Delete(tempFolder, true);
}
}

[TestMethod]
[TestCategory("Integration Tests")]
public void TestGenerateGlobalOptionsets_OneTypePerFile()
private static int CountMatches(string matchString, string tempFolder)
{
// Arrange
Guid id = Guid.NewGuid();
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
Directory.CreateDirectory(tempFolder);
try
var path = Path.Combine(tempFolder, "entities.cs");
string code = File.ReadAllText(path);
var matches = Regex.Matches(code, matchString);
var count = matches.Count;
path = Path.Combine(tempFolder, "optionsets.cs");
if (File.Exists(path))
{
var config = new ConfigFile
{
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = true,
generateGlobalOptionsets = true,
entities ="socialprofile,socialactivity",
filename="entities.cs",
oneTypePerFile = true
}
},
filePath = tempFolder

};
Generate(tempFolder, config);


Assert.IsFalse(File.Exists(Path.Combine(tempFolder, "entities.cs")));

EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialProfile.cs"), "SocialProfile");
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialActivity.cs"), "SocialActivity");

EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialprofile_community.cs"), "socialprofile_community");
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialactivity_prioritycode.cs"), "socialactivity_prioritycode");
}
finally
{
Directory.Delete(tempFolder, true);
code = File.ReadAllText(path);
matches = Regex.Matches(code, matchString);
count += matches.Count;
}
}

[TestMethod]
[TestCategory("Integration Tests")]
public void TestNotGeneratingGlobalOptionsets()
{
// Arrange
Guid id = Guid.NewGuid();
var tempFolder = Path.Combine(Path.GetTempPath(), id.ToString());
Directory.CreateDirectory(tempFolder);
try
{
var config = new ConfigFile
{
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = true,
generateGlobalOptionsets = false,
entities ="socialprofile,socialactivity",
filename="entities.cs"
}
},
filePath = tempFolder

};
Generate(tempFolder, config);

// Check that there was only a single instance of the global optionsset 'socialprofile_community'
// public enum socialprofile_community

string code = File.ReadAllText(Path.Combine(tempFolder, "entities.cs"));
var matches = Regex.Matches(code, "public enum socialprofile_community");
Assert.AreEqual(0, matches.Count, "Global optionset created once only");

// There should still be non-global optionsets generated
// public enum socialactivity_prioritycode
matches = Regex.Matches(code, "public enum socialactivity_prioritycode");
Assert.AreEqual(1, matches.Count, "Non-Global optionset created");
}
finally
path = Path.Combine(tempFolder, "actions.cs");
if (File.Exists(path))
{
Directory.Delete(tempFolder, true);
code = File.ReadAllText(path);
matches = Regex.Matches(code, matchString);
count += matches.Count;
}
return count;
}

[TestMethod]
[TestCategory("Integration Tests")]
public void TestNotGeneratingGlobalOptionsets_OneTypePerFile()
public void TestGenerateOptionsets_OneTypePerFile()
{
// Arrange
Guid id = Guid.NewGuid();
Expand All @@ -153,7 +88,6 @@ public void TestNotGeneratingGlobalOptionsets_OneTypePerFile()
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = true,
generateGlobalOptionsets = false,
entities ="socialprofile,socialactivity",
filename="entities.cs",
oneTypePerFile = true
Expand All @@ -170,9 +104,8 @@ public void TestNotGeneratingGlobalOptionsets_OneTypePerFile()
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialProfile.cs"), "SocialProfile");
EnsureClassIsCreatedCorrectly(Path.Combine($"{tempFolder}\\Entities", "SocialActivity.cs"), "SocialActivity");

Assert.IsFalse(File.Exists(Path.Combine($"{tempFolder}\\OptionSets", "socialprofile_community.cs")));
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialactivity_prioritycode.cs"), "socialactivity_prioritycode");

EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialprofile_community.cs"), "SocialProfile_Community");
EnsureOptionSetsIsCreatedCorrectly(Path.Combine($"{tempFolder}\\OptionSets", "socialactivity_prioritycode.cs"), "SocialActivity_PriorityCode");
}
finally
{
Expand All @@ -194,28 +127,25 @@ public void TestNotGeneratingAnyOptionsets()
{
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = false,
generateGlobalOptionsets = false,
entities ="socialprofile,socialactivity",
filename="entities.cs"
generateOptionsetEnums = false,
entities ="socialprofile,socialactivity"
}
},
filePath = tempFolder

};
Generate(tempFolder, config);

// Check that there are non instances of the global optionsset 'socialprofile_community'
// Check that there are no instances of the global optionsset 'socialprofile_community'
// public enum socialprofile_community

string code = File.ReadAllText(Path.Combine(tempFolder, "entities.cs"));
var matches = Regex.Matches(code, "public enum socialprofile_community");
Assert.AreEqual(0, matches.Count, "Global optionset created once only");
var matches = CountMatches("public enum SocialProfile_Community", tempFolder);
Assert.AreEqual(0, matches, "Global optionset created once only");

// There should be no non-global optionsets generated
// public enum socialactivity_prioritycode
matches = Regex.Matches(code, "public enum socialactivity_prioritycode");
Assert.AreEqual(0, matches.Count, "Non-Global optionset created");
matches = CountMatches("public enum SocialActivity_PriorityCode", tempFolder);
Assert.AreEqual(0, matches, "Non-Global optionset created");
}
finally
{
Expand All @@ -238,9 +168,7 @@ public void TestNotGeneratingAnyOptionsets_OneTypePerFile()
earlyboundtypes = new List<EarlyBoundTypeConfig>{
new EarlyBoundTypeConfig{
generateOptionsetEnums = false,
generateGlobalOptionsets = false,
entities ="socialprofile,socialactivity",
filename="entities.cs",
oneTypePerFile = true
}
},
Expand Down
Loading