dimanche 4 octobre 2015

Assert uniqueness of fields in list

I have made a list in C# and I want to make a test to see if all the values of the Id fields are unique.

    public static List<RestaurantReview> _reviews = new List<RestaurantReview>
    {
        new RestaurantReview
        {
            Id = 1,
            Name = "McDonalds",
        },
        new RestaurantReview
        {
            Id = 2,
            Name = "Burger King",
        },}

Because I did some debugging I fount out that it is running trough the list but I do not get the proper test value. Could someone please explain what I am doing wrong here?

    [TestMethod()]
    public void CheckReviewIds()
    {
        var FirstReview = ReviewsController._reviews.First();
        bool AllUniqueIds = ReviewsController._reviews.All(s => s.Id == FirstReview.Id);

        Assert.IsFalse(AllUniqueIds);

    }

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire