Skip to content

Commit f75a05d

Browse files
committed
Test coverage for custom add calls in an initialiser
1 parent 9168205 commit f75a05d

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

ReadableExpressions.UnitTests/WhenTranslatingMemberAccesses.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace AgileObjects.ReadableExpressions.UnitTests
22
{
33
using System;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using System.Collections.ObjectModel;
67
using System.Globalization;
@@ -326,6 +327,23 @@ public void ShouldIncludeRefParameterKeywords()
326327

327328
Assert.AreEqual("ip.RefGet(3, ref value)", translated);
328329
}
330+
331+
[TestMethod]
332+
public void ShouldTranslateACustomEnumerableAddInitialiser()
333+
{
334+
Expression<Func<int, int, int, CustomAdder>> customAdder =
335+
(intOne, intTwo, intThree) => new CustomAdder { { intOne, intTwo, intThree } };
336+
337+
var translated = customAdder.Body.ToReadableString();
338+
339+
const string EXPECTED = @"
340+
new CustomAdder
341+
{
342+
{ intOne, intTwo, intThree }
343+
}";
344+
345+
Assert.AreEqual(EXPECTED.TrimStart(), translated);
346+
}
329347
}
330348

331349
#region Helper Classes
@@ -409,5 +427,17 @@ public static void DoSomething()
409427
}
410428
}
411429

430+
internal class CustomAdder : IEnumerable
431+
{
432+
public void Add(int intOne, int intTwo, int intThree)
433+
{
434+
}
435+
436+
public IEnumerator GetEnumerator()
437+
{
438+
throw new NotImplementedException();
439+
}
440+
}
441+
412442
#endregion
413443
}

ReadableExpressions/Translators/InitialisationExpressionTranslator.Helpers.Member.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private string TranslateListBinding(MemberBinding binding, TranslationContext co
6262
.Initializers
6363
.Select(init => IsStandardAddMethod(init)
6464
? context.Translate(init.Arguments.First())
65-
: _methodCallTranslator.GetMethodCall(init.AddMethod, init.Arguments, context))
65+
: _methodCallTranslator.GetMethodCall(new BclMethodInfoWrapper(init.AddMethod), init.Arguments, context))
6666
.ToArray();
6767

6868
return GetInitialisation(listBinding.Member.Name + " =", listInitialisers);

ReadableExpressions/Translators/MethodCallExpressionTranslator.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ internal string GetMethodCall(
114114
}
115115

116116
internal string GetMethodCall(
117-
MethodInfo method,
118-
IEnumerable<Expression> arguments,
119-
TranslationContext context)
120-
{
121-
return GetMethodCall(new BclMethodInfoWrapper(method), arguments, context);
122-
}
123-
124-
private string GetMethodCall(
125117
IMethodInfo method,
126118
IEnumerable<Expression> arguments,
127119
TranslationContext context)

0 commit comments

Comments
 (0)