コード例 #1
0
        public async Task Should_enrich_with_reference_fields()
        {
            var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            var content = CreateContent();

            await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider);

            Assert.NotNull(content.ReferenceFields);
        }
コード例 #2
0
        public async Task Should_not_enrich_with_reference_fields_when_not_frontend()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var source = CreateContent();

            await sut.EnrichAsync(ctx, Enumerable.Repeat(source, 1), schemaProvider);

            Assert.Null(source.ReferenceFields);
        }
コード例 #3
0
ファイル: ConvertDataTests.cs プロジェクト: vmnet04/squidex
        public async Task Should_convert_data_and_data_draft_when_frontend_user()
        {
            var content = CreateContent(new NamedContentData());

            var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider);

            Assert.NotNull(content.Data);
        }
コード例 #4
0
        public async Task Should_enrich_with_schema_names()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var content = CreateContent();

            await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default);

            Assert.Equal("my-schema", content.SchemaDisplayName);
        }
コード例 #5
0
        public AssetQueryServiceTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            var options = Options.Create(new AssetOptions {
                DefaultPageSize = 30
            });

            sut = new AssetQueryService(tagService, assetEnricher, assetRepository, options);
        }
コード例 #6
0
        public AssetQueryParserTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            var options = Options.Create(new AssetOptions {
                DefaultPageSize = 30
            });

            sut = new AssetQueryParser(TestUtils.DefaultSerializer, tagService, options);
        }
コード例 #7
0
        public async Task Should_not_compute_ui_tokens_for_frontend()
        {
            var source = CreateContent();

            await sut.EnrichAsync(new Context(Mocks.FrontendUser(), Mocks.App(appId)), new[] { source }, schemaProvider, default);

            Assert.Null(source.EditToken);

            A.CallTo(() => urlGenerator.Root())
            .MustNotHaveHappened();
        }
コード例 #8
0
        public ContentEnricherTests()
        {
            ct = cts.Token;

            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema = Mocks.Schema(appId, schemaId);

            A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, schemaId.Id, false, ct))
            .Returns(schema);
        }
コード例 #9
0
        public ContentEnricherTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema = Mocks.Schema(appId, schemaId);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(A <Context> .Ignored, schemaId.Id.ToString()))
            .Returns(schema);

            sut = new ContentEnricher(assetQuery, assetUrlGenerator, new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
コード例 #10
0
        public AssetQueryServiceTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            SetupEnricher();

            A.CallTo(() => queryParser.ParseAsync(requestContext, A <Q> ._))
            .ReturnsLazily(c => Task.FromResult(c.GetArgument <Q>(1) !));

            sut = new AssetQueryService(assetEnricher, assetRepository, assetLoader, assetFolderRepository, queryParser);
        }
コード例 #11
0
        public AssetEnricherTests()
        {
            var assetMetadataSources = new[]
            {
                assetMetadataSource1,
                assetMetadataSource2
            };

            requestContext = Context.Anonymous(Mocks.App(appId));

            sut = new AssetEnricher(tagService, assetMetadataSources, requestCache, urlGenerator, jsonSerializer);
        }
コード例 #12
0
        public EnrichWithWorkflowsTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema         = Mocks.Schema(appId, schemaId);
            schemaProvider = x => Task.FromResult(schema);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(A <Context> .Ignored, schemaId.Id.ToString()))
            .Returns(schema);

            sut = new EnrichWithWorkflows(contentWorkflow);
        }
コード例 #13
0
        private Context ContextWithPermission(string?permission = null)
        {
            var claimsIdentity  = new ClaimsIdentity();
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            if (permission != null)
            {
                claimsIdentity.AddClaim(new Claim(SquidexClaimTypes.Permissions, permission));
            }

            return(new Context(claimsPrincipal, Mocks.App(appId)));
        }
コード例 #14
0
ファイル: BackupServiceTests.cs プロジェクト: jrlost/squidex
        public async Task Should_call_grain_to_clear_backups()
        {
            var grain = A.Fake <IBackupGrain>();

            A.CallTo(() => grainFactory.GetGrain <IBackupGrain>(appId.ToString(), null))
            .Returns(grain);

            await((IDeleter)sut).DeleteAppAsync(Mocks.App(NamedId.Of(appId, "my-app")), default);

            A.CallTo(() => grain.ClearAsync())
            .MustHaveHappened();
        }
コード例 #15
0
        public ReferenceFluidExtensionTests()
        {
            var extensions = new IFluidExtension[]
            {
                new ReferencesFluidExtension(contentQuery, appProvider)
            };

            A.CallTo(() => appProvider.GetAppAsync(appId.Id, false))
            .Returns(Mocks.App(appId));

            sut = new FluidTemplateEngine(extensions);
        }
コード例 #16
0
        public ResolveReferencesTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var refSchemaDef =
                new Schema("my-ref")
                .AddString(1, "name", Partitioning.Invariant,
                           new StringFieldProperties())
                .AddNumber(2, "number", Partitioning.Invariant,
                           new NumberFieldProperties())
                .SetFieldsInReferences("name", "number");

            var schemaDef =
                new Schema(schemaId.Name)
                .AddReferences(1, "ref1", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId1.Id
            })
                .AddReferences(2, "ref2", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId2.Id
            })
                .SetFieldsInLists("ref1", "ref2");

            schemaProvider = x =>
            {
                if (x == schemaId.Id)
                {
                    return(Task.FromResult(Mocks.Schema(appId, schemaId, schemaDef)));
                }
                else if (x == refSchemaId1.Id)
                {
                    return(Task.FromResult(Mocks.Schema(appId, refSchemaId1, refSchemaDef)));
                }
                else if (x == refSchemaId2.Id)
                {
                    return(Task.FromResult(Mocks.Schema(appId, refSchemaId2, refSchemaDef)));
                }
                else
                {
                    throw new DomainObjectNotFoundException(x.ToString());
                }
            };

            sut = new ResolveReferences(new Lazy <IContentQueryService>(() => contentQuery), requestCache);
        }
コード例 #17
0
        public async Task Should_not_call_script_engine_when_no_script_configured()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var content = new ContentEntity {
                SchemaId = schemaId
            };

            await sut.EnrichAsync(ctx, new[] { content }, schemaProvider);

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, A <string> ._, ScriptOptions()))
            .MustNotHaveHappened();
        }
コード例 #18
0
        public async Task Should_not_call_script_engine_for_frontend_user()
        {
            var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId));

            var content = new ContentEntity {
                SchemaId = schemaWithScriptId
            };

            await sut.EnrichAsync(ctx, new[] { content }, schemaProvider);

            A.CallTo(() => scriptEngine.ExecuteAndTransformAsync(A <ScriptVars> ._, A <string> ._))
            .MustNotHaveHappened();
        }
コード例 #19
0
        public async Task Should_track_if_calls_left()
        {
            httpContext.Features.Set <IAppFeature>(new AppFeature(Mocks.App(appId)));
            httpContext.Features.Set <IApiCostsFeature>(new ApiCostsAttribute(13));

            await sut.InvokeAsync(httpContext, next);

            Assert.True(isNextCalled);

            var date = instant.ToDateTimeUtc().Date;

            A.CallTo(() => usageTracker.TrackAsync(date, A <string> ._, A <string> ._, 13, A <long> ._, A <long> ._))
            .MustHaveHappened();
        }
コード例 #20
0
ファイル: CounterDeleterTests.cs プロジェクト: jrlost/squidex
        public async Task Should_remove_events_from_streams()
        {
            var app = Mocks.App(NamedId.Of(DomainId.NewGuid(), "my-app"));

            var grain = A.Fake <ICounterGrain>();

            A.CallTo(() => grainFactory.GetGrain <ICounterGrain>(app.Id.ToString(), null))
            .Returns(grain);

            await sut.DeleteAppAsync(app, default);

            A.CallTo(() => grain.ClearAsync())
            .MustHaveHappened();
        }
コード例 #21
0
        private Context ContextWithPermissions(params NamedId <DomainId>[] allowedSchemas)
        {
            var claimsIdentity  = new ClaimsIdentity();
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            foreach (var schemaId in allowedSchemas)
            {
                var permission = Permissions.ForApp(Permissions.AppContentsReadOwn, appId.Name, schemaId.Name).Id;

                claimsIdentity.AddClaim(new Claim(SquidexClaimTypes.Permissions, permission));
            }

            return(new Context(claimsPrincipal, Mocks.App(appId)));
        }
コード例 #22
0
        private Context ContextWithPermission(string?permission = null)
        {
            var claimsIdentity  = new ClaimsIdentity();
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            if (permission == null)
            {
                permission = Permissions.ForApp(Permissions.AppCommon, appId.Name).Id;
            }

            claimsIdentity.AddClaim(new Claim(SquidexClaimTypes.Permissions, permission));

            return(new Context(claimsPrincipal, Mocks.App(appId)));
        }
コード例 #23
0
        public ContentDomainObjectTests()
        {
            app = Mocks.App(AppNamedId, Language.DE);

            var scripts = new SchemaScripts
            {
                Change = "<change-script>",
                Create = "<create-script>",
                Delete = "<delete-script>",
                Update = "<update-script>"
            };

            var schemaDef =
                new Schema("my-schema")
                .AddNumber(1, "my-field1", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = true
            })
                .AddNumber(2, "my-field2", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = false
            })
                .SetScripts(scripts);

            schema = Mocks.Schema(AppNamedId, SchemaNamedId, schemaDef);

            A.CallTo(() => appProvider.GetAppAsync(AppName, false))
            .Returns(app);

            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId, false))
            .Returns((app, schema));

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, A <string> ._, ScriptOptions()))
            .ReturnsLazily(x => Task.FromResult(x.GetArgument <ScriptVars>(0) !.Data !));

            patched = patch.MergeInto(data);

            var validators = Enumerable.Repeat(new DefaultValidatorsFactory(), 1);

            var context = new ContentOperationContext(
                appProvider,
                validators,
                contentWorkflow,
                contentRepository,
                TestUtils.DefaultSerializer,
                scriptEngine, A.Fake <ISemanticLog>());

            sut = new ContentDomainObject(Store, A.Dummy <ISemanticLog>(), context);
            sut.Setup(Id);
        }
コード例 #24
0
        public GraphQLTestBase()
        {
            app = Mocks.App(appId, Language.DE, Language.GermanGermany);

            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.Id
            })
                .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();

            schema = Mocks.Schema(appId, schemaId, schemaDef);

            requestContext = new Context(Mocks.FrontendUser(), app);

            sut = CreateSut();
        }
コード例 #25
0
        public async Task Should_not_enrich_content_with_can_update_if_disabled_in_context()
        {
            var content = new ContentEntity {
                SchemaId = schemaId
            };

            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId)).Clone(b => b.WithResolveFlow(false));

            await sut.EnrichAsync(ctx, new[] { content }, null !);

            Assert.False(content.CanUpdate);

            A.CallTo(() => workflow.CanUpdateAsync(content, A <Status> ._, requestContext.User))
            .MustNotHaveHappened();
        }
コード例 #26
0
        public ContentEnricherReferencesTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var refSchemaDef =
                new Schema("my-ref")
                .AddString(1, "name", Partitioning.Invariant,
                           new StringFieldProperties {
                IsReferenceField = true
            })
                .AddNumber(2, "number", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsReferenceField = true
            });

            var schemaDef =
                new Schema(schemaId.Name)
                .AddReferences(1, "ref1", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId1.Id
            })
                .AddReferences(2, "ref2", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId2.Id
            });

            void SetupSchema(NamedId <Guid> id, Schema def)
            {
                var schemaEntity = Mocks.Schema(appId, id, def);

                A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, id.Id.ToString()))
                .Returns(schemaEntity);
            }

            SetupSchema(schemaId, schemaDef);
            SetupSchema(refSchemaId1, refSchemaDef);
            SetupSchema(refSchemaId2, refSchemaDef);

            sut = new ContentEnricher(new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
コード例 #27
0
        public async Task Should_not_enrich_references_if_disabled()
        {
            var contents = new[]
            {
                CreateContent(new[] { DomainId.NewGuid() }, Array.Empty <DomainId>())
            };

            var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)).WithoutContentEnrichment(true);

            await sut.EnrichAsync(ctx, contents, schemaProvider);

            Assert.Null(contents[0].ReferenceData);

            A.CallTo(() => assetQuery.QueryAsync(A <Context> ._, null, A <Q> ._))
            .MustNotHaveHappened();
        }
コード例 #28
0
        private Context SetupContext(string id)
        {
            var permission = Permissions.ForApp(id, appId.Name).Id;

            var claimsIdentity  = new ClaimsIdentity();
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            claimsIdentity.AddClaim(new Claim(SquidexClaimTypes.Permissions, permission));

            var requestContext = new Context(claimsPrincipal, Mocks.App(appId));

            A.CallTo(() => contextProvider.Context)
            .Returns(requestContext);

            return(requestContext);
        }
コード例 #29
0
        public async Task Should_call_deleters_when_contributor_removed()
        {
            var app = Mocks.App(NamedId.Of(DomainId.NewGuid(), "my-app"));

            await sut.On(Envelope.Create(new AppContributorRemoved
            {
                AppId         = app.NamedId(),
                ContributorId = "user1"
            }));

            A.CallTo(() => deleter1.DeleteContributorAsync(app.Id, "user1", default))
            .MustHaveHappened();

            A.CallTo(() => deleter2.DeleteContributorAsync(app.Id, "user1", default))
            .MustHaveHappened();
        }
コード例 #30
0
        public async Task Should_not_enrich_references_if_not_api_user()
        {
            var contents = new[]
            {
                CreateContent(new[] { DomainId.NewGuid() }, Array.Empty <DomainId>())
            };

            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            await sut.EnrichAsync(ctx, contents, schemaProvider, default);

            Assert.Null(contents[0].ReferenceData);

            A.CallTo(() => contentQuery.QueryAsync(A <Context> ._, A <Q> ._, A <CancellationToken> ._))
            .MustNotHaveHappened();
        }