public void Should_provide_enumerators()
        {
            var config = LanguagesConfig.Create();

            Assert.Equal(0, config.Count);

            Assert.NotNull(((IEnumerable)config).GetEnumerator());
            Assert.NotNull(((IEnumerable <IFieldPartitionItem>)config).GetEnumerator());
        }
        public void Should_update_language()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT).Update(Language.IT, true, false, new[] { Language.DE });

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE),
                new LanguageConfig(Language.IT, true, Language.DE)
            });
        }
        public void Should_add_language()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT);

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE),
                new LanguageConfig(Language.IT)
            });
        }
        public void Should_remove_language()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT).Add(Language.RU).Remove(Language.IT);

            config.ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE),
                new LanguageConfig(Language.RU)
            });
        }
        public void Should_create_initial_config_with_multiple_languages()
        {
            var config = LanguagesConfig.Create(Language.DE, Language.EN, Language.IT);

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE),
                new LanguageConfig(Language.EN),
                new LanguageConfig(Language.IT)
            });

            Assert.Equal(Language.DE, config.Master.Language);
        }
        public void Should_create_initial_config_with_configs()
        {
            var configs = new[]
            {
                new LanguageConfig(Language.DE),
                new LanguageConfig(Language.EN),
                new LanguageConfig(Language.IT)
            };
            var config = LanguagesConfig.Create(configs);

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(configs);

            Assert.Equal(configs[0], config.Master);
        }
        public void Should_create_initial_config()
        {
            var config = LanguagesConfig.Create(Language.DE);

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE)
            });

            Assert.Equal(Language.DE, config.Master.Language);

            Assert.Equal("de", ((IFieldPartitioning)config).Master.Key);
        }
        public void Should_remove_fallbacks_when_removing_language()
        {
            var config =
                LanguagesConfig.Create(Language.DE)
                .Add(Language.IT)
                .Add(Language.RU)
                .Update(Language.DE, false, false, new[] { Language.RU, Language.IT })
                .Update(Language.RU, false, false, new[] { Language.DE, Language.IT })
                .Remove(Language.IT);

            config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(
                new List <LanguageConfig>
            {
                new LanguageConfig(Language.DE, false, Language.RU),
                new LanguageConfig(Language.RU, false, Language.DE)
            });
        }
        public async Task Should_not_add_error_if_required_field_has_no_value_for_optional_language()
        {
            var optionalConfig =
                LanguagesConfig.Create(Language.ES, Language.IT).Update(Language.IT, true, false, null);

            schema = schema.AddOrUpdateField(new StringField(1, "my-field", Partitioning.Language, new StringFieldProperties {
                IsRequired = true
            }));

            var data =
                new ContentData()
                .AddField("my-field",
                          new ContentFieldData()
                          .AddValue("es", "value"));

            await data.ValidateAsync(schema, optionalConfig.ToResolver(), errors);

            Assert.Equal(0, errors.Count);
        }
        public void Should_not_throw_exception_if_language_is_already_master_language()
        {
            var config = LanguagesConfig.Create(Language.DE);

            config.MakeMaster(Language.DE);
        }
        public void Should_throw_exception_if_language_to_add_already_exists()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <ValidationException>(() => config.Add(Language.DE));
        }
        public void Should_make_master_language()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT).MakeMaster(Language.IT);

            Assert.Equal(Language.IT, config.Master.Language);
        }
        public void Should_throw_exception_if_language_to_remove_is_master_language()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <ValidationException>(() => config.Remove(Language.DE));
        }
        public void Should_throw_exception_if_language_to_remove_is_not_found()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <DomainObjectNotFoundException>(() => config.Remove(Language.EN));
        }
        public void Should_also_set_make_master_when_updating_language()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT).Update(Language.IT, false, true, null);

            Assert.Equal(Language.IT, config.Master.Language);
        }
        public void Should_throw_exception_if_language_to_update_is_not_found()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <DomainObjectNotFoundException>(() => config.Update(Language.EN, true, false, null));
        }
        public void Should_throw_exception_if_language_to_make_optional_must_be_set_to_master()
        {
            var config = LanguagesConfig.Create(Language.DE).Add(Language.IT);

            Assert.Throws <ValidationException>(() => config.Update(Language.DE, true, true, null));
        }
        public void Should_throw_exception_if_language_to_make_optional_is_master_language()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <ValidationException>(() => config.Update(Language.DE, true, false, null));
        }
        public void Should_throw_exception_if_fallback_language_is_invalid()
        {
            var config = LanguagesConfig.Create(Language.DE);

            Assert.Throws <ValidationException>(() => config.Update(Language.DE, false, false, new[] { Language.EN }));
        }