public async void Init_DataLoadsSuccessfully_LoadsTimeSlots()
        {
            var session = new Session {StartTime = DateTime.Now, EndTime = DateTime.Now, Id = 42, SpeakerId = 1};
            var data = new CampData
                           {
                               Sessions = new List<Session> {session},
                               Speakers = new List<Speaker> {new Speaker {Id = 1}},
                           };
            DataClient.GetDataBody = () => Task.FromResult(data);
            var viewModel = new SessionsViewModel(Messenger, CodeCampService);

            Assert.True(viewModel.IsLoading);

            await viewModel.Init();

            Assert.AreEqual(1, viewModel.TimeSlots.Count);

            var slot = viewModel.TimeSlots.First();

            Assert.AreEqual(session.StartTime, slot.StartTime);
            Assert.AreEqual(session.EndTime, slot.EndTime);
            Assert.AreEqual(1, slot.Sessions.Count);
            Assert.AreEqual(session, slot.Sessions.First());
            Assert.False(viewModel.IsLoading);
        }
        public async Task Init(NavigationParameters parameters)
        {
            bool successful = await SafeOperation(
                TaskEx.Run(async () => Session = await _campService.GetSession(parameters.Id)));

            FinishedLoading(successful);
        }
        public void ViewSessionCommand_NavigatesToSession()
        {
            var session = new Session {Id = 42};
            var viewModel = new SessionsViewModel(Messenger, CodeCampService);

            viewModel.ViewSessionCommand.Execute(session);

            Assert.AreEqual(1, Dispatcher.ShowViewModelRequests.Count);

            var request = Dispatcher.ShowViewModelRequests.Single();
            var navParameters = request.ParameterValues.Read(typeof(SessionViewModel.NavigationParameters)) as SessionViewModel.NavigationParameters;
            Assert.NotNull(navParameters);
            Assert.AreEqual(session.Id, navParameters.Id);
        }
        public async void Init_SomeSessionsHaveEnded_LoadsNextUnfinishedSlots()
        {
            var speaker = new Speaker {Id = 1};
            var pastSession = new Session { StartTime = DateTime.UtcNow.AddHours(-1), EndTime = DateTime.UtcNow.AddHours(-1), Id = 42, SpeakerId = speaker.Id};
            var inProgressSession = new Session { StartTime = DateTime.UtcNow.AddMinutes(-10), EndTime = DateTime.UtcNow.AddHours(1), Id = 24 };
            var data = new CampData
                           {
                               Sessions = new List<Session> {inProgressSession, pastSession},
                               Speakers = new List<Speaker> {speaker}
                           };
            DataClient.GetDataBody = () => Task.FromResult(data);
            var viewModel = new OverviewViewModel(Messenger, CodeCampService);

            await viewModel.Init();

            Assert.AreEqual(1, viewModel.TimeSlots.Count);
            Assert.AreEqual(inProgressSession, viewModel.TimeSlots.First().Sessions.Single());
        }
        public async void Init_DataLoadsSuccessfully_LoadsSession()
        {
            var session = new Session { Id = 42, SpeakerId = 1 };
            var data = new CampData
                           {
                               Sessions = new List<Session> {session},
                               Speakers = new List<Speaker> {new Speaker {Id = 1}},
                           };
            DataClient.GetDataBody = () => Task.FromResult(data);
            var viewModel = new SessionViewModel(Messenger, CodeCampService);

            Assert.True(viewModel.IsLoading);

            await viewModel.Init(new SessionViewModel.NavigationParameters(session.Id));

            Assert.False(viewModel.IsLoading);
            Assert.AreEqual(session, viewModel.Session);
        }
        public async void ListSessions_FetchesDataAndReturnsSessions()
        {
            var session = new Session
                              {
                                  Title = "Best Session Ever",
                                  Id = 42,
                                  StartTime = DateTime.UtcNow,
                                  EndTime = DateTime.UtcNow,
                                  SpeakerId = 1
                              };
            var campData = new CampData
            {
                Speakers = new List<Speaker> { new Speaker { Id = session.SpeakerId.Value } },
                Sessions = new List<Session> { session }
            };
            _mockDataClient.GetDataBody = () => Task.FromResult(campData);

            var service = new CodeCampService(_fileManager, _jsonConverter, _mockDataClient);

            var timeSlots = await service.ListSessions();

            Assert.AreEqual(1, timeSlots.Count);

            var slot = timeSlots.First();

            Assert.AreEqual(session.StartTime, slot.StartTime);
            Assert.AreEqual(session.EndTime, slot.EndTime);
            Assert.AreEqual(1, slot.Sessions.Count);
            Assert.AreEqual(session, slot.Sessions.First());
        }
        public async void GetSession_ValidSessionId_ReturnsSession()
        {
            var awesomeSession = new Session {Title = "Best Session Ever", Id = 42, SpeakerId = 1};
            var campData = new CampData
            {
                Sessions = new List<Session> { awesomeSession },
                Speakers = new List<Speaker> { new Speaker { Id = 1 } }
            };
            _mockDataClient.GetDataBody = () => Task.FromResult(campData);

            var service = new CodeCampService(_fileManager, _jsonConverter, _mockDataClient);

            var session = await service.GetSession(awesomeSession.Id);

            Assert.AreEqual(awesomeSession, session);
        }
        public async void ListSessionsBySpeaker_ValidSpeakerId_ReturnsSessionsForSpeaker()
        {
            int speakerId = 1;
            var correctSession = new Session {Id = 2, SpeakerId = speakerId};
            var wrongSession = new Session {Id = 3, SpeakerId = speakerId + 1};
            var campData = new CampData
                               {
                                   Sessions = new List<Session> {correctSession, wrongSession},
                                   Speakers = new List<Speaker> {new Speaker {Id = speakerId}}
                               };
            _mockDataClient.GetDataBody = () => Task.FromResult(campData);

            var service = new CodeCampService(_fileManager, _jsonConverter, _mockDataClient);

            var sessions = await service.ListSessionsBySpeaker(speakerId);

            Assert.AreEqual(1, sessions.Count);
            Assert.AreEqual(correctSession, sessions.First());
        }