Note that there are some explanatory texts on larger screens.

plurals
  1. POExclude results from Linq query excluding everything when exclude list is empty
    primarykey
    data
    text
    <p>I have the following code:</p> <pre><code> public IList&lt;Tweet&gt; Match(IEnumerable&lt;Tweet&gt; tweetStream, IList&lt;string&gt; match, IList&lt;string&gt; exclude) { var tweets = from f in tweetStream from m in match where f.Text.ToLowerInvariant().Contains(m) select f; var final = from f in tweets from e in exclude where !f.Text.ToLowerInvariant().Contains(e.ToLowerInvariant()) select f; return final.Distinct().ToList&lt;Tweet&gt;(); } </code></pre> <p>I've been building the tests up which haven't included the <code>final</code> resultset and been matching happily now I've added the exclude if the <code>IList&lt;string&gt;exclude</code> is empty all items are removed.</p> <p>So this test passes as it should:</p> <pre><code> [TestMethod] public void Should_exclude_items_from_exclude_list() { IEnumerable&lt;Tweet&gt; twitterStream = new List&lt;Tweet&gt; { new Tweet("I have a Mazda car"), new Tweet("I have a ford"), new Tweet("Mazda Rules"), new Tweet("My Ford car is great"), new Tweet("My renault is brill"), new Tweet("Mazda cars are great") }; IList&lt;string&gt; matches = new List&lt;string&gt;{"mazda","car"}; IList&lt;string&gt; exclude = new List&lt;string&gt;{"ford"}; Matcher target = new Matcher(); IList&lt;Tweet&gt; actual = target.Match(twitterStream, matches, exclude); Assert.AreEqual(3, actual.Count); } </code></pre> <p>but this test now fails:</p> <pre><code> [TestMethod] public void Should_match_items_either_mazda_or_car_but_no_duplicates() { IEnumerable&lt;Tweet&gt; twitterStream = new List&lt;Tweet&gt; { new Tweet("I have a Mazda car"), new Tweet("I have a ford"), new Tweet("Mazda Rules"), new Tweet("My Ford car is great"), new Tweet("My renault is brill"), new Tweet("Mazda cars are great") }; IList&lt;string&gt; matches = new List&lt;string&gt;{"mazda","car"}; IList&lt;string&gt; exclude = new List&lt;string&gt;(); Matcher target = new Matcher(); IList&lt;Tweet&gt; actual = target.Match(twitterStream, matches, exclude); Assert.AreEqual(4, actual.Count); } </code></pre> <p>I know I'm missing something really simple but after staring at the code for an hour its not coming to me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload