I have the following code:
var isDuplicateCategoryIds = _query.Categories
.GroupBy(x => x.Id)
.Any(g => g.Count() > 1);
I have two tests that invoke this code, one where there are duplicate Ids and one where there are not.
However, openCover (which is used on our CI server) is reporting:
Partially covered by tests (16 of 44 conditions).
Locally, dotCover is reporting 100%.
As I understand it, openCover uses the branches & conditions generated in the IL, and the IL for this statement is the following 24 lines (named symbols removed):
IL_0001: ldarg.0 // this
IL_0002: ldfld
IL_0007: callvirt
IL_000c: ldsfld
IL_0011: dup
IL_0012: brtrue.s IL_002b
IL_0014: pop
IL_0015: ldsfld
IL_001a: ldftn
IL_0020: newobj
IL_0025: dup
IL_0026: stsfld
IL_002b: call
IL_0030: ldsfld
IL_0035: dup
IL_0036: brtrue.s IL_004f
IL_0038: pop
IL_0039: ldsfld
IL_003e: ldftn
IL_0044: newobj
IL_0049: dup
IL_004a: stsfld
IL_004f: call
IL_0054: stloc.0
My question is how do I get coverage here?
As an aside: Is it even worthwhile to attempt do so? I have tests covering the two scenarios this code is concerned with; dupes & no dupes. There is code executed prior to this that checks whether Categories is null/empty & under that scenario this code won't be invoked. So if some of these conditions being generated under the hood are for that (I don't know that they are), it's a moot point.