public void PostCouchPotatoSettingsReturnsDefaultView() { var expectedDto = new CouchPotatoSettingsDto { Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true, Password = "******", Username = "******" }; var settingsMock = new Mock <ISettingsService <CouchPotatoSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto); settingsMock.Setup(x => x.SaveSettings(It.IsAny <CouchPotatoSettingsDto>())).Returns(true); _controller = new SettingsController(null, null, null, settingsMock.Object, null, null, null, null, null, Logger); var model = new CouchPotatoSettingsViewModel(); _controller.WithCallTo(x => x.CouchPotatoSettings(model)).ShouldRedirectTo(c => c.CouchPotatoSettings); settingsMock.Verify(x => x.SaveSettings(It.IsAny <CouchPotatoSettingsDto>()), Times.Once); }
public void GetCouchPotatoSettings() { var expectedDto = new CouchPotatoSettingsDto { Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true, Password = "******", Username = "******" }; var settingsMock = new Mock <ISettingsService <CouchPotatoSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto).Verifiable(); _controller = new SettingsController(null, null, null, settingsMock.Object, null, null, null, null, null, Logger); _controller.WithCallTo(x => x.CouchPotatoSettings()).ShouldRenderDefaultView(); var result = (ViewResult)_controller.CouchPotatoSettings(); var model = (CouchPotatoSettingsViewModel)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)); Assert.That(model.Username, Is.EqualTo(expectedDto.Username)); Assert.That(model.Password, Is.EqualTo(expectedDto.Password)); }
public void ModifySettings() { var dto = new CouchPotatoSettingsDto { Id = 1 }; var result = Service.SaveSettings(dto); Assert.That(result, Is.Not.Null); Assert.That(result, Is.True); MockRepo.Verify(x => x.Get(1), Times.Once); MockRepo.Verify(x => x.Insert(It.IsAny <CouchPotatoSettings>()), Times.Never); MockRepo.Verify(x => x.Update(It.IsAny <CouchPotatoSettings>()), Times.Once); }
public void PostCouchPotatoSettingsBadModel() { var expectedDto = new CouchPotatoSettingsDto { Enabled = true, Id = 2, IpAddress = "192", ApiKey = "pass", Port = 2, ShowOnDashboard = true }; var settingsMock = new Mock <ISettingsService <CouchPotatoSettingsDto> >(); settingsMock.Setup(x => x.GetSettings()).Returns(expectedDto); settingsMock.Setup(x => x.SaveSettings(It.IsAny <CouchPotatoSettingsDto>())).Returns(true); _controller = new SettingsController(null, null, null, settingsMock.Object, null); var model = new CouchPotatoSettingsViewModel(); _controller.WithModelErrors().WithCallTo(x => x.CouchPotatoSettings(model)).ShouldRenderDefaultView().WithModel(model); settingsMock.Verify(x => x.SaveSettings(It.IsAny <CouchPotatoSettingsDto>()), Times.Never); }
public ActionResult CouchPotatoSettings(CouchPotatoSettingsViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var dto = new CouchPotatoSettingsDto(); dto.InjectFrom(viewModel); var result = CpSettingsService.SaveSettings(dto); if (result) { return(RedirectToAction("CouchPotatoSettings")); } return(View("Error")); }