public async Task Init(NavigationParameters parameters) { bool successful = await SafeOperation( TaskEx.Run(async () => Sponsor = await _campService.GetSponsor(parameters.Id))); FinishedLoading(successful); }
public async void ViewWebsiteCommand_Executed_GoesToSponsorWebsite() { var sponsor = new Sponsor { Id = 42, Website = "http://codecampnyc.org" }; var data = new CampData { Sponsors = new List<Sponsor> { sponsor } }; DataClient.GetDataBody = () => Task.FromResult(data); var viewModel = new SponsorViewModel(Messenger, CodeCampService, WebBrowserTask); await viewModel.Init(new SponsorViewModel.NavigationParameters(sponsor.Id)); viewModel.ViewWebsiteCommand.Execute(null); Assert.AreEqual(1, WebBrowserTask.UrlRequests.Count); Assert.AreEqual(sponsor.Website, WebBrowserTask.UrlRequests.First()); }
public void ViewSessionCommand_NavigatesToSession() { var sponsor = new Sponsor { Id = 42 }; var viewModel = new SponsorsViewModel(Messenger, CodeCampService); viewModel.ViewSponsorCommand.Execute(sponsor); Assert.AreEqual(1, Dispatcher.ShowViewModelRequests.Count); var request = Dispatcher.ShowViewModelRequests.Single(); var navParameters = request.ParameterValues.Read(typeof(SponsorViewModel.NavigationParameters)) as SponsorViewModel.NavigationParameters; Assert.NotNull(navParameters); Assert.AreEqual(sponsor.Id, navParameters.Id); }
public async void Init_DataLoadsSuccessfully_LoadsSponsor() { var sponsor = new Sponsor { Id = 42 }; var data = new CampData { Sponsors = new List<Sponsor> { sponsor } }; DataClient.GetDataBody = () => Task.FromResult(data); var viewModel = new SponsorViewModel(Messenger, CodeCampService, WebBrowserTask); Assert.True(viewModel.IsLoading); await viewModel.Init(new SponsorViewModel.NavigationParameters(sponsor.Id)); Assert.False(viewModel.IsLoading); Assert.AreEqual(sponsor, viewModel.Sponsor); }
public async void Init_DataLoadsSuccessfully_LoadsSponsorList() { var sponsor = new Sponsor {Name = "Sponsor", Tier = "Gold"}; var data = new CampData { Sponsors = new List<Sponsor> { sponsor } }; DataClient.GetDataBody = () => Task.FromResult(data); var viewModel = new SponsorsViewModel(Messenger, CodeCampService); Assert.True(viewModel.IsLoading); await viewModel.Init(); //Assert.AreEqual(data.Sponsors, viewModel.Sponsors); Assert.AreEqual(1, viewModel.SponsorTiers.Count); Assert.AreEqual(1, viewModel.SponsorTiers.First().Sponsors.Count); Assert.AreEqual(sponsor, viewModel.SponsorTiers.First().Sponsors.First()); Assert.False(viewModel.IsLoading); }
public async void GetSponsor_ValidSponsorId_ReturnsSponsor() { var awesomeSponsor = new Sponsor {Id = 42}; var campData = new CampData { Sponsors = new List<Sponsor> { awesomeSponsor } }; _mockDataClient.GetDataBody = () => Task.FromResult(campData); var service = new CodeCampService(_fileManager, _jsonConverter, _mockDataClient); var sponsor = await service.GetSponsor(awesomeSponsor.Id); Assert.AreEqual(awesomeSponsor, sponsor); }
public async void ListSponsors_FetchesDataAndReturnsSponsors() { var sponsor = new Sponsor {Id = 42, Tier = "Gold" }; var campData = new CampData { Sponsors = new List<Sponsor> { sponsor } }; _mockDataClient.GetDataBody = () => Task.FromResult(campData); var service = new CodeCampService(_fileManager, _jsonConverter, _mockDataClient); var tiers = await service.ListSponsors(); Assert.AreEqual(1, tiers.Count); Assert.AreEqual(1, tiers.First().Sponsors.Count); Assert.AreEqual(sponsor, tiers.First().Sponsors.First()); }