Testing view model

Sep 20, 2010 at 1:47 PM


I have a simple view model implementation. I override OnInitialize method because I need my module populated with some data initialy

        protected override void OnInitialize()

            IVisitService visitService = IoC.Get<IVisitService>();
            Visits = visitService.GetList();
            TodayVisits = Visits.Take(2).ToList();

Is there a way I can test this implementation ? I need to mock my service, but how can I do this from a test ?



Sep 20, 2010 at 3:42 PM

You should not use IoC directly inside your VM. Try having the IVisitService injected into the VM. Next, mock the service and call OnInitialize in your test.