public void Should_have_validation_error_when_language_id_is_empty()
        {
            var command = new MenuItemLocalisation
            {
                LanguageId = Guid.Empty,
                Text       = "Text",
                Title      = "Title"
            };

            var languageRulesMock = new Mock <ILanguageRules>();
            var validator         = new MenuItemLocalisationValidator(languageRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.LanguageId, command);
        }
        public void Should_have_validation_error_when_language_does_not_exist()
        {
            var localisation = new MenuItemLocalisation
            {
                LanguageId = Guid.NewGuid(),
                Text       = "Text",
                Title      = "Title"
            };

            var languageRulesMock = new Mock <ILanguageRules>();

            languageRulesMock.Setup(x => x.DoesLanguageExist(localisation.LanguageId)).Returns(false);

            var validator = new MenuItemLocalisationValidator(languageRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.LanguageId, localisation);
        }
示例#3
0
        public void Setup()
        {
            _menu = new Menu();

            _command = new AddMenuItem
            {
                SiteId                = _menu.SiteId,
                MenuId                = Guid.NewGuid(),
                MenuItemId            = Guid.NewGuid(),
                MenuItemType          = MenuItemType.Link,
                PageId                = Guid.NewGuid(),
                Link                  = "link",
                Text                  = "Text",
                Title                 = "Title",
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>
                {
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 1",
                        Title      = "Title 1"
                    },
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 2",
                        Title      = "Title 2"
                    }
                }
            };

            _validatorMock = new Mock <IValidator <AddMenuItem> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _menu.AddMenuItem(_command, _validatorMock.Object);

            _menuItem = _menu.MenuItems.FirstOrDefault(c => c.Id == _command.MenuItemId);

            _firstMenuItemLocalisation = _menuItem.MenuItemLocalisations.FirstOrDefault();

            _event = _menu.Events.OfType <MenuItemAdded>().SingleOrDefault();
        }
        public void Should_have_validation_error_when_title_is_too_long()
        {
            var title = string.Empty;

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

            var command = new MenuItemLocalisation
            {
                LanguageId = Guid.NewGuid(),
                Text       = "Text",
                Title      = title
            };

            var languageRulesMock = new Mock <ILanguageRules>();
            var validator         = new MenuItemLocalisationValidator(languageRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.Title, command);
        }