C#C
C#4y ago
Daryl

Method works when dependent Method never called?

I am following a Pluralsight tutorial on ASP.NET Fundamentals and we've just created this hard-coded data repository to work from:

public class MockPieRepository : IPieRepository
{
    private readonly ICategoryRepository _categoryRepository = new MockCategoryRepository();

    public IEnumerable<Pie> AllPies =>
        new List<Pie>
        {
            new Pie {PieId = 1, etc},
            new Pie {PieId = 2, etc}
        };

   public IEnumerable<Pie> PiesOfTheWeek
    {
     get
        {
            return AllPies.Where(p => p.IsPieOfTheWeek);
        }
    }
}


I understand what both of these methods do but I don't understand how the
PiesOfTheWeek
method would currently work as the
AllPies
has never been called and not called in any constructor? I would expect
PiesOfTheWeek
to return Null when it tries it's Where statement.

Also, shouldn't
AllPies
have
()
when it's used in
PiesOfTheWeek
?

Thank you in advance!
Was this page helpful?