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

Tests for Issue48 #35

Open
wants to merge 4 commits into
base: 2x-dev
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions tests/FakeXrmEasy.Core.Tests/Issues/Issue48.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Crm;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using Xunit;

namespace FakeXrmEasy.Tests.Issues
{
// https://github.com/DynamicsValue/fake-xrm-easy/issues/48

public class Issue48 : FakeXrmEasyTestsBase
{
SalesOrder _salesOrder;
String fetchXML;
// setup
public Issue48()
{
_context.EnableProxyTypes(typeof(SalesOrder).Assembly);

_salesOrder = new SalesOrder() {Id = Guid.NewGuid(), Name = "O-12345" };

SalesOrderDetail salesOrderDetail1 = new SalesOrderDetail() {Id = Guid.NewGuid(), SalesOrderId = _salesOrder.ToEntityReference() };

_context.Initialize(new List<Entity> { _salesOrder, salesOrderDetail1 });

fetchXML = @"<fetch aggregate='true'>
<entity name='salesorderdetail'>
<attribute name='salesorderdetailid' alias='count' aggregate='count' />
<link-entity name='salesorder' to='salesorderid' from='salesorderid' alias='so' link-type='inner'>
<attribute name='name' alias='name' groupby='true' />
<order alias='name' />
</link-entity>
</entity>
</fetch>";
}


// This test currently fails - The given key was not present in the dictionary - the grouped by 'name' attribute is not in the resultset
[Fact]
public void When_An_Aggregated_Query_Contains_Group_By_Attributes_These_Should_Be_Returned_In_The_Query_Results()
{
EntityCollection records = _service.RetrieveMultiple(new FetchExpression(fetchXML));

// The 'name' column of the rist record should be the same as the orders name column
Assert.Equal(_salesOrder.Name, (string)((AliasedValue)records.Entities[0]["name"]).Value);
}

// This test currently passes - the aggregated value is returned ok
[Fact]
public void When_An_Aggregated_Query_Contains_Group_By_Attributes_The_Right_Aggregate_Values_Should_Be_Returned_In_The_Query_Results()
{
EntityCollection records = _service.RetrieveMultiple(new FetchExpression(fetchXML));

Assert.Equal(1, (int)((AliasedValue)records.Entities[0]["count"]).Value);

}
}
}