title: Assert that all items in a collection have the value for one of the items property using NUnit
body: <p>I have to convert MS unit tests to NUnit and came across this assertion.</p>
  
  <pre><code>Assert.AreEqual(collection.Select(item =&gt; item.location.id).Distinct().Count(), 1);
  </code></pre>
  
  <p>I was hoping the there would be an elegant way to write that with constraints but I have not been able to find one. My solution is this, but Im not that happy with it:</p>
  
  <pre><code>Expect(collection.Select(item =&gt; item.location.id).Distinct().Count(), Is.EqualTo(1));
  </code></pre>
  
  <p>Is there a better way of writing that assertion where the intent is clearer readable? (Using <code>Has.</code> or <code>Map(collection).</code> )</p>
  
  <hr>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I just realized it may be helpful to clearly state what the intent is:</p>
  
  <p>all items in the collection have the same location ID (without knowing what that ID is)</p>
  
  <hr>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>This is what the collection may look like as JSON:</p>
  
  <pre><code>[{itemId=1, location={name="A", id=1}},
   {itemId=2, location={name="A", id=1}},
   {itemId=3, location={name="A", id=1}}]
  </code></pre>
  
  <p>distinct.count = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> pass</p>
  
  <pre><code>[{itemId=1, location={name="A", id=1}},
   {itemId=2, location={name="A", id=1}},
   {itemId=4, location={name="B", id=2}}]
  </code></pre>
  
  <p>distinct.count = 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> fail</p>
  
  <p><strong>Edit 3: my final solution, based on Fabio's answer</strong></p>
  
  <pre><code>IEnumerable&lt;long?&gt; locationIds = collection.Select(item =&gt; item.location.id);
  Expect(locationIds, Has.All.EqualTo(locationIds.FirstOrDefault()));
  </code></pre>