コード例 #1
0
        public async Task Init(NavigationParameters parameters)
        {
            bool successful = await SafeOperation(
                TaskEx.Run(async () => Sponsor = await _campService.GetSponsor(parameters.Id)));

            FinishedLoading(successful);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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());
        }