Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
note. fixed an error on the proposed test case too.
  • Loading branch information
BetimBeja committed Nov 4, 2018
1 parent 719d3a8 commit 7e0d4ed
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FakeXrmEasy.Shared/XrmFakedContext.Queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static IQueryable<Entity> TranslateLinkedEntityToLinq(XrmFakedContext con
query = query.Join(inner,
outerKey => outerKey.KeySelector(linkFromAlias, context),
innerKey => innerKey.KeySelector(le.LinkToAttributeName, context),
(outerEl, innerEl) => outerEl.JoinAttributes(innerEl, new ColumnSet(true), leAlias, context));
(outerEl, innerEl) => outerEl.Clone(outerEl.GetType()).JoinAttributes(innerEl, new ColumnSet(true), leAlias, context));

break;
case JoinOperator.LeftOuter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,5 +1058,74 @@ public void When_There_Are_Multiple_LinkedEntities_With_The_Same_Entitiy_And_One
Assert.Equal("User2", ((AliasedValue)resultingEntity["systemuserwithalias.fullname"]).Value);
Assert.Equal("User1", ((AliasedValue)resultingEntity["systemuser2.fullname"]).Value);
}

[Fact]
public void TestRetriveMultipleWithLinkEntityWithAlternateNullField()
{
// ARRANGE

List<Entity> initialEntities = new List<Entity>();

Entity parentEntity = new Entity("parent");
parentEntity["parentname"] = "parent name";
parentEntity.Id = Guid.NewGuid();
initialEntities.Add(parentEntity);

// create the first child which has the "myvalue" field set to "value"
Entity childEntity1 = new Entity("child");
childEntity1["parent"] = parentEntity.ToEntityReference();
childEntity1["name"] = "entity1";
childEntity1["myvalue"] = "value";
childEntity1.Id = Guid.NewGuid();
initialEntities.Add(childEntity1);

// create the second child which has the "myvalue" field set to null
Entity childEntity2 = new Entity("child");
childEntity2["parent"] = parentEntity.ToEntityReference();
childEntity2["name"] = "entity2";
childEntity2["myvalue"] = null;
childEntity2.Id = Guid.NewGuid();
initialEntities.Add(childEntity2);

XrmFakedContext context = new XrmFakedContext();
IOrganizationService service = context.GetOrganizationService();

context.Initialize(initialEntities);

// the query selects the "parent" entity, and joins to the "child" entities
QueryExpression query = new QueryExpression("parent");
query.ColumnSet = new ColumnSet("parentname");

LinkEntity link = new LinkEntity("parent", "child", "parentid", "parent", JoinOperator.Inner);
link.EntityAlias = "c";
link.Columns = new ColumnSet("name", "myvalue");

query.LinkEntities.Add(link);

// ACT

DataCollection<Entity> results = service.RetrieveMultiple(query).Entities;

// ASSERT

// fields for the first entity work as expected...
string entity1Name = results[0].GetAttributeValue<AliasedValue>("c.name").Value as string;
string entity1Value = results[0].GetAttributeValue<AliasedValue>("c.myvalue").Value as string;

Assert.Equal("entity1", entity1Name);
Assert.Equal("value", entity1Value);

// fields for the second entity do not.
// The child "name" field is correct, but the "myvalue" field is returning the value of the previous
// entity when it should be returning null
string entity2Name = results[1].GetAttributeValue<AliasedValue>("c.name").Value as string;
string entity2Value = results[1].GetAttributeValue<AliasedValue>("c.myvalue")?.Value as string;

// this works fine:
Assert.Equal("entity2", entity2Name);

// this fails (entity2Value is "value")
Assert.Equal(null, entity2Value);
}
}
}

0 comments on commit 7e0d4ed

Please sign in to comment.