public void PostNzbDashSettingsReturnsErrorWithBadModel() { var expectedDto = new NzbDashSettingsDto { Id = 2, Authenticate = true }; var settingsMock = new Mock <ISettingsService <NzbDashSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto); settingsMock.Setup(x => x.SaveSettings(It.IsAny <NzbDashSettingsDto>())).Returns(true).Verifiable(); _controller = new SettingsController(null, null, null, null, null, settingsMock.Object, null, null, null, Logger); var model = new NzbDashSettingsViewModel(); _controller.WithModelErrors().WithCallTo(x => x.NzbDashSettings(model)).ShouldRenderDefaultView().WithModel(model); }
public void GetNzbDashSettingsReturnsDefaultViewWithModel() { var expectedDto = new NzbDashSettingsDto { Id = 2, Authenticate = false }; var settingsMock = new Mock <ISettingsService <NzbDashSettingsDto> >(); var authMock = new Mock <IAuthenticationService>(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto).Verifiable(); _controller = new SettingsController(null, null, null, null, null, settingsMock.Object, authMock.Object, null, null, Logger); _controller.WithCallTo(x => x.NzbDashSettings()).ShouldRenderDefaultView(); var result = (ViewResult)_controller.NzbDashSettings(); var model = (NzbDashSettingsViewModel)result.Model; Assert.That(model.Authenticate, Is.EqualTo(expectedDto.Authenticate)); Assert.That(model.Id, Is.EqualTo(expectedDto.Id)); }
public ActionResult NzbDashSettings(NzbDashSettingsViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var dto = new NzbDashSettingsDto(); dto.InjectFrom(model); var result = NzbDashServiceSettings.SaveSettings(dto); if (result) { return(RedirectToAction("NzbDashSettings")); } return(View("Error")); }
public void GetNzbDashSettingsWithoutUsers() { var expectedDto = new NzbDashSettingsDto { Id = 2, Authenticate = false, FinishedIntro = true }; var settingsMock = new Mock <ISettingsService <NzbDashSettingsDto> >(); var authMock = new Mock <IAuthenticationService>(); authMock.Setup(x => x.GetAllUsers()).Returns(Enumerable.Empty <User>().AsQueryable()); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto).Verifiable(); _controller = new SettingsController(null, null, null, null, null, settingsMock.Object, authMock.Object, null, null, Logger); _controller.WithCallTo(x => x.NzbDashSettings()).ShouldRenderDefaultView(); var result = (ViewResult)_controller.NzbDashSettings(); var model = (NzbDashSettingsViewModel)result.Model; Assert.That(model.Authenticate, Is.EqualTo(expectedDto.Authenticate)); Assert.That(model.FinishedIntro, Is.EqualTo(expectedDto.FinishedIntro)); Assert.That(model.UserExist, Is.EqualTo(false)); Assert.That(model.Id, Is.EqualTo(expectedDto.Id)); }