Как получить общую продолжительность в miutes из коллекции списков в C#
[TestMethod] public void GetTotalDurationFor_PassEventInBetween() { new List<EventItemModel>() { new EventItemModel() {DateTime = new DateTime(2017,1,1,10,0,0), Event = EventType.Enter}, new EventItemModel() {DateTime = new DateTime(2017,1,1,10,30,0), Event = EventType.Pass}, new EventItemModel() {DateTime = new DateTime(2017,1,1,11,30,0), Event = EventType.Leave}, }.GetTotalDurationFor().Should().Be(90); } } THIS TEST FAILES ... PLEASE HELP
Что я уже пробовал:
public static double GetTotalDurationFor(this IEnumerable<EventItemModel> lst) { var selectedEmployeDayinout = lst.OrderBy(d => d.DateTime).ToList(); const int enterExitOperations = 2; double duration = 0; if ((selectedEmployeDayinout.Count()%enterExitOperations) != 0) return duration; for (var i = 0; i < selectedEmployeDayinout.Count(); i ++) { var enterDate = selectedEmployeDayinout[i].DateTime; var leaveDate = selectedEmployeDayinout[i + 1].DateTime; duration += leaveDate.Subtract(enterDate).TotalSeconds; } return duration; }