public void should_get_schedule_from_repo_on_initialize () {
     var schedule = new Schedule ();
     _repository.GetScheduleResult = schedule;
     _repository.GetTrackFiltersResult = new List<string> ();
     _sut.Initialize ().Wait ();
     Assert.AreSame (schedule, _sut.Schedule);
 }
        public void SetUp ()
        {
            _sessionIds = new List<string> ();

            _slot1 = new Slot {
                StartTime = new DateTime (2014, 10, 1, 8, 0, 0),
                EndTime = new DateTime (2014, 10, 1, 8, 50, 0),
                SessionIds = _sessionIds
            };

            _slot2 = new Slot {
                StartTime = new DateTime (2014, 10, 1, 9, 0, 0),
                EndTime = new DateTime (2014, 10, 1, 9, 50, 0),
                SessionIds = _sessionIds
            };

            _days = new List<Day> {
                new Day {
                    Date = new DateTime(2014, 10, 1),
                    Slots = new List<Slot> {
                        _slot1,
                        _slot2
                    }
                }
            };

            _schedule = new Schedule { Days = _days };
            _appConfig = new AppConfig ();

            _repository = new MockRepository {
                GetDaysResult = _days,
                GetScheduleResult = _schedule,
                GetAppConfigResult = _appConfig
            };

            _sessions = new List<Session> ();
            _repository.GetSessionsResults [_sessionIds] = _sessions;

            _timeService = new MockTimeService ();
            _twitterService = new MockTwitterService ();
            _sut = new HomeViewModel (_repository, _timeService, _twitterService);
        }
		static void GetData (out List<Session> sessions, out Schedule schedule, out List<Speaker> speakers)
		{
			var rawData = RawScheduleData.GetData();

			var lines = rawData.Split (new char[] {'\r','\n'}, StringSplitOptions.RemoveEmptyEntries);

			var cells = lines.Select (x => x.Split (new char[] {'\t'}, StringSplitOptions.None));

			// SessionId	Date	StartTime	EndTime	Name	Abstract	Track	Presenter1	Company1	Position1	Presenter2	Company2	Position2	Presenter3	Company3	Position3
			var rawSessions = cells.Select (x => new {
				Id = "session-" + x [0],
				Date = DateTime.Parse (x [1]),
				StartTime = DateTime.Parse (x [1] + " " + x [2]),
				EndTime = DateTime.Parse (x [1] + " " + x [3]),
				Name = x [4],
				Abstract = x[5],
				Track = x [6],
				Presenter1Name = x [7],
				Presenter1Company = x [8],
				Presenter1Role = x [9],
				Presenter1Headshot = x [10],
				Presenter2Name = x [11],
				Presenter2Company = x [12],
				Presenter2Role = x [13],
				Presenter3Name = x [14],
				Presenter3Company = x [15],
				Presenter3Role = x [16],
			}).ToList ();

			var rawSpeakers = 
				rawSessions.Select (x => new SpeakerRaw {
					Name = x.Presenter1Name,
					Company = x.Presenter1Company,
					Role = x.Presenter1Role,
					HeadshotUrl = x.Presenter1Headshot
				})
					.Concat (rawSessions.Select (x => new SpeakerRaw {
						Name = x.Presenter2Name,
						Company = x.Presenter2Company,
						Role = x.Presenter2Role,
						HeadshotUrl = x.Presenter1Headshot
				}))
					.Concat (rawSessions.Select (x => new SpeakerRaw {
						Name = x.Presenter2Name,
						Company = x.Presenter2Company,
						Role = x.Presenter2Role,
						HeadshotUrl = x.Presenter1Headshot
					}))
					.GroupBy(x => x.Name)
					.Select(x => x.FirstOrDefault())
					.Where (x => String.IsNullOrWhiteSpace (x.Name) == false);
			
			Func<string, string> speakerNameToId = x => String.IsNullOrWhiteSpace(x) ? "" : "speaker-" + x.ToLower ().Replace (" ", "-");

			speakers = rawSpeakers
				.Select (x => new Speaker {
					Id = speakerNameToId (x.Name),
					First = x.Name.Trim ().Substring (0, x.Name.Trim ().LastIndexOf (" ")),
					Last = x.Name.Trim ().Substring (x.Name.Trim ().LastIndexOf (" ") + 1),
					Company = x.Company,
					Role = x.Role,
					HeadshotUrl = x.HeadshotUrl
				}).ToList ();

			var sessionSpeakers = rawSessions.Select (x => new SessionSpeaker {
				SessionId = x.Id,
				SpeakerId = speakerNameToId (x.Presenter1Name)
			}).Concat (rawSessions.Select (x => new SessionSpeaker {
				SessionId = x.Id,
				SpeakerId = speakerNameToId (x.Presenter2Name)
			})).Concat (rawSessions.Select (x => new SessionSpeaker {
				SessionId = x.Id,
				SpeakerId = speakerNameToId (x.Presenter3Name)
			})).Distinct ()
				.Where (x => String.IsNullOrWhiteSpace (x.SpeakerId) == false)
				.ToList ();

			sessions = rawSessions.Select( rs =>
				new Session {
					Id = rs.Id,
					Time = rs.StartTime,
					Title = rs.Name,
					Track = rs.Track,
					Abstract = rs.Abstract.Replace("<br>", Environment.NewLine),
					Location = "TBA"
				}).ToList ();

			var groupedSessionSpeakers = sessionSpeakers.GroupBy (x => x.SessionId, y => y.SpeakerId).ToList();

			foreach (var gs in groupedSessionSpeakers)
			{
				sessions.Where (x => x.Id == gs.Key).Single ().SpeakerIds = gs.ToList();
			}

			var groupedSessionIds = sessions.GroupBy (x => x.Time, y => y.Id).ToList();

			var timeSlots = rawSessions
				.Select (x => new StartAndEnd
					{ 
						StartTime = x.StartTime, 
						EndTime = x.EndTime
					}).Distinct()
				.ToList();

			var slots = timeSlots
				.Join (groupedSessionIds, s => s.StartTime, gs => gs.Key, (s, gs) => new Slot {
					StartTime = s.StartTime,
					EndTime = s.EndTime,
					SessionIds = gs.ToList ()
				}).ToList ();

			var groupedSlots = slots.GroupBy (x => x.StartTime.Date).ToList();

			var days = groupedSlots.Select (x => new Day {
				Date = x.Key,
				Slots = x.ToList ()
			}).ToList();

			schedule = new Schedule{ Days = days };
		}
		void SaveSchedule (Schedule schedule)
		{
			var db = GetTargetDatabase ();
			var scheduleDoc = db.GetExistingDocument("schedule");
			if (scheduleDoc == null)
			{
				scheduleDoc = db.GetDocument ("schedule");
			}
			var dict = new Dictionary<string, object> ();
			dict.Add ("type", "schedule");
			dict.Add ("schedule", schedule);

			scheduleDoc.PutProperties (dict);
			Console.WriteLine ("Saving {0}", scheduleDoc.Id);

			Thread.Sleep (100);
		}