diff --git a/.github/workflows/CI-3x.yml b/.github/workflows/CI-3x.yml index ff7aa9dd..c0cad78b 100644 --- a/.github/workflows/CI-3x.yml +++ b/.github/workflows/CI-3x.yml @@ -9,7 +9,7 @@ on: - '*.txt' env: - dotnet-version: 6.0.407 + dotnet-version: 3.1.201 source-url: "https://nuget.pkg.github.com/${{github.repository_owner}}/index.json" jobs: @@ -45,7 +45,7 @@ jobs: strategy: fail-fast: false matrix: - configuration: ['FAKE_XRM_EASY_9', 'FAKE_XRM_EASY_365', 'FAKE_XRM_EASY_2016','FAKE_XRM_EASY_2015','FAKE_XRM_EASY_2013'] + configuration: ['FAKE_XRM_EASY_9', 'FAKE_XRM_EASY_365', 'FAKE_XRM_EASY_2016','FAKE_XRM_EASY_2015','FAKE_XRM_EASY_2013','FAKE_XRM_EASY'] runs-on: windows-latest @@ -88,10 +88,10 @@ jobs: run: dotnet nuget enable source github - name: Quality Gate - uses: DynamicsValue/dotnet-sonarscanner@v2.4.7 + uses: DynamicsValue/dotnet-sonarscanner@v2.3 with: - buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 - testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage + buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 + testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage projectKey: ${{ secrets.SONAR_PROJECT_KEY }} projectName: fake-xrm-easy-core sonarOrganisation: ${{ vars.SONAR_ORG_NAME }} diff --git a/.github/workflows/CI-PullRequest-3x.yml b/.github/workflows/CI-PullRequest-3x.yml index 399358fc..8ba3b8ab 100644 --- a/.github/workflows/CI-PullRequest-3x.yml +++ b/.github/workflows/CI-PullRequest-3x.yml @@ -9,7 +9,7 @@ on: - '*.txt' env: - dotnet-version: 6.0.407 + dotnet-version: 3.1.201 source-url: "https://nuget.pkg.github.com/${{github.repository_owner}}/index.json" jobs: @@ -45,7 +45,7 @@ jobs: strategy: fail-fast: false matrix: - configuration: ['FAKE_XRM_EASY_9', 'FAKE_XRM_EASY_365', 'FAKE_XRM_EASY_2016','FAKE_XRM_EASY_2015','FAKE_XRM_EASY_2013'] + configuration: ['FAKE_XRM_EASY_9', 'FAKE_XRM_EASY_365', 'FAKE_XRM_EASY_2016','FAKE_XRM_EASY_2015','FAKE_XRM_EASY_2013','FAKE_XRM_EASY'] runs-on: windows-latest @@ -88,10 +88,10 @@ jobs: run: dotnet nuget enable source github - name: Quality Gate - uses: DynamicsValue/dotnet-sonarscanner@v2.4.7 + uses: DynamicsValue/dotnet-sonarscanner@v2.3 with: - buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 - testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage + buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 + testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage projectKey: ${{ secrets.SONAR_PROJECT_KEY }} projectName: fake-xrm-easy-core sonarOrganisation: ${{ vars.SONAR_ORG_NAME }} diff --git a/.github/workflows/PushNuget-3x.yml b/.github/workflows/PushNuget-3x.yml index c0097849..4e4d955e 100644 --- a/.github/workflows/PushNuget-3x.yml +++ b/.github/workflows/PushNuget-3x.yml @@ -9,7 +9,7 @@ on: - '*.txt' env: - dotnet-version: 6.0.407 + dotnet-version: 3.1.201 source-url: "https://api.nuget.org/v3/index.json" jobs: @@ -85,12 +85,12 @@ jobs: run: dotnet nuget enable source github - name: Quality Gate - uses: DynamicsValue/dotnet-sonarscanner@v2.4.7 + uses: DynamicsValue/dotnet-sonarscanner@v2.3 with: - buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 - testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework net6.0 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage + buildCommand: dotnet build . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 + testCommand: dotnet test . --configuration 'FAKE_XRM_EASY_9' --framework netcoreapp3.1 --verbosity normal --collect:"XPlat code coverage" --settings tests/.runsettings --results-directory ./coverage projectKey: ${{ secrets.SONAR_PROJECT_KEY }} - projectName: fake-xrm-easy-core + projectName: fake-xrm-easy sonarOrganisation: dynamicsvalue beginArguments: > /d:sonar.verbose="true" diff --git a/.vscode/launch.json b/.vscode/launch.json index fd3daa7b..7a8493d2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,9 +8,9 @@ "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", - "preLaunchTask": "build --framework 'net6.0' --configuration 'FAKE_XRM_EASY_9'", + "preLaunchTask": "build --framework 'netcoreapp3.1' --configuration 'FAKE_XRM_EASY_9'", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/tests/bin/FAKE_XRM_EASY_9/net6.0/FakeXrmEasy.Core.Tests.dll", + "program": "${workspaceFolder}/tests/bin/FAKE_XRM_EASY_9/netcoreapp3.1/FakeXrmEasy.Core.Tests.dll", "args": [], "cwd": "${workspaceFolder}/tests", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/.vscode/settings.json b/.vscode/settings.json index cc114589..0f1f801d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "dotnet-test-explorer.testProjectPath": "tests/FakeXrmEasy.Core.Tests", - "dotnet-test-explorer.testArguments": "--framework 'net6.0' --configuration 'FAKE_XRM_EASY_9'", + "dotnet-test-explorer.testArguments": "--framework 'netcoreapp3.1' --configuration 'FAKE_XRM_EASY_9'", "dotnet-test-explorer.enableTelemetry": false } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fdab15e..aec5cde1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,10 @@ - -## [3.5.1] +## [2.5.1] ### Changed - Resolves exception when searching attribute type that contains an alias in query expressions with linked entities - https://github.com/DynamicsValue/fake-xrm-easy/issues/151 -## [3.5.0] +## [2.5.0] ### Added @@ -22,23 +21,22 @@ - Resolves Resolving entity references by Alternate Keys when EntityMetadata doesn't have any Keys. - https://github.com/DynamicsValue/fake-xrm-easy/issues/138 - Resolves an issue where a ConditionExpression with an In operator should to not take array of integers as an input, but instead separate values (thanks Ben and Betim) - https://github.com/DynamicsValue/fake-xrm-easy/issues/96 - Resolves filtering Money attributes by an integer value (thanks Ben and Betim) - https://github.com/DynamicsValue/fake-xrm-easy/issues/64 -- Upgraded DataverseClient dependency to 1.1.22 -## [3.4.2] +## [2.4.2] ### Added - Added link to docs in exceptions - Added some logging in subscription usage for CI builds -## [3.4.1] +## [2.4.1] ### Changed - Should not read subscription usage while in a CI build -## [3.4.0] +## [2.4.0] ## Added @@ -52,7 +50,7 @@ - Update build scripts to use 'all' target frameworks by default - https://github.com/DynamicsValue/fake-xrm-easy/issues/126 - Update github actions to use new Sonar environment variables - https://github.com/DynamicsValue/fake-xrm-easy/issues/120 -## [3.3.3] +## [2.3.3] ### Added @@ -65,22 +63,21 @@ - Upgraded GitHub Actions to update Java major version to run SonarCloud analysis - https://github.com/DynamicsValue/fake-xrm-easy/issues/110 - Introduced new NewEntityRecord method to easily create instances of entity records based on the current use of early-bound or late-bound entities - Resolves an issue with query evaluation and MultiOptionSets when using late bound entities or if type information is not present. - https://github.com/DynamicsValue/fake-xrm-easy/issues/66 - - Update legacy CRM SDK 2011 dependency to use official MS package - https://github.com/DynamicsValue/fake-xrm-easy/issues/105 -## [3.3.1] +## [2.3.2] ### Changed -- Bump DataversClient nuget package to use net6.0 - https://github.com/DynamicsValue/fake-xrm-easy/issues/90 +- Update legacy CRM SDK 2011 dependency to use official MS package - https://github.com/DynamicsValue/fake-xrm-easy/issues/105 -## [3.3.0] +## [2.3.0] ### Changed - Adding tests for MetadataGenerator - https://github.com/DynamicsValue/fake-xrm-easy/issues/77 - Moved GetContextFromSerialisedCompressedProfile method into the Plugins package and FakeXrmEasy.Plugins namespace -## [3.2.0] +## [2.2.0] ### Changed @@ -88,14 +85,13 @@ - Replaced references to PullRequestException by references to UnsupportedExceptionFactory to make it easier raising requests based on the license context - **BREAKING**: In-Memory data dictionary that was defined as a public dictionary is now internal using a rewritten data structure to prepare for parallelization and concurrency. If you were accessing this property, please use the GetEntity or CreateQuery public methods in the IXrmFakedContext interface to query the state of the In-Memory database state instead. For any other use, always rely on the IOrganizationService* interfaces only. This breaking change will affect you only if you were accessing the 'Data' dictionary directly. - Fix Sonar Quality Gate settings: DynamicsValue/fake-xrm-easy#28 + -## [3.1.2] - -- Bump dataverse dependency to production ready version 1.0.1 -## [3.1.1] +## [2.1.1] ### Changed +- Made CRM SDK v8.2 dependencies less specific - DynamicsValue/fake-xrm-easy#21 - Limit FakeItEasy package dependency to v6.x versions - DynamicsValue/fake-xrm-easy#37 - Updated build script to also include the major version in the Title property of the generated .nuspec file - DynamicsValue/fake-xrm-easy#41 - Modified TopCount support in QueryByAttribute and QueryExpression, to not throw exception if PageInfo was set but empty: DynamicsValue/fake-xrm-easy#16 @@ -103,19 +99,12 @@ - Allow creating records with any statecode attribute, which will be overriden by the platform as Active - DynamicsValue/fake-xrm-easy#36 - Both GetEntityById and GetEntityById<T> now clone the entity record before returning it - DynamicsValue/fake-xrm-easy#27 -## [3.1.0] +## [2.1.0] ### Changed -- Added TopCount support in QueryByAttribute, and throw exception if both TopCount and PageInfo are set: DynamicsValue/fake-xrm-easy#16 -- Removed .netcoreapp3.1 target framework in versions 2.x, it'll be supported from versions 3.x onwards. Bump - -## [3.0.2] - -### Changed - -- Bump Dataverse dependency to 0.6.1 from 0.5.10 to solve DynamicsValue/fake-xrm-easy#20 -- Also replaced Microsoft.Dynamics.Sdk.Messages dependency, as it has also been deprecated by MSFT, to Microsoft.PowerPlatform.Dataverse.Client.Dynamics 0.6.1 DynamicsValue/fake-xrm-easy#20 - -## [3.0.1-rc1] - Initial release +Added TopCount support in QueryByAttribute, and throw exception if both TopCount and PageInfo are set: DynamicsValue/fake-xrm-easy#16 +Removed .netcoreapp3.1 target framework in versions 2.x, it'll be supported from versions 3.x onwards. +Bump Microsoft.CrmSdk.CoreAssemblies to version 9.0.2.27 to support plugin telemetry - DynamicsValue/fake-xrm-easy#24 +## [2.0.1-rc1] - Initial release \ No newline at end of file diff --git a/README.md b/README.md index 9ea7b93f..c38440d0 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,6 @@ When you submit a pull request, a CLA-bot will automatically determine whether y ## License ------------------- -Please see [LICENSE.txt](https://github.com/DynamicsValue/fake-xrm-easy/blob/main/LICENSE.txt). +Please see [LICENSE.txt](https://github.com/DynamicsValue/fake-xrm-easy/blob/master/LICENSE.txt). License questions? Please see our [License FAQ](https://github.com/DynamicsValue/licence-agreements/blob/main/FakeXrmEasy/FAQ.md). \ No newline at end of file diff --git a/pack-configuration.ps1 b/pack-configuration.ps1 index ed3ce4d0..b00c437d 100644 --- a/pack-configuration.ps1 +++ b/pack-configuration.ps1 @@ -1,6 +1,6 @@ param ( [string]$versionSuffix = "", - [string]$targetFrameworks = "net6.0", + [string]$targetFrameworks = "netcoreapp3.1", [string]$configuration = "FAKE_XRM_EASY_9", [string]$projectName = "FakeXrmEasy.Core", [string]$projectPath = "src/FakeXrmEasy.Core", diff --git a/pack-push.ps1 b/pack-push.ps1 index d21ad852..01b62d7e 100644 --- a/pack-push.ps1 +++ b/pack-push.ps1 @@ -1,7 +1,7 @@ param ( [string]$packageSource = "local-packages", [string]$versionSuffix = "", - [string]$targetFrameworks = "net6.0" + [string]$targetFrameworks = "netcoreapp3.1" ) Write-Host "Running with versionSuffix '$($versionSuffix)'..." diff --git a/pack-src.ps1 b/pack-src.ps1 index 699f5d90..82767562 100644 --- a/pack-src.ps1 +++ b/pack-src.ps1 @@ -1,6 +1,6 @@ param ( [string]$versionSuffix = "", - [string]$targetFrameworks = "net6.0" + [string]$targetFrameworks = "netcoreapp3.1" ) Write-Host "Running with versionSuffix '$($versionSuffix)'..." @@ -13,12 +13,18 @@ $projectPath = "src/FakeXrmEasy.Core" Write-Host "Packing All Configurations for project $($projectName)" -ForegroundColor Green -# ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2013" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2015" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2016" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_365" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_9" - + if($targetFrameworks -eq "netcoreapp3.1") + { + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_365" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_9" + } + else { + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2013" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2015" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_2016" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_365" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -configuration "FAKE_XRM_EASY_9" + } Write-Host "Pack Succeeded :)" -ForegroundColor Green \ No newline at end of file diff --git a/pack-tests.ps1 b/pack-tests.ps1 index 17d9fc30..fdc9c768 100644 --- a/pack-tests.ps1 +++ b/pack-tests.ps1 @@ -1,6 +1,6 @@ param ( [string]$versionSuffix = "", - [string]$targetFrameworks = "net6.0" + [string]$targetFrameworks = "netcoreapp3.1" ) Write-Host "Running with versionSuffix '$($versionSuffix)'..." @@ -13,11 +13,18 @@ $projectPath = "tests/FakeXrmEasy.Core.Tests" Write-Host "Packing All Configurations for project $($projectName)" -ForegroundColor Green -# ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2013" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2015" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2016" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_365" -./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_9" - + if($targetFrameworks -eq "netcoreapp3.1") + { + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_365" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_9" + } + else { + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2013" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2015" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_2016" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_365" + ./pack-configuration.ps1 -targetFramework $targetFrameworks -projectName $projectName -projectPath $projectPath -packageIdPrefix $packageIdPrefix -versionSuffix $versionSuffix -packTests "true" -configuration "FAKE_XRM_EASY_9" + } + Write-Host "Pack Succeeded :)" -ForegroundColor Green \ No newline at end of file diff --git a/scripts-dotnet/GetAssemblyName.cs b/scripts-dotnet/GetAssemblyName.cs index 7191ad93..0f43ba69 100644 --- a/scripts-dotnet/GetAssemblyName.cs +++ b/scripts-dotnet/GetAssemblyName.cs @@ -1 +1 @@ -Console.WriteLine(System.Reflection.Assembly.LoadFile("/home/jordi/code/DynamicsValue/fake-xrm-easy-core/tests/FakeXrmEasy.Core.Tests/bin/FAKE_XRM_EASY_9/net6.0/FakeXrmEasy.Core.Tests.dll").FullName); \ No newline at end of file +Console.WriteLine(System.Reflection.Assembly.LoadFile("/home/jordi/code/DynamicsValue/fake-xrm-easy-core/tests/FakeXrmEasy.Core.Tests/bin/FAKE_XRM_EASY_9/netcoreapp3.1/FakeXrmEasy.Core.Tests.dll").FullName); \ No newline at end of file diff --git a/src/FakeXrmEasy.Core/Extensions/OptionSetValueCollectionExtensions.cs b/src/FakeXrmEasy.Core/Extensions/OptionSetValueCollectionExtensions.cs index 57e5743b..4236aef1 100644 --- a/src/FakeXrmEasy.Core/Extensions/OptionSetValueCollectionExtensions.cs +++ b/src/FakeXrmEasy.Core/Extensions/OptionSetValueCollectionExtensions.cs @@ -36,19 +36,19 @@ public static HashSet ConvertToHashSetOfInt(this object input, bool isOptio if (input is int) { - set = new HashSet(new int[] {(int)input}); + set.Add((int)input); } else if (input is string) { - set = new HashSet(new int[] { int.Parse(input as string) }); + set.Add(int.Parse(input as string)); } else if (input is int[]) { - set = new HashSet(input as int[]); + set.UnionWith(input as int[]); } else if (input is string[]) { - set = new HashSet((input as string[]).Select(s => int.Parse(s))); + set.UnionWith((input as string[]).Select(s => int.Parse(s))); } else if (input is DataCollection) { @@ -56,19 +56,19 @@ public static HashSet ConvertToHashSetOfInt(this object input, bool isOptio if (collection.All(o => o is int)) { - set = new HashSet(collection.Cast()); + set.UnionWith(collection.Cast()); } else if (collection.All(o => o is string)) { - set = new HashSet(collection.Select(o => int.Parse(o as string))); + set.UnionWith(collection.Select(o => int.Parse(o as string))); } else if (collection.Count == 1 && collection[0] is int[]) { - set = new HashSet(collection[0] as int[]); + set.UnionWith(collection[0] as int[]); } else if (collection.Count == 1 && collection[0] is string[]) { - set = new HashSet((collection[0] as string[]).Select(s => int.Parse(s))); + set.UnionWith((collection[0] as string[]).Select(s => int.Parse(s))); } else { @@ -77,7 +77,7 @@ public static HashSet ConvertToHashSetOfInt(this object input, bool isOptio } else if (isOptionSetValueCollectionAccepted && input is OptionSetValueCollection) { - set = new HashSet((input as OptionSetValueCollection).Select(osv => osv.Value)); + set.UnionWith((input as OptionSetValueCollection).Select(osv => osv.Value)); } else if (typeof(IEnumerable).IsAssignableFrom(type)) { diff --git a/src/FakeXrmEasy.Core/FakeXrmEasy.Core.csproj b/src/FakeXrmEasy.Core/FakeXrmEasy.Core.csproj index a7c67f9b..dfc0c1ca 100644 --- a/src/FakeXrmEasy.Core/FakeXrmEasy.Core.csproj +++ b/src/FakeXrmEasy.Core/FakeXrmEasy.Core.csproj @@ -1,14 +1,14 @@ - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 + net462 + net462;net452 + net452 + net452 + net452 + net452 FakeXrmEasy.Core - 3.5.1 + 2.5.1 Jordi Montaña Dynamics Value FakeXrmEasy Core @@ -56,13 +56,45 @@ DEBUG;TRACE;FAKE_XRM_EASY_9;FXE_V2 - - $(DefineConstants);NETCOREAPP3_1;FAKE_XRM_EASY_NETCORE - + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -70,25 +102,22 @@ - + - + - + - + - + - - - - + diff --git a/src/FakeXrmEasy.Core/Middleware/MiddlewareBuilder.cs b/src/FakeXrmEasy.Core/Middleware/MiddlewareBuilder.cs index b0ee1d01..2648dba8 100644 --- a/src/FakeXrmEasy.Core/Middleware/MiddlewareBuilder.cs +++ b/src/FakeXrmEasy.Core/Middleware/MiddlewareBuilder.cs @@ -10,9 +10,6 @@ using FakeXrmEasy.Abstractions.Integrity; using FakeXrmEasy.Abstractions.Enums; using FakeXrmEasy.Abstractions.Exceptions; -using Microsoft.Xrm.Sdk.Query; -using Microsoft.PowerPlatform.Dataverse.Client; -using System.Threading; using FakeXrmEasy.Core.CommercialLicense; using FakeXrmEasy.Core.Exceptions; @@ -123,13 +120,6 @@ public IXrmFakedContext Build() A.CallTo(() => service.Execute(A._)) .ReturnsLazily((OrganizationRequest request) => app.Invoke(_context, request)); - var serviceAsync = _context.GetAsyncOrganizationService(); - AddOrganizationServiceAsyncFake(serviceAsync); - - var serviceAsync2 = _context.GetAsyncOrganizationService2(); - AddOrganizationServiceAsyncFake(serviceAsync2); - AddOrganizationServiceAsyncFake2(serviceAsync2); - return _context; } @@ -163,95 +153,5 @@ public IMiddlewareBuilder SetSubscriptionStorageProvider(ISubscriptionStoragePro Console.WriteLine($"Setting Subscription Storage Provider ok."); return this; } - - private void AddOrganizationServiceAsyncFake(IOrganizationServiceAsync serviceAsync) - { - var service = _context.GetOrganizationService(); - - A.CallTo(() => serviceAsync.Create(A._)) - .ReturnsLazily((Entity entity) => service.Create(entity)); - - A.CallTo(() => serviceAsync.CreateAsync(A._)) - .ReturnsLazily((Entity entity) => service.Create(entity)); - - A.CallTo(() => serviceAsync.Update(A._)) - .Invokes((Entity entity) => service.Update(entity)); - - A.CallTo(() => serviceAsync.UpdateAsync(A._)) - .Invokes((Entity entity) => service.Update(entity)); - - A.CallTo(() => serviceAsync.Delete(A._, A._)) - .Invokes((string entityLogicalName, Guid id) => service.Delete(entityLogicalName, id)); - - A.CallTo(() => serviceAsync.DeleteAsync(A._, A._)) - .Invokes((string entityLogicalName, Guid id) => service.Delete(entityLogicalName, id)); - - A.CallTo(() => serviceAsync.Retrieve(A._, A._, A._)) - .ReturnsLazily((string entityLogicalName, Guid id, ColumnSet columnSet) => service.Retrieve(entityLogicalName, id, columnSet)); - - A.CallTo(() => serviceAsync.RetrieveAsync(A._, A._, A._)) - .ReturnsLazily((string entityLogicalName, Guid id, ColumnSet columnSet) => service.Retrieve(entityLogicalName, id, columnSet)); - - A.CallTo(() => serviceAsync.RetrieveMultiple(A._)) - .ReturnsLazily((QueryBase query) => service.RetrieveMultiple(query)); - - A.CallTo(() => serviceAsync.RetrieveMultipleAsync(A._)) - .ReturnsLazily((QueryBase query) => service.RetrieveMultiple(query)); - - A.CallTo(() => serviceAsync.ExecuteAsync(A._)) - .ReturnsLazily((OrganizationRequest request) => service.Execute(request)); - - A.CallTo(() => serviceAsync.Execute(A._)) - .ReturnsLazily((OrganizationRequest request) => service.Execute(request)); - - A.CallTo(() => serviceAsync.AssociateAsync(A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection) - => service.Associate(entityLogicalName, id, relationship, entityRefCollection )); - - A.CallTo(() => serviceAsync.Associate(A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection) - => service.Associate(entityLogicalName, id, relationship, entityRefCollection )); - - A.CallTo(() => serviceAsync.DisassociateAsync(A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection) - => service.Disassociate(entityLogicalName, id, relationship, entityRefCollection )); - - A.CallTo(() => serviceAsync.Disassociate(A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection) - => service.Disassociate(entityLogicalName, id, relationship, entityRefCollection )); - - } - - private void AddOrganizationServiceAsyncFake2(IOrganizationServiceAsync2 serviceAsync) - { - var service = _context.GetOrganizationService(); - - A.CallTo(() => serviceAsync.CreateAsync(A._, A._)) - .ReturnsLazily((Entity entity, CancellationToken token) => service.Create(entity)); - - A.CallTo(() => serviceAsync.UpdateAsync(A._, A._)) - .Invokes((Entity entity, CancellationToken token) => service.Update(entity)); - - A.CallTo(() => serviceAsync.DeleteAsync(A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, CancellationToken token) => service.Delete(entityLogicalName, id)); - - A.CallTo(() => serviceAsync.RetrieveAsync(A._, A._, A._, A._)) - .ReturnsLazily((string entityLogicalName, Guid id, ColumnSet columnSet, CancellationToken token) => service.Retrieve(entityLogicalName, id, columnSet)); - - A.CallTo(() => serviceAsync.RetrieveMultipleAsync(A._, A._)) - .ReturnsLazily((QueryBase query, CancellationToken token) => service.RetrieveMultiple(query)); - - A.CallTo(() => serviceAsync.ExecuteAsync(A._, A._)) - .ReturnsLazily((OrganizationRequest request, CancellationToken token) => service.Execute(request)); - - A.CallTo(() => serviceAsync.AssociateAsync(A._, A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection, CancellationToken token) - => service.Associate(entityLogicalName, id, relationship, entityRefCollection )); - - A.CallTo(() => serviceAsync.DisassociateAsync(A._, A._, A._, A._, A._)) - .Invokes((string entityLogicalName, Guid id, Relationship relationship, EntityReferenceCollection entityRefCollection, CancellationToken token) - => service.Disassociate(entityLogicalName, id, relationship, entityRefCollection )); - - } } } diff --git a/src/FakeXrmEasy.Core/XrmFakedContext.Async.cs b/src/FakeXrmEasy.Core/XrmFakedContext.Async.cs deleted file mode 100644 index 6944c7b6..00000000 --- a/src/FakeXrmEasy.Core/XrmFakedContext.Async.cs +++ /dev/null @@ -1,38 +0,0 @@ -using FakeXrmEasy.Abstractions; -using Microsoft.PowerPlatform.Dataverse.Client; - -namespace FakeXrmEasy -{ - public partial class XrmFakedContext : IXrmFakedContext - { - /// - /// Stores a reference of an IOrganizationServiceAsync interface without cancellation token support - /// - protected internal readonly IOrganizationServiceAsync _serviceAsync; - - /// - /// Reference to an async IOrganizationService instance with cancellation token support - /// - protected internal readonly IOrganizationServiceAsync2 _serviceAsync2; - - /// - /// Gets an IOrganizationService interface with async support and without cancellation tokens - /// See https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/advanced/async/ for more details. - /// - /// - public IOrganizationServiceAsync GetAsyncOrganizationService() - { - return _serviceAsync; - } - - /// - /// Gets an IOrganizationService interface with async support and cancellation tokens - /// See https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/advanced/async/ for more details. - /// - /// - public IOrganizationServiceAsync2 GetAsyncOrganizationService2() - { - return _serviceAsync2; - } - } -} \ No newline at end of file diff --git a/src/FakeXrmEasy.Core/XrmFakedContext.cs b/src/FakeXrmEasy.Core/XrmFakedContext.cs index e2a564b7..7bcc9de6 100644 --- a/src/FakeXrmEasy.Core/XrmFakedContext.cs +++ b/src/FakeXrmEasy.Core/XrmFakedContext.cs @@ -12,7 +12,6 @@ using FakeXrmEasy.Middleware.Messages; using FakeXrmEasy.Permissions; using FakeXrmEasy.Services; -using Microsoft.PowerPlatform.Dataverse.Client; using Microsoft.Xrm.Sdk; using System; using System.Collections.Generic; @@ -156,8 +155,6 @@ public XrmFakedContext(FakeXrmEasyLicense? license = null) _fakeTracingService = new XrmFakedTracingService(); _properties = new Dictionary(); _service = A.Fake(); - _serviceAsync = A.Fake(); - _serviceAsync2 = A.Fake(); _builder = MiddlewareBuilder .New(this) @@ -186,8 +183,6 @@ internal XrmFakedContext(IMiddlewareBuilder middlewareBuilder) _fakeTracingService = new XrmFakedTracingService(); _properties = new Dictionary(); _service = A.Fake(); - _serviceAsync = A.Fake(); - _serviceAsync2 = A.Fake(); Init(); } diff --git a/src/FakeXrmEasy.Core/XrmRealContext.cs b/src/FakeXrmEasy.Core/XrmRealContext.cs index 63409b67..69f06ad5 100644 --- a/src/FakeXrmEasy.Core/XrmRealContext.cs +++ b/src/FakeXrmEasy.Core/XrmRealContext.cs @@ -17,7 +17,7 @@ using FakeXrmEasy.Abstractions.Exceptions; #if FAKE_XRM_EASY_NETCORE -using Microsoft.PowerPlatform.Dataverse.Client; +using Microsoft.Powerplatform.Cds.Client; #elif FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9 using Microsoft.Xrm.Tooling.Connector; #else @@ -34,24 +34,14 @@ namespace FakeXrmEasy public class XrmRealContext : IXrmRealContext { /// - /// The current license context + /// /// public FakeXrmEasyLicense? LicenseContext { get; set; } /// /// /// - private readonly string _connectionString; - - /// - /// Reference to an actual IOrganizationService - /// - protected IOrganizationService _service; - - /// - /// Reference to an IOrganizationService instance without cancellation tokens - /// - protected IOrganizationServiceAsync _serviceAsync; + public string ConnectionStringName { get; set; } = "fakexrmeasy-connection"; /// /// Use these user to impersonate calls @@ -66,7 +56,7 @@ public class XrmRealContext : IXrmRealContext /// /// Internal reference to an IOrganizationService. /// - protected IOrganizationServiceAsync2 _serviceAsync2; + protected IOrganizationService _service; /// /// A fake tracing service if one is needed @@ -76,12 +66,20 @@ public class XrmRealContext : IXrmRealContext private Dictionary _properties; /// - /// A constructor that will use connection string + /// A default constructor that will use a connection string with name fakexrmeasy-connection to establish a real connection to an environment for integration testing purposes /// - /// - public XrmRealContext(string connectionString) + public XrmRealContext() { - _connectionString = connectionString; + Init(); + } + + /// + /// A constructor that will use a different connection string name + /// + /// + public XrmRealContext(string connectionStringName) + { + ConnectionStringName = connectionStringName; Init(); } @@ -89,13 +87,9 @@ public XrmRealContext(string connectionString) /// Creates an XrmRealContext that uses the specified IOrganizationService interface /// /// - /// - /// - public XrmRealContext(IOrganizationService organizationService, IOrganizationServiceAsync serviceAsync = null, IOrganizationServiceAsync2 serviceAsync2 = null) + public XrmRealContext(IOrganizationService organizationService) { _service = organizationService; - _serviceAsync = serviceAsync; - _serviceAsync2 = serviceAsync2; Init(); } @@ -110,7 +104,7 @@ private void Init() } /// - /// Returns true if the property exists in this XrmRealContext + /// /// /// /// @@ -120,7 +114,7 @@ public bool HasProperty() } /// - /// Returns a property from this XrmRealContext + /// /// /// /// @@ -136,7 +130,7 @@ public T GetProperty() } /// - /// Sets a property to this XrmRealContext + /// /// /// /// @@ -171,45 +165,32 @@ public IOrganizationService GetOrganizationService() } /// - /// Returns an IOrganizationServiceAsync instance that uses the underlying connectionString, without cancellation tokens - /// - /// - public IOrganizationServiceAsync GetAsyncOrganizationService() - { - if (_serviceAsync != null) - return _serviceAsync; - - _serviceAsync = GetOrgService(); - return _serviceAsync; - } - - /// - /// Returns an IOrganizationServiceAsync instance that uses the underlying connectionString, with cancellation tokens + /// /// /// - public IOrganizationServiceAsync2 GetAsyncOrganizationService2() + /// + protected IOrganizationService GetOrgService() { - if (_serviceAsync2 != null) - return _serviceAsync2; + var connection = ConfigurationManager.ConnectionStrings[ConnectionStringName]; - _serviceAsync2 = GetOrgService(); - return _serviceAsync2; - } + // In case of missing connection string in configuration, + // use ConnectionStringName as an explicit connection string + var connectionString = connection == null ? ConnectionStringName : connection.ConnectionString; - /// - /// Internal method to retrieve an instance of an organization service - /// - /// - /// - protected ServiceClient GetOrgService() - { - if (string.IsNullOrWhiteSpace(_connectionString)) + if (string.IsNullOrWhiteSpace(connectionString)) { - throw new Exception("The ConnectionString property is null or empty"); + throw new Exception("The ConnectionStringName property must be either a connection string or a connection string name"); } - // Connect to the Dataverse with a connection string. - var client = new ServiceClient(_connectionString); + // Connect to the CRM web service using a connection string. +#if FAKE_XRM_EASY_NETCORE + var client = new CdsServiceClient(connectionString); +#elif FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9 + var client = new CrmServiceClient(connectionString); +#else + CrmConnection crmConnection = CrmConnection.Parse(connectionString); + var client = new OrganizationService(crmConnection); +#endif return client; } diff --git a/tests/DataverseEntities/DataverseEntities.csproj b/tests/DataverseEntities/DataverseEntities.csproj index c6d3f401..d1924fe2 100644 --- a/tests/DataverseEntities/DataverseEntities.csproj +++ b/tests/DataverseEntities/DataverseEntities.csproj @@ -1,12 +1,12 @@ - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 + net462 + net462;net452 + net452 + net452 + net452 + net452 FAKE_XRM_EASY;FAKE_XRM_EASY_2013;FAKE_XRM_EASY_2015;FAKE_XRM_EASY_2016;FAKE_XRM_EASY_365;FAKE_XRM_EASY_9 ..\..\fakexrmeasy.snk @@ -37,8 +37,45 @@ DEBUG;TRACE; - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/FakeXrmEasy.Core.Tests/FakeContextTests/FakeContextMockTests.cs b/tests/FakeXrmEasy.Core.Tests/FakeContextTests/FakeContextMockTests.cs index 74e59ed2..f7bec4a9 100644 --- a/tests/FakeXrmEasy.Core.Tests/FakeContextTests/FakeContextMockTests.cs +++ b/tests/FakeXrmEasy.Core.Tests/FakeContextTests/FakeContextMockTests.cs @@ -1 +1 @@ -/* Moved to FakeXrmEasy.Tests.Middleware.MiddlewareBuilderTests */ +/* Moved to FakeXrmEasy.Tests.Middleware.MiddlewareBuilderTests */ \ No newline at end of file diff --git a/tests/FakeXrmEasy.Core.Tests/FakeXrmEasy.Core.Tests.csproj b/tests/FakeXrmEasy.Core.Tests/FakeXrmEasy.Core.Tests.csproj index 098e0a4b..2ab2cc4f 100644 --- a/tests/FakeXrmEasy.Core.Tests/FakeXrmEasy.Core.Tests.csproj +++ b/tests/FakeXrmEasy.Core.Tests/FakeXrmEasy.Core.Tests.csproj @@ -1,17 +1,17 @@  - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 - net6.0 + net462 + net462;net452 + net452 + net452 + net452 + net452 true FakeXrmEasy.CoreTests - 3.5.1 + 2.5.1 Jordi Montaña Dynamics Value S.L. Internal Unit test suite for FakeXrmEasy.Core package @@ -62,16 +62,48 @@ + + + + + - - $(DefineConstants);NETCOREAPP3_1;FAKE_XRM_EASY_NETCORE - + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -82,25 +114,22 @@ - + - + - + - + - + - - - - + @@ -108,22 +137,22 @@ - + - + - + - + - + - + diff --git a/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsync2Tests.cs b/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsync2Tests.cs deleted file mode 100644 index bb399f2d..00000000 --- a/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsync2Tests.cs +++ /dev/null @@ -1,133 +0,0 @@ - - -using System; -using System.Collections.Generic; -using System.Threading; -using Crm; -using FakeItEasy; -using Microsoft.PowerPlatform.Dataverse.Client; -using Microsoft.Xrm.Sdk; -using Microsoft.Xrm.Sdk.Messages; -using Microsoft.Xrm.Sdk.Query; -using Xunit; - -namespace FakeXrmEasy.Core.Tests.Middleware -{ - public class OrganizationServiceAsync2Tests : OrganizationServiceAsyncTests - { - protected IOrganizationServiceAsync2 _serviceAsync2; - - public OrganizationServiceAsync2Tests() : base() - { - _serviceAsync2 = _context.GetAsyncOrganizationService2(); - } - - protected override void InitServiceAsync() - { - _serviceAsync = _context.GetAsyncOrganizationService2(); - } - - [Fact] - public async void Should_call_create_when_calling_async_create_with_cancellation() - { - var asyncResult = await _serviceAsync2.CreateAsync(_contact, new CancellationToken()); - - A.CallTo(() => _service.Create(_contact)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_update_when_calling_async_update_with_cancellation() - { - _context.Initialize(_contact); - - var entity = new Contact() { Id = _contact.Id, FirstName = "New Name" }; - await _serviceAsync2.UpdateAsync(entity, new CancellationToken()); - - A.CallTo(() => _service.Update(entity)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_delete_when_calling_async_delete_with_cancellation() - { - _context.Initialize(_contact); - - await _serviceAsync2.DeleteAsync(Contact.EntityLogicalName, _contact.Id, new CancellationToken()); - - A.CallTo(() => _service.Delete(Contact.EntityLogicalName, _contact.Id)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_retrieve_when_calling_async_retrieve_with_cancellation() - { - _context.Initialize(_contact); - - var allColumns = new ColumnSet(true); - var entity = await _serviceAsync2.RetrieveAsync(Contact.EntityLogicalName, _contact.Id, allColumns, new CancellationToken()); - - A.CallTo(() => _service.Retrieve(Contact.EntityLogicalName, _contact.Id, allColumns)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_retrieve_multiple_when_calling_async_retrieve_multiple_with_cancellation() - { - _context.Initialize(_contact); - - var queryByAttribute = new QueryByAttribute(Contact.EntityLogicalName); - queryByAttribute.ColumnSet = new ColumnSet(true); - queryByAttribute.Attributes.AddRange("firstname"); - queryByAttribute.Values.AddRange("Lionel"); - - var entityCollection = await _serviceAsync2.RetrieveMultipleAsync(queryByAttribute, new CancellationToken()); - - A.CallTo(() => _service.RetrieveMultiple(queryByAttribute)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_execute_when_calling_async_execute_with_cancellation() - { - var request = new CreateRequest() { Target = _contact }; - - var asyncResult = await _serviceAsync2.ExecuteAsync(request, new CancellationToken()); - - A.CallTo(() => _service.Execute(request)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_associate_when_calling_async_associate_with_cancellation() - { - _context.Initialize(new List() { _team, _user }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - await _serviceAsync2.AssociateAsync(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities, new CancellationToken()); - - A.CallTo(() => _service.Associate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_disassociate_when_calling_async_disassociate_with_cancellation() - { - var intersect = new TeamMembership() - { - Id = Guid.NewGuid(), - ["teamid"] = _team.Id, - ["systemuserid"] = _user.Id - }; - _context.Initialize(new List() { _team, _user, intersect }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - await _serviceAsync2.DisassociateAsync(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities, new CancellationToken()); - - A.CallTo(() => _service.Disassociate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - } -} \ No newline at end of file diff --git a/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsyncTests.cs b/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsyncTests.cs deleted file mode 100644 index 102e8aa0..00000000 --- a/tests/FakeXrmEasy.Core.Tests/Middleware/OrganizationServiceAsyncTests.cs +++ /dev/null @@ -1,264 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using Crm; -using FakeItEasy; -using FakeXrmEasy.Abstractions; -using Microsoft.PowerPlatform.Dataverse.Client; -using Microsoft.Xrm.Sdk; -using Microsoft.Xrm.Sdk.Messages; -using Microsoft.Xrm.Sdk.Query; -using Xunit; - -namespace FakeXrmEasy.Core.Tests.Middleware -{ - public class OrganizationServiceAsyncTests : FakeXrmEasyTestsBase - { - protected readonly Account _account; - protected readonly Contact _contact; - protected IOrganizationServiceAsync _serviceAsync; - protected readonly SystemUser _user; - protected readonly SystemUser _user2; - protected readonly Team _team; - - public OrganizationServiceAsyncTests() : base() - { - InitServiceAsync(); - - _contact = new Contact() { Id = Guid.NewGuid() }; - _account = new Account() { Id = Guid.NewGuid() }; - - _context.EnableProxyTypes(Assembly.GetAssembly(typeof(Contact))); - - _context.AddRelationship("teammembership", new XrmFakedRelationship() - { - RelationshipType = XrmFakedRelationship.FakeRelationshipType.ManyToMany, - IntersectEntity = "teammembership", - Entity1Attribute = "systemuserid", - Entity1LogicalName = "systemuser", - Entity2Attribute = "teamid", - Entity2LogicalName = "team" - }); - - _user = new SystemUser() { Id = Guid.NewGuid() }; - _user2 = new SystemUser() { Id = Guid.NewGuid() }; - _team = new Team() { Id = Guid.NewGuid() }; - - } - - protected virtual void InitServiceAsync() - { - _serviceAsync = _context.GetAsyncOrganizationService(); - } - - [Fact] - public async void Should_call_create_when_calling_async_create() - { - var asyncResult = await _serviceAsync.CreateAsync(_contact); - - A.CallTo(() => _service.Create(_contact)).MustHaveHappened(); - } - - [Fact] - public void Should_call_create_when_calling_sync_create() - { - var asyncResult = _serviceAsync.Create(_contact); - - A.CallTo(() => _service.Create(_contact)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_update_when_calling_async_update() - { - _context.Initialize(_contact); - - var entity = new Contact() { Id = _contact.Id, FirstName = "New Name" }; - await _serviceAsync.UpdateAsync(entity); - - A.CallTo(() => _service.Update(entity)).MustHaveHappened(); - } - - [Fact] - public void Should_call_update_when_calling_sync_update() - { - _context.Initialize(_contact); - - var entity = new Contact() { Id = _contact.Id, FirstName = "New Name" }; - _serviceAsync.Update(entity); - - A.CallTo(() => _service.Update(entity)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_delete_when_calling_async_delete() - { - _context.Initialize(_contact); - - await _serviceAsync.DeleteAsync(Contact.EntityLogicalName, _contact.Id); - - A.CallTo(() => _service.Delete(Contact.EntityLogicalName, _contact.Id)).MustHaveHappened(); - } - - [Fact] - public void Should_call_delete_when_calling_sync_delete() - { - _context.Initialize(_contact); - - _serviceAsync.Delete(Contact.EntityLogicalName, _contact.Id); - - A.CallTo(() => _service.Delete(Contact.EntityLogicalName, _contact.Id)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_retrieve_when_calling_async_retrieve() - { - _context.Initialize(_contact); - - var allColumns = new ColumnSet(true); - var entity = await _serviceAsync.RetrieveAsync(Contact.EntityLogicalName, _contact.Id, allColumns); - - A.CallTo(() => _service.Retrieve(Contact.EntityLogicalName, _contact.Id, allColumns)).MustHaveHappened(); - } - - [Fact] - public void Should_call_retrieve_when_calling_sync_retrieve() - { - _context.Initialize(_contact); - - var allColumns = new ColumnSet(true); - var entity = _serviceAsync.Retrieve(Contact.EntityLogicalName, _contact.Id, allColumns); - - A.CallTo(() => _service.Retrieve(Contact.EntityLogicalName, _contact.Id, allColumns)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_retrieve_multiple_when_calling_async_retrieve_multiple() - { - _context.Initialize(_contact); - - var queryByAttribute = new QueryByAttribute(Contact.EntityLogicalName); - queryByAttribute.ColumnSet = new ColumnSet(true); - queryByAttribute.Attributes.AddRange("firstname"); - queryByAttribute.Values.AddRange("Lionel"); - - var entityCollection = await _serviceAsync.RetrieveMultipleAsync(queryByAttribute); - - A.CallTo(() => _service.RetrieveMultiple(queryByAttribute)).MustHaveHappened(); - } - - [Fact] - public void Should_call_retrieve_multiple_when_calling_sync_retrieve_multiple() - { - _context.Initialize(_contact); - - var queryByAttribute = new QueryByAttribute(Contact.EntityLogicalName); - queryByAttribute.ColumnSet = new ColumnSet(true); - queryByAttribute.Attributes.AddRange("firstname"); - queryByAttribute.Values.AddRange("Lionel"); - - var entity = _serviceAsync.RetrieveMultiple(queryByAttribute); - - A.CallTo(() => _service.RetrieveMultiple(queryByAttribute)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_execute_when_calling_async_execute() - { - var request = new CreateRequest() { Target = _contact }; - - var asyncResult = await _serviceAsync.ExecuteAsync(request); - - A.CallTo(() => _service.Execute(request)).MustHaveHappened(); - } - - [Fact] - public void Should_call_execute_when_calling_sync_execute() - { - var request = new CreateRequest() { Target = _contact }; - - var asyncResult = _serviceAsync.Execute(request); - - A.CallTo(() => _service.Execute(request)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_associate_when_calling_async_associate() - { - _context.Initialize(new List() { _team, _user }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - await _serviceAsync.AssociateAsync(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities); - - A.CallTo(() => _service.Associate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - - [Fact] - public void Should_associate_execute_when_calling_sync_associate() - { - _context.Initialize(new List() { _team, _user }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - _serviceAsync.Associate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities); - - A.CallTo(() => _service.Associate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - - [Fact] - public async void Should_call_disassociate_when_calling_async_disassociate() - { - var intersect = new TeamMembership() - { - Id = Guid.NewGuid(), - ["teamid"] = _team.Id, - ["systemuserid"] = _user.Id - }; - _context.Initialize(new List() { _team, _user, intersect }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - await _serviceAsync.DisassociateAsync(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities); - - A.CallTo(() => _service.Disassociate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - - [Fact] - public void Should_disassociate_execute_when_calling_sync_disassociate() - { - var intersect = new TeamMembership() - { - Id = Guid.NewGuid(), - ["teamid"] = _team.Id, - ["systemuserid"] = _user.Id - }; - _context.Initialize(new List() { _team, _user, intersect }); - - var relationShip = new Relationship("teammembership"); - var relatedEntities = new EntityReferenceCollection() - { - new EntityReference(SystemUser.EntityLogicalName, _user.Id), - }; - - _serviceAsync.Disassociate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities); - - A.CallTo(() => _service.Disassociate(Team.EntityLogicalName, _team.Id, relationShip, relatedEntities)).MustHaveHappened(); - } - } - - - - -} diff --git a/tests/FakeXrmEasy.Core.Tests/XrmRealContextTests/XrmRealContextTests.cs b/tests/FakeXrmEasy.Core.Tests/XrmRealContextTests/XrmRealContextTests.cs index 7ba1cc60..4944d4e3 100644 --- a/tests/FakeXrmEasy.Core.Tests/XrmRealContextTests/XrmRealContextTests.cs +++ b/tests/FakeXrmEasy.Core.Tests/XrmRealContextTests/XrmRealContextTests.cs @@ -1,5 +1,4 @@ -using FakeXrmEasy.Abstractions.Enums; -using Microsoft.PowerPlatform.Dataverse.Client; +using FakeXrmEasy.Abstractions.Enums; using FakeXrmEasy.Abstractions.Exceptions; using System; using Xunit; @@ -9,14 +8,10 @@ namespace FakeXrmEasy.Core.Tests.XrmRealContextTests public class XrmRealContextTests: FakeXrmEasyTestsBase { private readonly XrmRealContext _realContext; - private readonly IOrganizationServiceAsync _serviceAsync; - private readonly IOrganizationServiceAsync2 _serviceAsync2; public XrmRealContextTests() : base() { _realContext = new XrmRealContext(_service); - _serviceAsync = _context.GetAsyncOrganizationService(); - _serviceAsync2 = _context.GetAsyncOrganizationService2(); _realContext.LicenseContext = FakeXrmEasyLicense.RPL_1_5; } @@ -25,6 +20,13 @@ private class CustomProperty } + [Fact] + public void Should_connect_to_CRM_with_given_ConnectionString() + { + var ctx = new XrmRealContext("myfirstconnectionstring"); + Assert.Equal("myfirstconnectionstring", ctx.ConnectionStringName); + } + [Fact] public void Should_return_service_that_was_injected_in_the_constructor() { @@ -70,48 +72,16 @@ public void Should_return_fake_tracing_service() } [Fact] - public void Should_return_license_exception_if_not_set_when_getting_an_organization_service() - { - var ctx = new XrmRealContext(_service); - Assert.Throws(() => ctx.GetOrganizationService()); - } - - [Fact] - public void Should_retrieve_fake_organization_service() - { - var ctx = new XrmRealContext(_service, _serviceAsync, _serviceAsync2); - ctx.LicenseContext = FakeXrmEasyLicense.RPL_1_5; - - Assert.Equal(_service, ctx.GetOrganizationService()); - Assert.Equal(_serviceAsync, ctx.GetAsyncOrganizationService()); - Assert.Equal(_serviceAsync2, ctx.GetAsyncOrganizationService2()); - } - - [Fact] - public void Should_return_false_if_context_doesnt_have_a_property() + public void Should_set_default_caller_properties() { - var ctx = new XrmRealContext(_service, _serviceAsync, _serviceAsync2); - Assert.False(ctx.HasProperty()); + Assert.NotNull(_realContext.CallerProperties); } [Fact] - public void Should_return_true_if_context_does_have_a_property() - { - var ctx = new XrmRealContext(_service, _serviceAsync, _serviceAsync2); - ctx.SetProperty(new CustomProperty()); - Assert.True(ctx.HasProperty()); - } - - [Fact] - public void Should_retrieve_property_that_was_previously_set() + public void Should_return_license_exception_if_not_set_when_getting_an_organization_service() { - var ctx = new XrmRealContext(_service, _serviceAsync, _serviceAsync2); - - var prop = new CustomProperty(); - ctx.SetProperty(prop); - - var retrieved = ctx.GetProperty(); - Assert.Equal(prop, retrieved); + var ctx = new XrmRealContext(_service); + Assert.Throws(() => ctx.GetOrganizationService()); } } } \ No newline at end of file