public void Should_build_json_schema() { var languagesConfig = LanguagesConfig.Build(Language.DE, Language.EN); var jsonSchema = schema.BuildJsonSchema(languagesConfig.ToResolver(), (n, s) => new JsonSchema4 { Reference = s }); var jsonProperties = AllPropertyNames(jsonSchema); void CheckField(IField field) { if (!field.IsForApi()) { Assert.DoesNotContain(field.Name, jsonProperties); } else { Assert.Contains(field.Name, jsonProperties); } if (field is IArrayField array) { foreach (var nested in array.Fields) { CheckField(nested); } } } foreach (var field in schema.Fields) { CheckField(field); } }
public void Should_not_resolve_language_fór_invalid_language() { var config_0 = LanguagesConfig.Build(Language.DE); Assert.False(config_0.TryGetItem("invalid", out var item)); Assert.Null(item); }
public void Should_resolve_language_by_string() { var config_0 = LanguagesConfig.Build(Language.DE); Assert.True(config_0.TryGetItem("de", out var item)); Assert.NotNull(item); }
public void Should_do_nothing_if_language_to_remove_is_not_found() { var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Remove(Language.EN); Assert.Equal(config_0, config_1); }
private static IAppEntity GetApp() { var app = A.Fake <IAppEntity>(); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.EN, Language.DE)); return(app); }
public void Should_build_edm_model() { var languagesConfig = LanguagesConfig.Build(Language.DE, Language.EN); var edmModel = TestData.MixedSchema().BuildEdmType(languagesConfig.ToResolver(), x => x); Assert.NotNull(edmModel); }
public GraphQLTestBase() { schemaDef = new Schema("my-schema") .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(3, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddNumber(4, "my_number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(5, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(6, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(7, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(8, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }) .AddReferences(9, "my-invalid", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddTags(11, "my-tags", Partitioning.Invariant, new TagsFieldProperties()) .AddString(12, "my-localized", Partitioning.Language, new StringFieldProperties()) .AddArray(13, "my-array", Partitioning.Invariant, f => f .AddBoolean(121, "nested-boolean") .AddNumber(122, "nested-number") .AddNumber(123, "nested_number")) .ConfigureScripts(new SchemaScripts { Query = "<query-script>" }) .Publish(); A.CallTo(() => app.Id).Returns(appId); A.CallTo(() => app.Name).Returns(appName); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE, Language.GermanGermany)); context = QueryContext.Create(app, user); A.CallTo(() => schema.Id).Returns(schemaId); A.CallTo(() => schema.SchemaDef).Returns(schemaDef); var allSchemas = new List <ISchemaEntity> { schema }; A.CallTo(() => appProvider.GetSchemasAsync(appId)).Returns(allSchemas); sut = new CachingGraphQLService(cache, appProvider, assetQuery, contentQuery, new FakeUrlGenerator()); }
public void Should_provide_enumerators() { var config_0 = LanguagesConfig.Build(Language.DE); Assert.NotEmpty(config_0); Assert.NotNull(((IEnumerable)config_0).GetEnumerator()); Assert.NotNull(((IEnumerable <IFieldPartitionItem>)config_0).GetEnumerator()); }
public void On(AppCreated @event, EnvelopeHeaders headers) { App = EntityMapper.Create <JsonAppEntity>(@event, headers, a => { SimpleMapper.Map(@event, a); a.LanguagesConfig = LanguagesConfig.Build(Language.EN); }); }
public void Should_build_data_schema() { var languagesConfig = LanguagesConfig.Build(Language.DE, Language.EN); var jsonSchema = schema.BuildJsonSchema(languagesConfig.ToResolver(), (n, s) => new JsonSchema4 { Reference = s }); Assert.NotNull(new ContentSchemaBuilder().CreateContentSchema(schema, jsonSchema)); }
public void Should_make_master_language() { var config = LanguagesConfig.Build(Language.DE); config.Set(new LanguageConfig(Language.UK)); config.Set(new LanguageConfig(Language.IT)); config.MakeMaster(Language.IT); Assert.Equal(Language.IT, config.Master.Language); }
public void Should_build_json_schema() { var languagesConfig = LanguagesConfig.Build(Language.DE, Language.EN); var jsonSchema = schema.BuildJsonSchema(languagesConfig.ToResolver(), (n, s) => new JsonSchema4 { Reference = s }); Assert.NotNull(jsonSchema); }
public void Should_make_master_language() { var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Set(new LanguageConfig(Language.UK)); var config_2 = config_1.Set(new LanguageConfig(Language.IT)); var config_3 = config_2.MakeMaster(Language.IT); Assert.Equal(Language.IT, config_3.Master.Language); }
public void Should_return_same_languages_if_master_language_is_already_master() { var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Set(Language.UK); var config_2 = config_1.Set(Language.IT); var config_3 = config_2.MakeMaster(Language.IT); var config_4 = config_3.MakeMaster(Language.IT); Assert.Same(config_3, config_4); }
protected Task On(AppCreated @event, EnvelopeHeaders headers) { return(Collection.CreateAsync(@event, headers, a => { SimpleMapper.Map(@event, a); a.Clients = new AppClients(); a.Contributors = new AppContributors(); a.LanguagesConfig = LanguagesConfig.Build(Language.EN); })); }
public void Should_remove_language() { var config_0 = LanguagesConfig.Build(Language.DE, Language.IT, Language.RU); var config_1 = config_0.Remove(Language.IT); config_1.ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE), new LanguageConfig(Language.RU) }); }
public GraphQLTestBase() { var schemaDef = new Schema("my-schema") .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(3, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddNumber(4, "my_number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(5, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(6, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(7, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(8, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }) .AddReferences(9, "my-invalid", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddTags(11, "my-tags", Partitioning.Invariant, new TagsFieldProperties()) .AddString(12, "my-localized", Partitioning.Language, new StringFieldProperties()) .AddArray(13, "my-array", Partitioning.Invariant, f => f .AddBoolean(121, "nested-boolean") .AddNumber(122, "nested-number") .AddNumber(123, "nested_number")) .ConfigureScripts(new SchemaScripts { Query = "<query-script>" }) .Publish(); A.CallTo(() => app.Id).Returns(appId); A.CallTo(() => app.Name).Returns(appName); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE, Language.GermanGermany)); context = new Context(user, app); A.CallTo(() => schema.Id).Returns(schemaId); A.CallTo(() => schema.SchemaDef).Returns(schemaDef); sut = CreateSut(); }
public void Should_update_language() { var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Set(new LanguageConfig(Language.IT)); var config_2 = config_1.Set(new LanguageConfig(Language.IT, true, Language.DE)); config_2.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE), new LanguageConfig(Language.IT, true, Language.DE) }); }
public void Should_build_edm_model() { var languagesConfig = LanguagesConfig.Build(Language.DE, Language.EN); var typeFactory = new EdmTypeFactory(names => { return(new EdmComplexType("Squidex", string.Join(".", names)), true); }); var edmModel = TestUtils.MixedSchema().BuildEdmType(true, languagesConfig.ToResolver(), typeFactory); Assert.NotNull(edmModel); }
public void Should_serialize_and_deserialize() { var languages = LanguagesConfig.Build( new LanguageConfig(Language.EN), new LanguageConfig(Language.DE, true, Language.EN), new LanguageConfig(Language.IT, false, Language.DE)) .MakeMaster(Language.IT); var serialized = languages.SerializeAndDeserialize(); serialized.Should().BeEquivalentTo(languages); Assert.Same(serialized.FirstOrDefault(x => x.Key == "it"), serialized.Master); }
public void Should_create_initial_config_0() { var config_0 = LanguagesConfig.Build(Language.DE); config_0.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE) }); Assert.Equal(Language.DE, config_0.Master.Language); Assert.Equal("de", ((IFieldPartitioning)config_0).Master.Key); }
public void Should_serialize_and_deserialize() { var sut = LanguagesConfig.Build( new LanguageConfig(Language.EN), new LanguageConfig(Language.DE, true, Language.EN), new LanguageConfig(Language.IT, false, Language.DE)) .MakeMaster(Language.IT); var serialized = JToken.FromObject(sut, serializer).ToObject <LanguagesConfig>(serializer); serialized.Should().BeEquivalentTo(sut); Assert.Same(serialized.FirstOrDefault(x => x.Key == "it"), serialized.Master); }
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.Build(configs); config.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo(configs); Assert.Equal(configs[0], config.Master); }
public void Should_remove_language() { var config_0 = LanguagesConfig.Build(Language.DE, Language.IT, Language.RU); var config_1 = config_0.Remove(Language.IT); Assert.Same(config_1.Master, config_1.OfType <LanguageConfig>().FirstOrDefault(x => x.Language == Language.DE)); config_1.ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE), new LanguageConfig(Language.RU) }); }
public GraphQLTestBase() { schemaDef = new Schema("my-schema") .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(3, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(4, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(5, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(6, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(7, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }) .AddReferences(9, "my-invalid", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddTags(11, "my-tags", Partitioning.Invariant, new TagsFieldProperties()); A.CallTo(() => app.Id).Returns(appId); A.CallTo(() => app.Name).Returns(appName); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE)); context = QueryContext.Create(app, user); A.CallTo(() => schema.Id).Returns(schemaId); A.CallTo(() => schema.Name).Returns(schemaDef.Name); A.CallTo(() => schema.SchemaDef).Returns(schemaDef); A.CallTo(() => schema.IsPublished).Returns(true); A.CallTo(() => schema.ScriptQuery).Returns("<script-query>"); var allSchemas = new List <ISchemaEntity> { schema }; A.CallTo(() => appProvider.GetSchemasAsync(appId)).Returns(allSchemas); sut = new CachingGraphQLService(cache, appProvider, assetRepository, commandBus, contentQuery, new FakeUrlGenerator()); }
public void Should_add_language() { var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Set(new LanguageConfig(Language.IT)); config_1.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE), new LanguageConfig(Language.IT) }); Assert.True(config_1.TryGetConfig(Language.IT, out var _)); Assert.True(config_1.Contains(Language.IT)); }
public void Should_create_initial_config_with_multiple_languages() { var config = LanguagesConfig.Build(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); Assert.Equal(3, config.Count); }
public void Should_remove_fallbacks_when_removing_language() { var config_0 = LanguagesConfig.Build( new LanguageConfig(Language.DE), new LanguageConfig(Language.IT, false, Language.RU, Language.IT), new LanguageConfig(Language.RU, false, Language.DE, Language.IT)); var config_1 = config_0.Remove(Language.IT); config_1.OfType <LanguageConfig>().ToList().ShouldBeEquivalentTo( new List <LanguageConfig> { new LanguageConfig(Language.DE), 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.Build( new LanguageConfig(Language.ES, false), new LanguageConfig(Language.IT, true)); schema = schema.AddString(1, "my-field", Partitioning.Language, new StringFieldProperties { IsRequired = true }); var data = new NamedContentData() .AddField("my-field", new ContentFieldData() .AddValue("es", "value")); await data.ValidateAsync(context, schema, optionalConfig.ToResolver(), errors); Assert.Empty(errors); }
public LanguagesConfig ToConfig() { var languagesConfig = new LanguageConfig[Languages?.Count ?? 0]; if (Languages != null) { var i = 0; foreach (var config in Languages) { languagesConfig[i++] = config.Value.ToConfig(config.Key); } } var result = LanguagesConfig.Build(languagesConfig); if (Master != null) { result.MakeMaster(Master); } return(result); }