Example #1
0
        public async Task ShouldReturnNotfoundForNonExistingSection()
        {
            //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
            {
                Title       = "Module Title",
                Key         = "module-key",
                Description = "Module Decription"
            });

            var command = new CreateTheme
            {
                ModuleId    = module.Id,
                Title       = "New Theme",
                Description = "New Theme Description",
                Necessity   = Necessity.Other,
                Complexity  = Complexity.Beginner,
                Order       = 1,
                SectionId   = 999
            };

            await FluentActions.Invoking(() =>
                                         SendAsync(command)).Should().ThrowAsync <NotFoundException>();
        }
        public void Should_validate_command_and_save_new_theme()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRepositoryMock = new Mock <IThemeRepository>();

            themeRepositoryMock.Setup(x => x.Create(It.IsAny <Theme>()));

            var validatorMock = new Mock <IValidator <CreateTheme> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var sortOrderGeneratorMock = new Mock <IThemeSortOrderGenerator>();

            var createThemeHandler = new CreateThemeHandler(themeRepositoryMock.Object, validatorMock.Object, sortOrderGeneratorMock.Object);

            createThemeHandler.Handle(command);

            validatorMock.Verify(x => x.Validate(command));
            themeRepositoryMock.Verify(x => x.Create(It.IsAny <Theme>()));
        }
Example #3
0
        public async Task <IActionResult> Post([FromBody] CreateTheme model)
        {
            model.Id = Guid.NewGuid();
            await Task.Run(() => _commandSender.Send <CreateTheme, Theme>(model));

            return(new NoContentResult());
        }
Example #4
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateTheme();

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>();
        }
Example #5
0
        public void Setup()
        {
            _themeId      = Guid.NewGuid();
            _newSortOrder = 1;

            var command = new CreateTheme
            {
                Id          = _themeId,
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var validatorMock = new Mock <IValidator <CreateTheme> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var sortOrderGeneratorMock = new Mock <IThemeSortOrderGenerator>();

            sortOrderGeneratorMock.Setup(x => x.GenerateNextSortOrder()).Returns(2);

            _theme = Theme.CreateNew(command, validatorMock.Object, sortOrderGeneratorMock.Object);

            _theme.Reorder(_newSortOrder);

            _event = _theme.Events.OfType <ThemeReordered>().SingleOrDefault();
        }
Example #6
0
        public static Theme CreateNew(CreateTheme cmd,
                                      IValidator <CreateTheme> validator,
                                      IThemeSortOrderGenerator sortOrderGenerator)
        {
            validator.ValidateCommand(cmd);

            return(new Theme(cmd, sortOrderGenerator));
        }
Example #7
0
        public async Task Create_ReturnsBadRequest_WhenRequestedModuleIdDoesNotMatchCommandModuleId()
        {
            var createCommand = new CreateTheme {
                PathId = 1, ModuleId = 1, Order = 0, Title = "Create title", Description = "Create Description"
            };
            var controller = new ThemesController(moqMediator.Object);

            var result = await controller.Create(1, 2, createCommand);

            Assert.IsInstanceOf(typeof(BadRequestResult), result.Result);
        }
Example #8
0
        public void ShouldReturnNotFoundForNonExistingModule()
        {
            var command = new CreateTheme
            {
                ModuleId    = 999,
                Title       = "Theme Title",
                Description = "Theme Decription"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <NotFoundException>();
        }
Example #9
0
 private Theme(CreateTheme cmd, IThemeSortOrderGenerator themeSortOrderGenerator) : base(cmd.Id)
 {
     AddEvent(new ThemeCreated
     {
         AggregateRootId = Id,
         Name            = cmd.Name,
         Description     = cmd.Description,
         Folder          = cmd.Folder,
         SortOrder       = themeSortOrderGenerator.GenerateNextSortOrder(),
         Status          = ThemeStatus.Hidden
     });
 }
Example #10
0
        public void ShouldRequireDescription()
        {
            var command = new CreateTheme
            {
                ModuleId = 1,
                Title    = "Theme Title"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Description"))
            .Result.And.Errors["Description"].Should().Contain("Description is required.");
        }
Example #11
0
        public async Task <ActionResult <Theme> > Create(int pathId, int moduleId,
                                                         [FromBody] CreateTheme command)
        {
            if (pathId != command.PathId || moduleId != command.ModuleId)
            {
                return(BadRequest());
            }

            Theme model = await Mediator.Send(command);

            return(CreatedAtRoute("GetTheme",
                                  new { pathId = command.PathId, moduleId = model.ModuleId, themeId = model.Id }, model));
        }
Example #12
0
 private void button3_Click(object sender, EventArgs e)
 {
     CreateTheme.Visible = true;
     CreateTheme.BringToFront();
     resizecreatetheme();
     categoryin.Visible = false;
     themehead.Visible  = false;
     themetwit.Visible  = false;
     for (int i = 0; i < разделDataGridView.RowCount; i++)
     {
         comboBox1.Items.Add(Convert.ToString(разделDataGridView[0, i].Value));
     }
 }
Example #13
0
        public void ShouldDisallowLongTitle()
        {
            var command = new CreateTheme
            {
                ModuleId    = 1,
                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 = "Theme Decription"
            };

            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.");
        }
        public void Should_have_validation_error_when_theme_name_is_empty()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = string.Empty,
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRulesMock = new Mock <IThemeRules>();
            var validator      = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Name, command);
        }
Example #15
0
        public async Task ShouldCreateThemeWithExistingSection()
        {
            //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
            {
                Title       = "Module Title",
                Key         = "module-key",
                Description = "Module Decription"
            });

            var sect = await AddAsync(new Section
            {
                ModuleId = module.Id,
                Title    = "First Section"
            });

            var command = new CreateTheme
            {
                PathId      = path.Id,
                ModuleId    = module.Id,
                Title       = "New Theme",
                Description = "New Theme Description",
                Necessity   = Necessity.Other,
                Complexity  = Complexity.Beginner,
                Order       = 1,
                SectionId   = sect.Id
            };

            var createdTheme = await SendAsync(command);

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

            theme.Should().NotBeNull();
            theme.Title.Should().Be(command.Title);
            theme.Description.Should().Be(command.Description);
            theme.ModuleId.Should().Be(module.Id);
            theme.Necessity.Should().Be(command.Necessity);
            //theme.CreatedBy.Should().Be(userId);
            theme.Created.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(1000));
        }
Example #16
0
 public void Setup()
 {
     _command = new CreateTheme
     {
         Id          = Guid.NewGuid(),
         Name        = "Name",
         Description = "Description",
         Folder      = "Folder"
     };
     _validatorMock = new Mock <IValidator <CreateTheme> >();
     _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());
     _sortOrderGeneratorMock = new Mock <IThemeSortOrderGenerator>();
     _sortOrderGeneratorMock.Setup(x => x.GenerateNextSortOrder()).Returns(4);
     _theme = Theme.CreateNew(_command, _validatorMock.Object, _sortOrderGeneratorMock.Object);
     _event = _theme.Events.OfType <ThemeCreated>().SingleOrDefault();
 }
Example #17
0
        public async Task Create_ReturnsCreatedAtRoute()
        {
            var createCommand = new CreateTheme {
                PathId = 1, ModuleId = 1, Order = 0, Title = "Create title", Description = "Create Description"
            };
            var controller = new ThemesController(moqMediator.Object);

            var result = await controller.Create(1, 1, createCommand);

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

            Assert.IsInstanceOf(typeof(CreatedAtRouteResult), result.Result);
            Assert.AreEqual("GetTheme", ((CreatedAtRouteResult)result.Result).RouteName);
            Assert.IsNotNull(content);
            Assert.AreEqual(1, content.Id);
        }
Example #18
0
        public void EnsureThemeInstalled(CreateTheme createTheme)
        {
            if (_queryDispatcher.Dispatch <IsThemeInstalled, bool>(new IsThemeInstalled {
                Name = createTheme.Name
            }))
            {
                return;
            }

            var newThemeId = Guid.NewGuid();

            createTheme.Id = newThemeId;

            _commandSender.Send <CreateTheme, Theme>(createTheme, false);
            _commandSender.Send <ActivateTheme, Theme>(new ActivateTheme {
                Id = newThemeId
            }, false);
        }
Example #19
0
        public void EnsureThemeInstalled(CreateTheme createTheme)
        {
            if (_dispatcher.GetResult <IsThemeInstalled, bool>(new IsThemeInstalled {
                Name = createTheme.Name
            }))
            {
                return;
            }

            var newThemeId = Guid.NewGuid();

            createTheme.Id = newThemeId;

            _dispatcher.SendAndPublish <CreateTheme, Theme>(createTheme);
            _dispatcher.SendAndPublish <ActivateTheme, Theme>(new ActivateTheme {
                Id = newThemeId
            });
        }
        public void Should_have_validation_error_when_theme_name_is_not_unique()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRulesMock = new Mock <IThemeRules>();

            themeRulesMock.Setup(x => x.IsThemeNameUnique(command.Name, Guid.Empty)).Returns(false);

            var validator = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Name, command);
        }
        public void Should_have_validation_error_when_folder_is_not_valid()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "a@b"
            };

            var themeRulesMock = new Mock <IThemeRules>();

            themeRulesMock.Setup(x => x.IsThemeFolderValid(command.Folder)).Returns(false);

            var validator = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Folder, command);
        }
        public void Should_have_validation_error_when_theme_id_already_exists()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRulesMock = new Mock <IThemeRules>();

            themeRulesMock.Setup(x => x.IsThemeIdUnique(command.Id)).Returns(false);

            var siteRulesMock = new Mock <ISiteRules>();
            var validator     = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Id, command);
        }
Example #23
0
        public static Theme Theme(Guid id, string name, string description, string folder)
        {
            var command = new CreateTheme
            {
                Id          = id,
                Name        = name,
                Description = description,
                Folder      = folder
            };

            var validatorMock = new Mock <IValidator <CreateTheme> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var sortOrderGeneratorMock = new Mock <IThemeSortOrderGenerator>();

            sortOrderGeneratorMock.Setup(x => x.GenerateNextSortOrder()).Returns(2);

            return(Domain.Themes.Theme.CreateNew(command, validatorMock.Object, sortOrderGeneratorMock.Object));
        }
        public void Should_have_validation_error_when_theme_name_is_too_long()
        {
            var name = "";

            for (int i = 0; i < 101; i++)
            {
                name += i;
            }

            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = name,
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRulesMock = new Mock <IThemeRules>();
            var validator      = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Name, command);
        }
        public void Should_have_validation_error_when_folder_is_too_long()
        {
            var folder = "";

            for (int i = 0; i < 251; i++)
            {
                folder += i;
            }

            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = folder
            };

            var themeRulesMock = new Mock <IThemeRules>();
            var validator      = new CreateThemeValidator(themeRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Folder, command);
        }
        public void Should_throw_validation_exception_when_validation_fails()
        {
            var command = new CreateTheme
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var themeRepositoryMock = new Mock <IThemeRepository>();

            var validatorMock = new Mock <IValidator <CreateTheme> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> {
                new ValidationFailure("Id", "Id Error")
            }));

            var sortOrderGeneratorMock = new Mock <IThemeSortOrderGenerator>();

            var createThemeHandler = new CreateThemeHandler(themeRepositoryMock.Object, validatorMock.Object, sortOrderGeneratorMock.Object);

            Assert.Throws <ValidationException>(() => createThemeHandler.Handle(command));
        }
Example #27
0
        public async Task ShouldRequireUniqueTitle()
        {
            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"
            });

            await SendAsync(new CreateTheme
            {
                PathId      = path.Id,
                ModuleId    = module.Id,
                Title       = "Theme Title",
                Description = "Theme Decription"
            });

            var command = new CreateTheme
            {
                ModuleId    = module.Id,
                Title       = "Theme Title",
                Description = "Theme Decription"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Title"))
            .Result.And.Errors["Title"].Should().Contain("The specified theme already exists in this module.");
        }
Example #28
0
 public IActionResult Save(CreateTheme model)
 {
     model.Id = Guid.NewGuid();
     _dispatcher.SendAndPublish <CreateTheme, Theme>(model);
     return(new NoContentResult());
 }
Example #29
0
 public IActionResult Post([FromBody] CreateTheme model)
 {
     model.Id = Guid.NewGuid();
     _commandSender.Send <CreateTheme, Theme>(model);
     return(new NoContentResult());
 }