I have the following test code:
parentViewModel = MockRepository.GenerateMock<IParentViewModel>();
parentViewModel.Expect(x => x.GetPropertyValue<IEnumerable<Milestone>>("JobMilestones")).Return(new Milestone[0]);
viewModel = new JobPenaltiesViewModel(j, new Penalty[0], _opContext, parentViewModel);
Assert.That(viewModel.Milestones.Count(), Is.EqualTo(0));
parentViewModel.VerifyAllExpectations();
List<string> propsChanged = new List<string>();
viewModel.PropertyChanged += (s, e) => propsChanged.Add(e.PropertyName);
parentViewModel.Raise(x => x.PropertyChanged += null, parentViewModel, new PropertyChangedEventArgs("JobMilestones"));
AssertPropertiesChangedAsExepected(propsChanged, 1, "Milestones");
Milestone m1 = GenerateMilestone(j);
List<Milestone> milestones1 = new List<Milestone> { m1 };
parentViewModel.Expect(x => x.GetPropertyValue<IEnumerable<Milestone>>("JobMilestones")).Return(milestones1).Repeat.Any();
IEnumerable<Milestone> milestones = viewModel.Milestones;
Assert.That(milestones.Count(), Is.EqualTo(1));
parentViewModel.VerifyAllExpectations();
All the tests and assertions succeed up until the:
Assert.That(milestones.Count(), Is.EqualTo(1));
That's where I get the exception:
Previous method 'IEnumerator.MoveNext();' requires a return value or an exception to throw.
I've tried everything I can think of, and my testing seems to indicate that the parentViewModel Mock is returning null, or an empty enumeration (i.e. when I use the debugger to inspect the returned value the 'Results View' says the enumeration returned no results).
What am I missing here?
I've since removed the offending code; however I never did figure out why it was behaving the way it was.