public SonarrController(IThirdPartyService apiService, ISettingsService <SonarrSettingsDto> settingsService) : base(typeof(SonarrController)) { ApiService = apiService; SettingsService = settingsService; Settings = SettingsService.GetSettings(); }
public SonarrController(IThirdPartyService apiService, ISettingsService <SonarrSettingsDto> settingsService, ILogger logger) : base(logger) { ApiService = apiService; SettingsService = settingsService; Settings = SettingsService.GetSettings(); }
public void PostSonarrSettingsReturnsErrorWithBadModel() { var expectedDto = new SonarrSettingsDto { Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true }; var settingsMock = new Mock <ISettingsService <SonarrSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto); settingsMock.Setup(x => x.SaveSettings(It.IsAny <SonarrSettingsDto>())).Returns(true).Verifiable(); _controller = new SettingsController(null, null, settingsMock.Object, null, null, null, null, null, null, Logger); var model = new SonarrSettingsViewModel(); _controller.WithModelErrors().WithCallTo(x => x.SonarrSettings(model)).ShouldRenderDefaultView().WithModel(model); }
public ActionResult SonarrSettings(SonarrSettingsViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var dto = new SonarrSettingsDto(); dto.InjectFrom(viewModel); var result = SonarrSettingsService.SaveSettings(dto); if (result) { return(RedirectToAction("SonarrSettings")); } return(View("Error")); }
public void GetEpisodesForSeriesNoConfig() { SettingsMock = new Mock <ISettingsService <SonarrSettingsDto> >(); ServiceMock = new Mock <IThirdPartyService>(); var f = new Fixture(); ExpectedSettings = new SonarrSettingsDto(); 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, LoggerMock.Object); var series = (PartialViewResult)_controller.GetEpisodes(1, "title"); var model = series.ViewBag; Assert.That(model.Error, Is.Not.Null); }
public void GetSonarrSettingsReturnsDefaultView() { var expectedDto = new SonarrSettingsDto { Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true }; var settingsMock = new Mock <ISettingsService <SonarrSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto).Verifiable(); _controller = new SettingsController(null, null, settingsMock.Object, null, null, null, null, null, null, Logger); _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)); }