예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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"));
        }