Skip to content

Commit 5abffcc

Browse files
committed
1 parent e41b227 commit 5abffcc

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

src/FakeXrmEasy.Core/Extensions/XmlExtensionsForFetchXml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static ColumnSet ToColumnSet(this XElement el)
205205
public static bool? ToReturnTotalRecordCount(this XElement el)
206206
{
207207
var returnTotalRecordCountAttr = el.GetAttribute("returntotalrecordcount");
208-
if (returnTotalRecordCountAttr == null)
208+
if (returnTotalRecordCountAttr == null)
209209
return null;
210210

211211
bool bReturnCount;
@@ -738,7 +738,7 @@ public static ConditionExpression ToConditionExpression(this XElement elem, IXrm
738738

739739

740740
//Otherwise, a single value was used
741-
if (value != null)
741+
if (value != null && values.Length == 0)
742742
{
743743
#if FAKE_XRM_EASY_2013 || FAKE_XRM_EASY_2015 || FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
744744
if (string.IsNullOrWhiteSpace(conditionEntityName))
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Crm;
2+
using Microsoft.Xrm.Sdk;
3+
using Microsoft.Xrm.Sdk.Query;
4+
using System;
5+
using System.Collections.Generic;
6+
using Xunit;
7+
8+
namespace FakeXrmEasy.Tests.Issues
9+
{
10+
// https://github.com/DynamicsValue/fake-xrm-easy/issues/45
11+
12+
public class Issue45 : FakeXrmEasyTestsBase
13+
{
14+
// setup
15+
public Issue45()
16+
{
17+
_context.EnableProxyTypes(typeof(Account).Assembly);
18+
19+
Contact contact1 = new Contact() { Id = Guid.NewGuid(), LastName = "May" };
20+
Contact contact2 = new Contact() { Id = Guid.NewGuid(), LastName = "Truss" };
21+
Contact contact3 = new Contact() { Id = Guid.NewGuid(), LastName = "Johnson" };
22+
23+
_context.Initialize(new List<Entity> { contact1, contact2 });
24+
}
25+
26+
// This test currently fails - returns no records
27+
[Fact]
28+
public void When_An_IN_Clause_On_A_String_Field_Contains_ValueEqualsQuote_It_Should_Return_The_Right_Records()
29+
{
30+
string fetchXML = @"<fetch>
31+
<entity name='contact'>
32+
<attribute name='lastname' />
33+
<filter>
34+
<condition attribute='lastname' operator='in' value=''>
35+
<value>Truss</value>
36+
<value>May</value>
37+
</condition>
38+
</filter>
39+
</entity>
40+
</fetch>";
41+
42+
EntityCollection contacts = _service.RetrieveMultiple(new FetchExpression(fetchXML));
43+
Assert.Equal(2, contacts.Entities.Count);
44+
}
45+
// This test currently passes
46+
[Fact]
47+
public void When_An_IN_Clause_On_A_String_Field_Doesnt_Contain_ValueEqualsQuote_It_Should_Return_The_Right_Records()
48+
{
49+
string fetchXML = @"<fetch>
50+
<entity name='contact'>
51+
<attribute name='lastname' />
52+
<filter>
53+
<condition attribute='lastname' operator='in'>
54+
<value>Truss</value>
55+
<value>May</value>
56+
</condition>
57+
</filter>
58+
</entity>
59+
</fetch>";
60+
61+
EntityCollection contacts = _service.RetrieveMultiple(new FetchExpression(fetchXML));
62+
63+
Assert.Equal(2, contacts.Entities.Count);
64+
}
65+
66+
// Fails - When trying to parse value for entity contact and attribute statecode: Integer value expected
67+
[Fact]
68+
public void When_An_IN_Clause_On_An_OptionSetValue_Field_Contains_ValueEqualsQuote_It_Should_Return_The_Right_Records()
69+
{
70+
string fetchXML = @"<fetch top='2'>
71+
<entity name='contact'>
72+
<attribute name='lastname' />
73+
<filter>
74+
<condition attribute='statecode' operator='in' value=''>
75+
<value>0</value>
76+
</condition>
77+
</filter>
78+
</entity>
79+
</fetch>";
80+
81+
EntityCollection contacts = _service.RetrieveMultiple(new FetchExpression(fetchXML));
82+
Assert.Equal(2, contacts.Entities.Count);
83+
}
84+
85+
// Passes
86+
[Fact]
87+
public void When_An_IN_Clause_On_An_OptionSetValue_Field_Doesnt_Contain_ValueEqualsQuote_It_Should_Return_The_Right_Records()
88+
{
89+
string fetchXML = @"<fetch top='2'>
90+
<entity name='contact'>
91+
<attribute name='lastname' />
92+
<filter>
93+
<condition attribute='statecode' operator='in'>
94+
<value>0</value>
95+
</condition>
96+
</filter>
97+
</entity>
98+
</fetch>";
99+
100+
EntityCollection contacts = _service.RetrieveMultiple(new FetchExpression(fetchXML));
101+
Console.WriteLine(contacts.Entities.Count);
102+
Assert.Equal(2, contacts.Entities.Count);
103+
}
104+
105+
}
106+
}

0 commit comments

Comments
 (0)