Skip to content

Commit

Permalink
Merge pull request #44 from DynamicsValue/bugfix/several-updates-fixes
Browse files Browse the repository at this point in the history
Updated build scripts, added new helper method to create new instances.
  • Loading branch information
jordimontana82 authored Sep 13, 2023
2 parents 6a05372 + f803239 commit cc9818e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/CI-2x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ jobs:
name: Sonar Quality Gate
runs-on: windows-latest
steps:
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.11
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/CI-PullRequest-2x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ jobs:
name: Sonar Quality Gate
runs-on: windows-latest
steps:
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.11
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/PushNuget-2x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ jobs:
name: Sonar Quality Gate
runs-on: windows-latest
steps:
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.11
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Changed

- Upgraded GitHub Actions to update Java major version to run SonarCloud analysis - https://github.com/DynamicsValue/fake-xrm-easy/issues/110
- Updated build scripts so that it actually deletes bin folders as opposed to doing dotnet clean - https://github.com/DynamicsValue/fake-xrm-easy/issues/76
- 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

## [2.3.2]
Expand Down
1 change: 1 addition & 0 deletions FakeXrmEasy.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ED506DF3-19B6-420B-9172-13D54CC1A020}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
build.ps1 = build.ps1
EndProjectSection
EndProject
Global
Expand Down
11 changes: 4 additions & 7 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ else
}

Write-Host " -> Cleaning..." -ForegroundColor Yellow
if($targetFrameworks -eq "all")
{
dotnet clean /p:Configuration=$configuration /p:PackTests=$packTests --verbosity quiet
}
else {
dotnet clean /p:Configuration=$configuration /p:PackTests=$packTests /p:TargetFrameworks=$targetFrameworks --verbosity quiet
}
./clean.ps1 -folderPath "./src/FakeXrmEasy.Core/bin"
./clean.ps1 -folderPath "./src/FakeXrmEasy.Core/obj"
./clean.ps1 -folderPath "./tests/FakeXrmEasy.Core.Tests/bin"
./clean.ps1 -folderPath "./tests/FakeXrmEasy.Core.Tests/obj"

if($targetFrameworks -eq "all")
{
Expand Down
7 changes: 7 additions & 0 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
param (
[string]$folderPath = "./src/FakeXrmEasy.Core/bin"
)

if (Test-Path -Path $folderPath) {
Get-ChildItem -Path $folderPath -Include * -File -Recurse | foreach { $_.Delete()}
}
33 changes: 28 additions & 5 deletions src/FakeXrmEasy.Core/XrmFakedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ public IEnumerable<Assembly> ProxyTypesAssemblies
/// <summary>
///
/// </summary>
[Obsolete("Please use ProxyTypesAssemblies to retrieve assemblies and EnableProxyTypes to add new ones")]
[Obsolete("Please use ProxyTypesAssemblies to retrieve assemblies and EnableProxyTypes to add new ones. This method is solely maintained for making a smoother transition to the latest versions from v1")]
public Assembly ProxyTypesAssembly
{
get
{
// TODO What we should do when ProxyTypesAssemblies contains multiple assemblies? One shouldn't throw exceptions from properties.
return _proxyTypesAssemblies.FirstOrDefault();
}
set
Expand Down Expand Up @@ -310,12 +309,12 @@ public virtual void Initialize(IEnumerable<Entity> entities)
}

/// <summary>
///
/// Initializes the context with a single entity record
/// </summary>
/// <param name="e"></param>

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name

Check warning on line 314 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

XML comment has a param tag for 'e', but there is no parameter by that name
public void Initialize(Entity e)
public void Initialize(Entity entity)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2015)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2013)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_2016)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_365)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / build-windows (FAKE_XRM_EASY_9)

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)

Check warning on line 315 in src/FakeXrmEasy.Core/XrmFakedContext.cs

View workflow job for this annotation

GitHub Actions / pack-push

Parameter 'entity' has no matching param tag in the XML comment for 'XrmFakedContext.Initialize(Entity)' (but other parameters do)
{
this.Initialize(new List<Entity>() { e });
this.Initialize(new List<Entity>() { entity });
}

/// <summary>
Expand Down Expand Up @@ -486,5 +485,29 @@ protected IOrganizationService GetFakedOrganizationService(XrmFakedContext conte
return context._service;
}

/// <summary>
/// Creates a new entity record that is consistent with the current use of early-bound or late-bound entities by the current context
/// </summary>
/// <param name="logicalName">The entity logical name of the entity</param>
/// <returns>An early-bound record dif the context is already using early-bound entity records, a late bound entity otherwise</returns>
public Entity NewEntityRecord(string logicalName)
{
if (_proxyTypesAssemblies.Any())
{
var subClassType = FindReflectedType(logicalName);
if (subClassType != null)
{
var instance = Activator.CreateInstance(subClassType);
return (Entity) instance;
}
}

return new Entity
{
LogicalName = logicalName,
Id = Guid.Empty
};
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Crm;
using FakeXrmEasy.Tests;
using Xunit;

namespace FakeXrmEasy.Core.Tests.FakeContextTests
{

public class NewEntityRecordTests: FakeXrmEasyTestsBase
{
[Fact]
public void Should_use_late_bound_if_no_early_bound_entity_has_been_used()
{
var contact = ((XrmFakedContext)_context).NewEntityRecord("contact");
Assert.IsNotType<Contact>(contact);
}

[Fact]
public void Should_use_early_bound_if_the_context_is_using_early_bound()
{
_context.Initialize(new Contact() { Id = Guid.NewGuid()});
var contact = ((XrmFakedContext)_context).NewEntityRecord("contact");
Assert.IsType<Contact>(contact);
}
}
}

0 comments on commit cc9818e

Please sign in to comment.