Skip to content
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
108 changes: 102 additions & 6 deletions spkl/SparkleXrm.Tasks.Tests/EarlyBoundTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,89 @@
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
{
[TestClass]
public class EarlyBoundTypes
{
[TestMethod]
[TestCategory("Integration Tests")]
public void TestEbgGenerateGlobalOptionsets()
{
// 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{
useEarlyBoundGeneratorApi = true,
generateOptionsetEnums = true,
entities ="socialprofile,socialactivity"
}
},
filePath = tempFolder

};
Generate(tempFolder, config);

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

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 TestEbgGenerateGlobalOptionsets_OneTypePerFile()
{
// 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,
useEarlyBoundGeneratorApi = true,
entities ="socialprofile,socialactivity",
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);
}
}

[TestMethod]
[TestCategory("Integration Tests")]
public void TestGenerateGlobalOptionsets()
Expand Down Expand Up @@ -222,7 +295,7 @@ public void TestNotGeneratingAnyOptionsets()
Directory.Delete(tempFolder, true);
}
}

[TestMethod]
[TestCategory("Integration Tests")]
public void TestNotGeneratingAnyOptionsets_OneTypePerFile()
Expand Down Expand Up @@ -263,7 +336,7 @@ public void TestNotGeneratingAnyOptionsets_OneTypePerFile()
Directory.Delete(tempFolder, true);
}
}

private static void Generate(string tempFolder, ConfigFile config)
{
var connectionString = ConfigurationManager.ConnectionStrings["integration_testing"].ConnectionString;
Expand All @@ -284,7 +357,6 @@ private static void Generate(string tempFolder, ConfigFile config)
}
}


private static void EnsureClassIsCreatedCorrectly(string classPath, string className)
{
var code = File.ReadAllText(classPath);
Expand All @@ -298,5 +370,29 @@ private static void EnsureOptionSetsIsCreatedCorrectly(string optionSetsPath, st
var matches = Regex.Matches(code, $"public enum {optionSetsName}");
Assert.AreEqual(1, matches.Count, $"Optionset {optionSetsName} created once only");
}

private static int CountMatches(string matchString, string tempFolder)
{
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))
{
code = File.ReadAllText(path);
matches = Regex.Matches(code, matchString);
count += matches.Count;
}

path = Path.Combine(tempFolder, "actions.cs");
if (File.Exists(path))
{
code = File.ReadAllText(path);
matches = Regex.Matches(code, matchString);
count += matches.Count;
}
return count;
}
}
}
106 changes: 96 additions & 10 deletions spkl/SparkleXrm.Tasks.Tests/SparkleXrm.Tasks.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,51 @@
<AssemblyOriginatorKeyFile>Plugins.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="DLaB.EarlyBoundGenerator.Api, Version=1.2020.5.5, Culture=neutral, PublicKeyToken=915c5118a4c943b9, processorArchitecture=MSIL">
<HintPath>..\packages\DLaB.Xrm.EarlyBoundGenerator.Api.1.2020.5.5\lib\net462\DLaB.EarlyBoundGenerator.Api.dll</HintPath>
</Reference>
<Reference Include="FakeItEasy, Version=5.0.0.0, Culture=neutral, PublicKeyToken=eff28e2146d5fd2c, processorArchitecture=MSIL">
<HintPath>..\packages\FakeItEasy.5.5.0\lib\net45\FakeItEasy.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.2.23\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.24\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.4\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.19.8.16603, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.38\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.42\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.23\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.Deployment.9.0.2.23\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.Deployment.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Workflow, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.23\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.24\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Tooling.Connector, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.38\lib\net462\Microsoft.Xrm.Tooling.Connector.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.42\lib\net462\Microsoft.Xrm.Tooling.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down Expand Up @@ -188,6 +203,16 @@
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="bin\Debug\SparkleXrm.Tasks.dll.config" />
<None Include="bin\Debug\SparkleXrm.Tasks.Tests.dll.config" />
<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="packages.config">
<SubType>Designer</SubType>
</None>
Expand All @@ -209,6 +234,67 @@
<ItemGroup>
<None Include="Resources\CustomBaseClassPlugin.txt" />
</ItemGroup>
<ItemGroup>
<Content Include="bin\Debug\DLaB.EarlyBoundGenerator.Api.dll" />
<Content Include="bin\Debug\FakeItEasy.dll" />
<Content Include="bin\Debug\FakeItEasy.pdb" />
<Content Include="bin\Debug\FakeItEasy.xml" />
<Content Include="bin\Debug\Log10.txt" />
<Content Include="bin\Debug\Log12.txt" />
<Content Include="bin\Debug\Log15.txt" />
<Content Include="bin\Debug\Log17.txt" />
<Content Include="bin\Debug\Log18.txt" />
<Content Include="bin\Debug\Log19.txt" />
<Content Include="bin\Debug\Log20.txt" />
<Content Include="bin\Debug\Log21.txt" />
<Content Include="bin\Debug\Log22.txt" />
<Content Include="bin\Debug\Log24.txt" />
<Content Include="bin\Debug\Log27.txt" />
<Content Include="bin\Debug\Log8.txt" />
<Content Include="bin\Debug\Microsoft.Crm.Sdk.Proxy.dll" />
<Content Include="bin\Debug\Microsoft.Crm.Sdk.Proxy.xml" />
<Content Include="bin\Debug\Microsoft.Extensions.FileSystemGlobbing.dll" />
<Content Include="bin\Debug\Microsoft.Extensions.FileSystemGlobbing.xml" />
<Content Include="bin\Debug\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" />
<Content Include="bin\Debug\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" />
<Content Include="bin\Debug\Microsoft.IdentityModel.Clients.ActiveDirectory.xml" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.Deployment.dll" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.Deployment.xml" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.dll" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.Workflow.dll" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.Workflow.xml" />
<Content Include="bin\Debug\Microsoft.Xrm.Sdk.xml" />
<Content Include="bin\Debug\Microsoft.Xrm.Tooling.Connector.dll" />
<Content Include="bin\Debug\Microsoft.Xrm.Tooling.Connector.xml" />
<Content Include="bin\Debug\netstandard.dll" />
<Content Include="bin\Debug\Newtonsoft.Json.dll" />
<Content Include="bin\Debug\SparkleXrm.Tasks.dll" />
<Content Include="bin\Debug\SparkleXrm.Tasks.pdb" />
<Content Include="bin\Debug\SparkleXrm.Tasks.Tests.dll" />
<Content Include="bin\Debug\SparkleXrm.Tasks.Tests.pdb" />
<Content Include="bin\Debug\System.Collections.Immutable.dll" />
<Content Include="bin\Debug\System.Collections.Immutable.xml" />
<Content Include="bin\Debug\System.Runtime.dll" />
<Content Include="bin\Debug\System.Runtime.Extensions.dll" />
<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\Release\" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions spkl/SparkleXrm.Tasks.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<connectionStrings>
<add name="integration_testing" connectionString="Url=http://dev04/Contoso" />
</connectionStrings>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Expand Down Expand Up @@ -73,7 +73,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
<bindingRedirect oldVersion="0.0.0.0-3.19.8.0" newVersion="3.19.8.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand Down
13 changes: 7 additions & 6 deletions spkl/SparkleXrm.Tasks.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DLaB.Xrm.EarlyBoundGenerator.Api" version="1.2020.5.5" targetFramework="net462" />
<package id="FakeItEasy" version="5.5.0" targetFramework="net462" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.23" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.23" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.23" targetFramework="net462" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.0.38" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.4" targetFramework="net462" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.24" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.24" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.24" targetFramework="net462" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.0.42" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.19.8" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.20" targetFramework="net462" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net462" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net462" />
<package id="System.Buffers" version="4.5.0" targetFramework="net462" />
<package id="System.Collections.Immutable" version="1.7.0" targetFramework="net462" />
<package id="System.Memory" version="4.5.3" targetFramework="net462" />
Expand Down
Loading