List <ParticipantListItemViewModel> GetParticipants(MoqTimerEventArgs moqArgs, DateTime[] birthDateTimes) { var returnVar = new List <ParticipantListItemViewModel>(birthDateTimes.Length); for (int i = 0; i < birthDateTimes.Length; i++) { var p = new ParticipantListItemViewModel( new ParticipantBaseModel { Id = i + 1, DateTimeBirth = birthDateTimes[i] }); p.PropertyChanged += (s, e) => { var returnedP = (ParticipantListItemViewModel)s; Console.WriteLine("Id:{0}, DOB:{1:dd/MM hh:mm}, daysOld:{2}, called:{3:dd/MM hh:mm}", p.Id, p.DateTimeBirth, p.AgeDays, moqArgs.StartAt); }; returnVar.Add(p); } return(returnVar); }
public void TestAgeUpdatingStartOnAdd() { var moqArgs = new MoqTimerEventArgs(true); var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict); mockTimer.SetupProperty(m => m.Interval); mockTimer.Setup(m => m.Start()).Verifiable(); mockTimer.Setup(m => m.Stop()).Verifiable(); IDispatcherTimer timer = mockTimer.Object; var ageService = new AgeUpdatingService(new ParticipantListItemViewModel[0], timer); mockTimer.Verify(m => m.Start(), Times.Never); TimeSpan toDob = TimeSpan.FromMinutes(-10); var p = new ParticipantListItemViewModel( new ParticipantBaseModel { Id = 1, DateTimeBirth = moqArgs.StartAt + toDob }); TimeSpan expectedInterval = TimeSpan.FromDays(1) + toDob; TimeSpan tolerance = TimeSpan.FromSeconds(defaultSecsTolerance); mockTimer.SetupSet(m => m.Interval = It.IsAny <TimeSpan>()).Callback <TimeSpan>(i => { string usrMsg = string.Format(intervalLogTemplate, i, expectedInterval, tolerance); if (i < expectedInterval - tolerance || i > expectedInterval + tolerance) { throw new ArgumentOutOfRangeException("Interval", usrMsg); } else { Console.WriteLine(usrMsg); } }); ageService.AddParticipant(p); mockTimer.Verify(m => m.Start(), Times.Once); TimeSpan laterDayversary = TimeSpan.FromMinutes(-5); p = new ParticipantListItemViewModel( new ParticipantBaseModel { Id = 2, DateTimeBirth = moqArgs.StartAt + laterDayversary }); ageService.AddParticipant(p); toDob = TimeSpan.FromMinutes(-30); p = new ParticipantListItemViewModel( new ParticipantBaseModel { Id = 2, DateTimeBirth = moqArgs.StartAt + toDob }); expectedInterval = TimeSpan.FromDays(1) + toDob; ageService.AddParticipant(p); toDob = TimeSpan.FromDays(-1).Add(TimeSpan.FromMinutes(5)); p = new ParticipantListItemViewModel( new ParticipantBaseModel { Id = 2, DateTimeBirth = moqArgs.StartAt + toDob }); expectedInterval = TimeSpan.FromDays(1) + toDob; ageService.AddParticipant(p); }