Exemplo n.º 1
0
 public SonarrController(IThirdPartyService apiService, ISettingsService <SonarrSettingsViewModelDto> settingsService)
     : base(typeof(SonarrController))
 {
     ApiService      = apiService;
     SettingsService = settingsService;
     Settings        = SettingsService.GetSettings();
 }
Exemplo n.º 2
0
        public void ModifySettings()
        {
            var dto = new SonarrSettingsViewModelDto {
                Id = 1
            };
            var result = Service.SaveSettings(dto);

            Assert.That(result, Is.True);
            MockRepo.Verify(x => x.Get(1), Times.Once);
            MockRepo.Verify(x => x.Insert(It.IsAny <SonarrSettings>()), Times.Never);
            MockRepo.Verify(x => x.Update(It.IsAny <SonarrSettings>()), Times.Once);
        }
Exemplo n.º 3
0
        public void PostSonarrSettingsCouldNotSaveToDb()
        {
            var expectedDto = new SonarrSettingsViewModelDto {
                Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true
            };
            var settingsMock = new Mock <ISettingsService <SonarrSettingsViewModelDto> >();

            settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto);
            settingsMock.Setup(x => x.SaveSettings(It.IsAny <SonarrSettingsViewModelDto>())).Returns(false).Verifiable();

            _controller = new SettingsController(null, null, settingsMock.Object, null, null);

            var model = new SonarrSettingsViewModel();

            _controller.WithCallTo(x => x.SonarrSettings(model)).ShouldRenderView("Error");
        }
Exemplo n.º 4
0
        public ActionResult SonarrSettings(SonarrSettingsViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var dto = new SonarrSettingsViewModelDto();

            dto.InjectFrom(viewModel);

            var result = SonarrSettingsServiceSettingsService.SaveSettings(dto);

            if (result)
            {
                return(RedirectToAction("SonarrSettings"));
            }

            return(View("Error"));
        }
Exemplo n.º 5
0
        public void GetEpisodesForSeriesNoConfig()
        {
            SettingsMock = new Mock <ISettingsService <SonarrSettingsViewModelDto> >();
            ServiceMock  = new Mock <IThirdPartyService>();
            var f = new Fixture();

            ExpectedSettings = new SonarrSettingsViewModelDto();
            SonarrSeries     = f.CreateMany <SonarrSeries>().ToList();
            SonarrEpisode    = f.CreateMany <SonarrEpisode>().ToList();


            SettingsMock.Setup(x => x.GetSettings()).Returns(ExpectedSettings);
            ServiceMock.Setup(x => x.GetSonarrSeries(It.IsAny <string>(), It.IsAny <string>())).Returns(SonarrSeries);
            ServiceMock.Setup(x => x.GetSonarrEpisodes(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(SonarrEpisode);
            _controller = new SonarrController(ServiceMock.Object, SettingsMock.Object);

            var series = (PartialViewResult)_controller.GetEpisodes(1, "title");
            var model  = series.ViewBag;

            Assert.That(model.Error, Is.Not.Null);
        }
Exemplo n.º 6
0
        public void GetSonarrSettingsReturnsDefaultView()
        {
            var expectedDto = new SonarrSettingsViewModelDto {
                Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true
            };
            var settingsMock = new Mock <ISettingsService <SonarrSettingsViewModelDto> >();

            settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto).Verifiable();

            _controller = new SettingsController(null, null, settingsMock.Object, null, null);
            _controller.WithCallTo(x => x.SonarrSettings()).ShouldRenderDefaultView();

            var result = (ViewResult)_controller.SonarrSettings();
            var model  = (SonarrSettingsViewModel)result.Model;

            Assert.That(model.Enabled, Is.EqualTo(expectedDto.Enabled));
            Assert.That(model.Id, Is.EqualTo(expectedDto.Id));
            Assert.That(model.IpAddress, Is.EqualTo(expectedDto.IpAddress));
            Assert.That(model.ApiKey, Is.EqualTo(expectedDto.ApiKey));
            Assert.That(model.Port, Is.EqualTo(expectedDto.Port));
            Assert.That(model.ShowOnDashboard, Is.EqualTo(expectedDto.ShowOnDashboard));
        }