8000 Alias and name checks by filcole · Pull Request #486 · jordimontana82/fake-xrm-easy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Alias and name checks #486

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
8 changes: 2 additions & 6 deletions FakeXrmEasy.Shared/XrmFakedContext.Aggregations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ internal static List<Entity> ProcessAggregateFetchXml(XrmFakedContext ctx, XDocu
namespacedAlias.Add(attr.GetAttribute("name")?.Value);
var logicalName = string.Join(".", namespacedAlias);

if (string.IsNullOrEmpty("alias"))
if (string.IsNullOrEmpty(alias))
{
throw new Exception("Missing alias for attribute in aggregate fetch xml");
}
if (string.IsNullOrEmpty("name"))
{
throw new Exception("Missing name for attribute in aggregate fetch xml");
}

if (attr.IsAttributeTrue("groupby"))
{
Expand Down Expand Up @@ -157,7 +153,7 @@ private static List<Entity> OrderAggregateResult(XDocument xmlDoc, IQueryable<En
{
throw new Exception("An attribute cannot be specified for an order clause for an aggregate Query. Use an alias");
}
if (string.IsNullOrEmpty("alias"))
if (string.IsNullOrEmpty(alias))
{
throw new Exception("An alias is required for an order clause for an aggregate Query.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,47 @@ public void FetchXml_Aggregate_Group_EntityReference_Count()
Assert.Equal(2, biggestGroup.GetAttributeValue<AliasedValue>("Qt").Value);
}

[Fact]
public void FetchXml_Aggregate_MissingAttribAlias_shouldThrowException()
{
var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
<entity name='contact'>
<attribute name='contactid' aggregate='count' />
</entity>
</fetch>";

var ctx = new XrmFakedContext();
ctx.Initialize(new[] {
new Contact() { Id = Guid.NewGuid() },
});

var exception = Record.Exception(() => ctx.GetOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml)));

Assert.IsType<Exception>(exception);
Assert.Equal("Missing alias for attribute in aggregate fetch xml", exception.Message);
}

[Fact]
public void FetchXml_Aggregate_EmptyOrderAlias_shouldThrowException()
{
var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
<entity name='contact'>
<attribute name='contactid' alias='count.contacts' aggregate='count' />
<attribute name='lastname' alias='group.lastname' groupby='true' />
<order alias='' />
</entity>
</fetch>";

var ctx = new XrmFakedContext();
ctx.Initialize(new[] {
new Contact() { Id = Guid.NewGuid(), LastName = "Smith" },
});

var exception = Record.Exception(() => ctx.GetOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml)));

Assert.IsType<Exception>(exception);
Assert.Equal("An alias is required for an order clause for an aggregate Query.", exception.Message);
}

[Fact]
public void FetchXml_Aggregate_CountDistinct()
Expand Down
0