Esempio n. 1
0
        public ActionResult GetEpisodes(int id, string title)
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_Sonarr;
                return(PartialView("DashletError"));
            }

            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            var episodes  = ApiService.GetSonarrEpisodes(formattedUri, Settings.ApiKey, id);
            var viewModel = new SonarrEpisodeViewModel {
                EpisodeViewModels = new Dictionary <int, List <EpisodeViewModel> >(), SeasonTitle = title
            };

            foreach (var e in episodes)
            {
                var episodeViewModel = new EpisodeViewModel();

                if (!viewModel.EpisodeViewModels.ContainsKey(e.seasonNumber))
                {
                    viewModel.EpisodeViewModels.Add(e.seasonNumber, new List <EpisodeViewModel>());
                }
                var mappedResult = (EpisodeViewModel)episodeViewModel.InjectFrom(new SonarrEpisodeMapper(), e);
                viewModel.EpisodeViewModels[e.seasonNumber].Add(mappedResult);
            }

            return(PartialView("Episodes", viewModel));
        }
Esempio n. 2
0
        public ActionResult SearchForEpisode(int episodeId)
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_Sonarr;
                return(PartialView("DashletError"));
            }

            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            var result = ApiService.SonarrEpisodeSearch(formattedUri, Settings.ApiKey, episodeId);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult GetSeries()
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_Sonarr;
                return(PartialView("DashletError"));
            }

            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            var series    = ApiService.GetSonarrSeries(formattedUri, Settings.ApiKey);
            var viewModel = new List <SonarrSeriesViewModel>();

            foreach (var s in series)
            {
                var seriesViewModel = new SonarrSeriesViewModel();
                var mappedResult    = (SonarrSeriesViewModel)seriesViewModel
                                      .InjectFrom(new JsonSerializerTargetMapper <SonarrSeriesViewModel>(), s);

                DateTime convertedDate;
                DateTime.TryParse(mappedResult.FirstAired, out convertedDate);

                mappedResult.FirstAired = convertedDate.ToString("D");

                var images = s.images.Select(x => x.url);
                if (images.Any())
                {
                    mappedResult.ImageUrls = new List <string>();
                    foreach (var format in images.Select(image => string.Format("{0}{1}", formattedUri, image)))
                    {
                        mappedResult.ImageUrls.Add(format);
                    }
                }
                viewModel.Add(mappedResult);
            }

            return(PartialView("SeriesList", viewModel));
        }
Esempio n. 4
0
        public void GetSeries()
        {
            var series = (PartialViewResult)_controller.GetSeries();
            var model  = (List <SonarrSeriesViewModel>)series.Model;

            DateTime newDate;

            DateTime.TryParse(SonarrSeries[0].firstAired, out newDate);


            Assert.That(model.Count, Is.GreaterThan(0));
            Assert.That(model[0].Id, Is.EqualTo(SonarrSeries[0].id));
            Assert.That(model[0].ImdbId, Is.EqualTo(SonarrSeries[0].imdbId));
            Assert.That(model[0].Monitored, Is.EqualTo(SonarrSeries[0].monitored));
            Assert.That(model[0].FirstAired, Is.EqualTo(newDate.ToString("D")));
            Assert.That(model[0].EpisodeCount, Is.EqualTo(SonarrSeries[0].episodeCount));
            Assert.That(model[0].CleanTitle, Is.EqualTo(SonarrSeries[0].cleanTitle));
            Assert.That(model[0].AirTime, Is.EqualTo(SonarrSeries[0].airTime));
            Assert.That(model[0].Network, Is.EqualTo(SonarrSeries[0].network));
            Assert.That(model[0].NextAiring, Is.EqualTo(SonarrSeries[0].nextAiring));
            Assert.That(model[0].Overview, Is.EqualTo(SonarrSeries[0].overview));
            Assert.That(model[0].Path, Is.EqualTo(SonarrSeries[0].path));
            Assert.That(model[0].QualityProfileId, Is.EqualTo(SonarrSeries[0].qualityProfileId));
            Assert.That(model[0].Runtime, Is.EqualTo(SonarrSeries[0].runtime));
            Assert.That(model[0].SeasonCount, Is.EqualTo(SonarrSeries[0].seasonCount));
            Assert.That(model[0].SeasonFolder, Is.EqualTo(SonarrSeries[0].seasonFolder));
            Assert.That(model[0].SeriesType, Is.EqualTo(SonarrSeries[0].seriesType));
            Assert.That(model[0].Status, Is.EqualTo(SonarrSeries[0].status));
            Assert.That(model[0].Title, Is.EqualTo(SonarrSeries[0].title));
            Assert.That(model[0].TitleSlug, Is.EqualTo(SonarrSeries[0].titleSlug));
            Assert.That(model[0].Year, Is.EqualTo(SonarrSeries[0].year));
            Assert.That(model[0].ImageUrls[0], Is.EqualTo(UrlHelper.ReturnUri(ExpectedSettings.IpAddress, ExpectedSettings.Port) + SonarrSeries[0].images[0].url));

            ServiceMock.Verify(x => x.GetSonarrSeries(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            SettingsMock.Verify(x => x.GetSettings(), Times.Once);
        }