Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate key fix #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 5 additions & 7 deletions src/XrmMockupShared/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,17 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
switch (request.RequestName)
{
case "Create":
var createResponse = (CreateResponse) response;
var entityLogicalName = ((Entity) request.Parameters["Target"]).LogicalName;
var createResponse = (CreateResponse)response;
var entityLogicalName = ((Entity)request.Parameters["Target"]).LogicalName;
var reference = primaryRef ?? new EntityReference(entityLogicalName, createResponse.id);

var createdEntity =
GetDbRow(new EntityReference(entityLogicalName, createResponse.id))
.ToEntity();
var createdEntity = GetDbRow(reference).ToEntity();
TriggerExtension(
new MockupService(this, userRef.Id, pluginContext), request,
createdEntity, null, userRef);
break;
case "Update":
var target = (Entity) request.Parameters["Target"];
var updatedEntity = GetDbRow(target.ToEntityReferenceWithKeyAttributes()).ToEntity();
var updatedEntity = GetDbRow(primaryRef).ToEntity();
TriggerExtension(
new MockupService(this, userRef.Id, pluginContext), request,
updatedEntity, preImage, userRef);
Expand Down
47 changes: 46 additions & 1 deletion tests/SharedTests/TestAlternateKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TestAlternateKeys : UnitTestBase
{
public TestAlternateKeys(XrmMockupFixture fixture) : base(fixture) { }

[Fact(Skip = "Alternate key implementation should be based on column values")]
[Fact]
public void TestAlternateKeysAll()
{
using (var context = new Xrm(orgAdminUIService))
Expand Down Expand Up @@ -61,6 +61,51 @@ public void TestAlternateKeysAll()
}
}

[Fact]
public void TestAlternateKeysUpdateOnly()
{
using (var context = new Xrm(orgAdminUIService))
{
var attributes = new AttributeCollection {
{ "name", "Burgers" },
{ "address1_city", "Virum" }
};
orgAdminUIService.Create(new Account { Attributes = attributes });

var keyAttributes = new KeyAttributeCollection {
{ "name", "Burgers" },
{ "address1_city", "Virum" }
};
var req = new RetrieveRequest
{
Target = new EntityReference
{
LogicalName = Account.EntityLogicalName,
KeyAttributes = keyAttributes
}
};

var resp = orgAdminUIService.Execute(req) as RetrieveResponse;

var newAttributes = new AttributeCollection {
{ "address1_line1", "Some street" }
};
orgAdminUIService.Update(new Account { KeyAttributes = keyAttributes, Attributes = newAttributes });

req = new RetrieveRequest
{
Target = new EntityReference
{
LogicalName = Account.EntityLogicalName,
KeyAttributes = keyAttributes
}
};
resp = orgAdminUIService.Execute(req) as RetrieveResponse;
var updatedEntity = resp.Entity as Account;
Assert.Equal("Some street", updatedEntity.Address1_Line1);
}
}

[Fact]

public void AltKeyRetrieveWithoutEntityTypeInDb()
Expand Down