Пример #1
0
        public async Task <ActionResult <Theme> > Update(int pathId, int moduleId, int themeId,
                                                         [FromBody] UpdateTheme command)
        {
            if (pathId != command.PathId || moduleId != command.ModuleId || themeId != command.Id)
            {
                return(BadRequest());
            }

            return(Ok(await Mediator.Send(command)));
        }
Пример #2
0
        public async Task Update_ReturnsBadRequest_WhenRequestedIdDoesNotMatchCommandId()
        {
            var updateCommand = new UpdateTheme {
                Id = 1, PathId = 1, ModuleId = 1, Order = 0, Title = "Update title", Description = "Update Description"
            };
            var controller = new ThemesController(moqMediator.Object);

            var result = await controller.Update(1, 1, 2, updateCommand);

            Assert.IsInstanceOf(typeof(BadRequestResult), result.Result);
        }
Пример #3
0
        public Theme()
        {
            SetBlueTheme = new UpdateTheme(
                this,
                Colors.DeepSkyBlue,
                Colors.White);

            SetDarkTheme = new UpdateTheme(
                this,
                Colors.Black,
                Colors.Gray);
        }
Пример #4
0
        public void ShouldRequireValidModuleId()
        {
            var command = new UpdateTheme
            {
                Id          = 1,
                ModuleId    = 99999,
                Title       = "New Title",
                Description = "New Description",
                Necessity   = 0
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <NotFoundException>();
        }
Пример #5
0
        public async Task Update_ReturnsUpdatedTheme_WhenRequestedIdMatchesCommandId()
        {
            var updateCommand = new UpdateTheme {
                Id = 1, PathId = 1, ModuleId = 1, Order = 0, Title = "Update title", Description = "Update Description"
            };
            var controller = new ThemesController(moqMediator.Object);

            var result = await controller.Update(1, 1, 1, updateCommand);

            var content = GetObjectResultContent <Theme>(result.Result);

            Assert.IsInstanceOf(typeof(OkObjectResult), result.Result);
            Assert.IsNotNull(content);
            Assert.AreEqual(1, content.Id);
        }
Пример #6
0
        public async Task ShouldRequireUniqueTitle()
        {
            var module = await AddAsync(new Module
            {
                Title       = "New Module",
                Key         = "module-key",
                Description = "New Module Description",
                Paths       = new List <Path> {
                    new Path
                    {
                        Title       = "Some Path",
                        Key         = "some-path",
                        Description = "Some Path Description"
                    }
                }
            });

            await AddAsync(new Theme
            {
                Title       = "New Theme",
                Description = "New Theme Description",
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                },
                ModuleId = module.Id
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Other Theme",
                Description = "New Other Theme Description",
                ModuleId    = module.Id
            });

            var command = new UpdateTheme
            {
                Id          = theme.Id,
                ModuleId    = module.Id,
                Title       = "New Theme",
                Description = "Updated Description"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command))
            .Should().ThrowAsync <ValidationException>().Where(ex => ex.Errors.ContainsKey("Title"))
            .Result.And.Errors["Title"].Should().Contain("Theme with this title already exists in this module.");
        }
Пример #7
0
        public async Task ShouldUpdateTheme()
        {
            var userId = await RunAsDefaultUserAsync();

            var path = await AddAsync(new Path
            {
                Title       = "Some Path",
                Key         = "some-path",
                Description = "Some Path Description"
            });

            var module = await SendAsync(new CreateModule
            {
                Key         = "module-key",
                Title       = "Module Title",
                Description = "Module Decription"
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Theme",
                Description = "New Theme Description",
                ModuleId    = module.Id
            });

            var command = new UpdateTheme
            {
                PathId      = path.Id,
                ModuleId    = module.Id,
                Id          = theme.Id,
                Title       = "Updated title",
                Description = "Updated Description",
                Necessity   = 0
            };

            await SendAsync(command);

            var updatedTheme = await FindAsync <Theme>(theme.Id);

            updatedTheme.Title.Should().Be(command.Title);
            updatedTheme.Description.Should().Be(command.Description);
            updatedTheme.LastModifiedBy.Should().NotBeNull();
            updatedTheme.LastModifiedBy.Should().Be(userId);
            updatedTheme.LastModified.Should().NotBeNull();
            updatedTheme.LastModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(1000));
        }
Пример #8
0
        public async Task ShouldRequireDescription()
        {
            var module = await AddAsync(new Module
            {
                Title       = "New Module",
                Key         = "module-key",
                Description = "New Module Description",
                Paths       = new List <Path> {
                    new Path
                    {
                        Title       = "Some Path",
                        Key         = "some-path",
                        Description = "Some Path Description"
                    }
                }
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Theme",
                Description = "New Theme Description",
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                },
                ModuleId = module.Id
            });

            var command = new UpdateTheme
            {
                Id          = theme.Id,
                ModuleId    = module.Id,
                Title       = "New Theme",
                Description = "",
                Necessity   = 0
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command))
            .Should().ThrowAsync <ValidationException>().Where(ex => ex.Errors.ContainsKey("Description"))
            .Result.And.Errors["Description"].Should().Contain("Description is required.");
        }
Пример #9
0
        public async Task ShouldDisallowLongTitle()
        {
            var module = await AddAsync(new Module
            {
                Title       = "New Module",
                Key         = "module-key",
                Description = "New Module Description",
                Paths       = new List <Path> {
                    new Path
                    {
                        Title       = "Some Path",
                        Key         = "some-path",
                        Description = "Some Path Description"
                    }
                }
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Theme",
                Description = "New Theme Description",
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                },
                ModuleId = module.Id
            });

            var command = new UpdateTheme
            {
                Id          = theme.Id,
                Title       = "This theme title is too long and exceeds two hundred characters allowed for theme titles by CreateThemeCommandValidator. And this theme title in incredibly long and ugly. I imagine no one would create a title this long but just in case",
                Description = "New Description",
                Necessity   = 0
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command))
            .Should().ThrowAsync <ValidationException>().Where(ex => ex.Errors.ContainsKey("Title"))
            .Result.And.Errors["Title"].Should().Contain("Title must not exceed 200 characters.");
        }
Пример #10
0
        private void SaveTheme(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NameBox.Text))
            {
                return;
            }
            _themeViewModel.Theme.Name = NameBox.Text;
            var bg = BackgroundColor.SelectedColor.Value;

            _themeViewModel.Theme.Background = new SolidColorBrush(Color.FromRgb(bg.R, bg.G, bg.B));
            var fg = ForegroundColor.SelectedColor.Value;

            _themeViewModel.Theme.Foreground = new SolidColorBrush(Color.FromRgb(fg.R, fg.G, fg.B));
            var ho = HoverColor.SelectedColor.Value;

            _themeViewModel.Theme.Hover     = new SolidColorBrush(Color.FromRgb(ho.R, ho.G, ho.B));
            _themeViewModel.Theme.DarkIcons = !GetLuminance(bg);
            var themes = _settingsViewModel.Themes;
            var found  = false;

            for (var i = 0; i < themes.Count; i++)
            {
                if (themes[i].Id != _themeViewModel.Theme.Id)
                {
                    continue;
                }
                themes[i] = _themeViewModel.Theme;
                found     = true;
                break;
            }
            if (!found)
            {
                _settingsViewModel.Themes.Add(_themeViewModel.Theme);
            }
            _settingsViewModel.SaveThemes();
            UpdateTheme?.Invoke(null, null);
            this.Close();
        }