i’m trying to find all the tags which equal a name from a list of words.
for example :-
public class Tag
{
public int Id { get; set; }
public string Name { get; set; }
public string UserId { get; set; }
}
// Arrange.
var searchWords = new List<string>(new [] {"c#", ".net", "rails"});
var tags = new Tags
{
new Tag { Name = "c#" },
new Tag { Name = "pewpew" },
new Tag { Name = "linq" },
new Tag { Name = "iis" }
};
// Act.
// Grab all the tags given the following search words => 'c#' '.net' and 'rails'
// Expected: 1 result.
var results = ???
// Assert.
Assert.NotNull(results);
Assert.Equal(1, results.Count);
Assert.Equal("c#", results.First());
I’ve been trying to use Any or Contains but my code just doesn’t compile.
NOTE: Can be .NET 4.0
Does this work for you?
Also note that since
resultsisIEnumerable<T>you will need to use the methodresults.Count()instead of the propertyresults.Countin your assert.Countis a property defined by theICollectioninterface.