Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
Closes #7. Fixed issues with joins / linked entities and filters acro…
Browse files Browse the repository at this point in the history
…ss versions as a new EntityName property was introduced in ConditionExpression >= 2013. All tests passing now.
  • Loading branch information
jordimontana82 committed Dec 13, 2015
1 parent 2112944 commit 8fd5a8b
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 58 deletions.
4 changes: 2 additions & 2 deletions FakeXrmEasy.2013/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.1")]
[assembly: AssemblyFileVersion("1.8.1")]
[assembly: AssemblyVersion("1.8.2")]
[assembly: AssemblyFileVersion("1.8.2")]
2 changes: 1 addition & 1 deletion FakeXrmEasy.2015/FakeXrmEasy.2015.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;FAKE_XRM_EASY_2015</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
Expand Down
4 changes: 2 additions & 2 deletions FakeXrmEasy.2015/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: AssemblyVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.8.2.0")]
2 changes: 1 addition & 1 deletion FakeXrmEasy.Tests.2013/buildNugetPackages.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
copy ..\FakeXrmEasy.2013\bin\Debug\FakeXrmEasy.dll .\build\lib\net40
cd build
nuget pack FakeXrmEasy.2013.dll.nuspec
nuget push FakeXrmEasy.2013.1.8.1.nupkg
nuget push FakeXrmEasy.2013.1.8.2.nupkg
pause
2 changes: 1 addition & 1 deletion FakeXrmEasy.Tests.2015/FakeXrmEasy.Tests.2015.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;FAKE_XRM_EASY_2015</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions FakeXrmEasy.Tests.2015/build/FakeXrmEasy.2015.dll.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>FakeXrmEasy.2015</id>
<version>1.8.1</version>
<version>1.8.2</version>
<authors>@jordimontana</authors>
<owners>@jordimontana</owners>
<licenseUrl>https://raw.githubusercontent.com/jordimontana82/fake-xrm-easy/master/LICENSE.md</licenseUrl>
<projectUrl>https://it-gems.com/fake-xrm-easy.html</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Utilities to streamline unit testing in Dynamics CRM 2013 by faking the IOrganizationService using FakeItEasy and make it work against an In-Memory context.</description>
<releaseNotes>
fixed Assembly Name
Fixed issues with joins / linked entities and filters across versions as a new EntityName property was introduced in ConditionExpression >= 2013
</releaseNotes>
<copyright>Copyright 2015</copyright>
<tags>xrm dynamics crm 2013 unit testing mock mocking fake fakes</tags>
Expand Down
2 changes: 1 addition & 1 deletion FakeXrmEasy.Tests.2015/buildNugetPackages.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
copy ..\FakeXrmEasy.2015\bin\Debug\FakeXrmEasy.dll .\build\lib\net452
cd build
nuget pack FakeXrmEasy.2015.dll.nuspec
nuget push FakeXrmEasy.2015.1.8.1.nupkg
nuget push FakeXrmEasy.2015.1.8.2.nupkg
pause
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ public void When_executing_a_linq_query_with_equals_between_2_activityparties_re
using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var activities = (from pointer in ctx.CreateQuery<Email>()
join party in ctx.CreateQuery<ActivityParty>() on pointer.Id equals party.ActivityId.Id
where party.PartyId.Id == contactId
join party in ctx.CreateQuery<ActivityParty>() on pointer.ActivityId.Value equals party.ActivityId.Id
// from party in ctx.CreateQuery<ActivityParty>() //on pointer.ActivityId.Value equals party.ActivityId.Id
where party.PartyId.Id == contactId
select pointer).ToList();

Assert.True(activities.Count == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,5 +833,39 @@ public void When_doing_a_crm_linq_query_that_produces_a_filter_expression_plus_c
Assert.True(matches.Count == 2);
}
}

[Fact(DisplayName = "When_doing_a_join_with_filter_then_can_filter_by_the_joined_entity_attributes")]
public void When_doing_a_join_with_filter_then_can_filter_by_the_joined_entity_attributes()
{
//REVIEW: Different implementations of the ConditionExpression class in Microsoft.Xrm.Sdk (which has EntityName property for versions >= 2013)

var fakedContext = new XrmFakedContext();
fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

var contactId = Guid.NewGuid();
var accountId = Guid.NewGuid();
var accountId2 = Guid.NewGuid();

//Contact is related to first account, but because first account is not related to itself then the query must return 0 records
fakedContext.Initialize(new List<Entity>() {
new Account() { Id = accountId, Name="Account1" },
new Account() { Id = accountId2, Name = "Account2" },
new Contact() { Id = contactId, ParentCustomerId = new EntityReference(Account.EntityLogicalName, accountId),
NumberOfChildren = 2, FirstName = "Contact" },
new Contact() {Id = Guid.NewGuid(), ParentCustomerId = new EntityReference(Account.EntityLogicalName, accountId2) }
});

var service = fakedContext.GetFakedOrganizationService();

using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var matches = (from c in ctx.CreateQuery<Contact>()
join account in ctx.CreateQuery<Account>() on c.ParentCustomerId.Id equals account.AccountId
where account.Name == "Account1"
select c).ToList();

Assert.True(matches.Count == 1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ public void When_executing_a_query_expression_with_all_attributes_all_of_them_ar
var firstContact = result.FirstOrDefault();
var lastContact = result.LastOrDefault();

Assert.True(firstContact.Attributes.Count == 3 + 4); //Contact 1 (the extra four are the CreatedOn, ModifiedOn, CreatedBy, ModifiedBy attributes generated automatically
Assert.True(lastContact.Attributes.Count == 3 + 4); //Contact 2
//Contact 1 attributes = 3 + 4 (the extra four are the CreatedOn, ModifiedOn, CreatedBy, ModifiedBy attributes generated automatically
//+ Attributes from the join(account) = 1 + 4 (the extra four are the CreatedOn, ModifiedOn, CreatedBy, ModifiedBy attributes generated automatically

Assert.True(firstContact.Attributes.Count == 3 + 1 + 4 * 2);
Assert.True(lastContact.Attributes.Count == 3 + 1 + 4 * 2); //Contact 2
}

[Fact]
Expand Down Expand Up @@ -342,6 +345,7 @@ public void When_executing_a_query_expression_without_columnset_no_attributes_ar
}
);

qe.ColumnSet = new ColumnSet(false);
var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe);

Assert.True(result.Count() == 2);
Expand Down
5 changes: 2 additions & 3 deletions FakeXrmEasy.Tests/build/FakeXrmEasy.dll.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>FakeXrmEasy</id>
<version>1.8.1</version>
<version>1.8.2</version>
<authors>@jordimontana</authors>
<owners>@jordimontana</owners>
<licenseUrl>https://raw.githubusercontent.com/jordimontana82/fake-xrm-easy/master/LICENSE.md</licenseUrl>
<projectUrl>https://it-gems.com/fake-xrm-easy.html</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Utilities to streamline unit testing in Dynamics CRM by faking the IOrganizationService using FakeItEasy and make it work against an In-Memory context.</description>
<releaseNotes>
Added the ability to pass custom mocks to the context.
Bug fix.
Fixed issues with joins / linked entities and filters across versions as a new EntityName property was introduced in ConditionExpression >= 2013
</releaseNotes>
<copyright>Copyright 2015</copyright>
<tags>xrm dynamics crm unit testing mock mocking fake fakes</tags>
Expand Down
Binary file modified FakeXrmEasy.Tests/build/lib/net40/FakeXrmEasy.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion FakeXrmEasy.Tests/buildNugetPackages.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
copy ..\FakeXrmEasy\bin\Debug\FakeXrmEasy.dll .\build\lib\net40
cd build
nuget pack FakeXrmEasy.dll.nuspec
nuget push FakeXrmEasy.1.8.1.nupkg
nuget push FakeXrmEasy.1.8.2.nupkg
pause
29 changes: 22 additions & 7 deletions FakeXrmEasy/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ public static Entity AddAttribute(this Entity e, string key, object value)
/// <returns></returns>
public static Entity ProjectAttributes(this Entity e, ColumnSet columnSet, XrmFakedContext context)
{
if (columnSet == null) return e;
return ProjectAttributes(e, new QueryExpression() { ColumnSet = columnSet }, context);
}

if (columnSet.AllColumns)
public static Entity ProjectAttributes(this Entity e, QueryExpression qe, XrmFakedContext context)
{
if (qe.ColumnSet == null) return e;

if (qe.ColumnSet.AllColumns)
{
return e; //return all the original attributes
}
Expand All @@ -62,7 +67,7 @@ public static Entity ProjectAttributes(this Entity e, ColumnSet columnSet, XrmFa
else
projected = new Entity(e.LogicalName) { Id = e.Id };

foreach (var attKey in columnSet.Columns)
foreach (var attKey in qe.ColumnSet.Columns)
{
if (e.Attributes.ContainsKey(attKey))
projected[attKey] = e[attKey];
Expand All @@ -76,12 +81,22 @@ public static Entity ProjectAttributes(this Entity e, ColumnSet columnSet, XrmFa
}
}

//Plus the aliased attributes, if any
foreach (var attKey in e.Attributes.Keys)
//Plus attributes from joins
foreach(var le in qe.LinkEntities)
{
if(e[attKey] is AliasedValue && !projected.Attributes.ContainsKey(attKey))
projected[attKey] = e[attKey];
foreach (var attKey in le.Columns.Columns)
{
var sAlias = string.IsNullOrWhiteSpace(le.EntityAlias) ? le.LinkToEntityName : le.EntityAlias;
var linkedAttKey = sAlias + "." + attKey;
if (e.Attributes.ContainsKey(linkedAttKey) || le.Columns.AllColumns)
projected[linkedAttKey] = e[linkedAttKey];
}
}
//foreach (var attKey in e.Attributes.Keys)
//{
// if(e[attKey] is AliasedValue && !projected.Attributes.ContainsKey(attKey))
// projected[attKey] = e[attKey];
//}
return projected;
}
}
Expand Down
6 changes: 3 additions & 3 deletions FakeXrmEasy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: AssemblyInformationalVersion("1.8.1")]
[assembly: AssemblyVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.8.2.0")]
[assembly: AssemblyInformationalVersion("1.8.2")]
Loading

0 comments on commit 8fd5a8b

Please sign in to comment.