示例#1
0
        public async Task ShouldCreateNewPublishedContentItem()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemId)]                 = "newcontentitemid";
                    jItem[nameof(ContentItem.ContentItemVersionId)]          = "newversion";
                    jItem[nameof(ContentItem.DisplayText)]                   = "new version";
                    jItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "blog/another";
                });

                await context.PostRecipeAsync(recipe);

                // Test
                var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName);

                await shellScope.UsingAsync(async scope =>
                {
                    var session        = scope.ServiceProvider.GetRequiredService <ISession>();
                    var blogPostsCount = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                             x.ContentType == "BlogPost").CountAsync();

                    Assert.Equal(2, blogPostsCount);
                });
            }
        }
示例#2
0
        public async Task ShouldProduceSameOutcomeForExistingContentItemVersionOnMultipleExecutions()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.DisplayText)] = "existing version mutated";
                });

                for (var i = 0; i < 2; i++)
                {
                    await context.PostRecipeAsync(recipe);

                    // Test
                    using (var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName))
                    {
                        await shellScope.UsingAsync(async scope =>
                        {
                            var session   = scope.ServiceProvider.GetRequiredService <ISession>();
                            var blogPosts = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                                x.ContentType == "BlogPost").ListAsync();

                            Assert.Single(blogPosts);
                            var mutatedVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == context.OriginalBlogPostVersionId);
                            Assert.Equal("existing version mutated", mutatedVersion?.DisplayText);
                        });
                    }
                }
            }
        }
示例#3
0
        public async Task ShouldDiscardDraftThenCreateNewDraftContentItemVersion()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                var content = await context.Client.PostAsJsonAsync("api/content?draft=true", context.OriginalBlogPost);

                var draftContentItemVersionId = (await content.Content.ReadAsAsync <ContentItem>()).ContentItemVersionId;

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemVersionId)] = "newdraftversion";
                    jItem[nameof(ContentItem.DisplayText)]          = "new draft version";
                    jItem[nameof(ContentItem.Published)]            = false;
                });

                await context.PostRecipeAsync(recipe);

                // Test
                using (var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName))
                {
                    await shellScope.UsingAsync(async scope =>
                    {
                        var session   = scope.ServiceProvider.GetRequiredService <ISession>();
                        var blogPosts = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                            x.ContentType == "BlogPost").ListAsync();

                        Assert.Equal(3, blogPosts.Count());

                        var originalVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == context.OriginalBlogPostVersionId);
                        Assert.False(originalVersion?.Latest);
                        Assert.True(originalVersion?.Published);

                        var draftVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == draftContentItemVersionId);
                        Assert.False(draftVersion?.Latest);
                        Assert.False(draftVersion?.Published);

                        var newDraftVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == "newdraftversion");
                        Assert.Equal("new draft version", newDraftVersion?.DisplayText);
                        Assert.True(newDraftVersion?.Latest);
                        Assert.False(newDraftVersion?.Published);
                    });
                }
            }
        }
示例#4
0
        public async Task ShouldIgnoreDuplicateContentItems()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Create a recipe with two content items and the same version id.
                var firstRecipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemId)]                 = "newcontentitemid";
                    jItem[nameof(ContentItem.ContentItemVersionId)]          = "dupversion";
                    jItem[nameof(ContentItem.DisplayText)]                   = "duplicate version";
                    jItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "blog/another";
                });

                var secondRecipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemId)]                 = "newcontentitemid";
                    jItem[nameof(ContentItem.ContentItemVersionId)]          = "dupversion";
                    jItem[nameof(ContentItem.DisplayText)]                   = "duplicate version";
                    jItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "blog/another";
                });

                var firstRecipeData = firstRecipe.SelectToken("steps[0].Data") as JArray;

                var secondContentItem = secondRecipe.SelectToken("steps[0].Data[0]");

                firstRecipeData.Add(secondContentItem);

                await context.PostRecipeAsync(firstRecipe);

                // Test
                var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName);

                await shellScope.UsingAsync(async scope =>
                {
                    var session        = scope.ServiceProvider.GetRequiredService <ISession>();
                    var blogPostsCount = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                             x.ContentType == "BlogPost" && x.ContentItemVersionId == "dupversion").CountAsync();

                    Assert.Equal(1, blogPostsCount);
                });
            }
        }
        public async Task ShouldFailWhenAutoroutePathIsNotUnique()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemId)]                 = "newcontentitemid";
                    jItem[nameof(ContentItem.ContentItemVersionId)]          = "newversion";
                    jItem[nameof(ContentItem.DisplayText)]                   = "new version";
                    jItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "blog/another";
                });

                var data = recipe["steps"][0]["Data"] as JArray;
                var secondContentItem = JObject.FromObject(context.OriginalBlogPost);
                secondContentItem[nameof(ContentItem.ContentItemId)]        = "secondcontentitemid";
                secondContentItem[nameof(ContentItem.ContentItemVersionId)] = "secondcontentitemversionid";
                secondContentItem[nameof(ContentItem.DisplayText)]          = "second content item display text";
                // To be explicit in this test set path to a known value.
                secondContentItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "blog/post-1";
                data.Add(secondContentItem);

                // Test
                await Assert.ThrowsAnyAsync <Exception>(async() =>
                {
                    var response = await context.PostRecipeAsync(recipe, false);
                    response.EnsureSuccessStatusCode();
                });

                // Confirm creation of both content items was cancelled.
                var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName);

                await shellScope.UsingAsync(async scope =>
                {
                    var session   = scope.ServiceProvider.GetRequiredService <ISession>();
                    var blogPosts = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                        x.ContentType == "BlogPost").ListAsync();

                    Assert.Single(blogPosts);
                });
            }
        }
        public async Task ShouldUpdateLuceneIndexesOnImport()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemVersionId)] = "newVersion";
                    jItem[nameof(ContentItem.DisplayText)]          = "new version";
                });

                // Create a second content item in the recipe data so we can confirm the behaviour
                // of the LuceneIndexingContentHandler.
                var data = recipe["steps"][0]["Data"] as JArray;
                var secondContentItem = JObject.FromObject(context.OriginalBlogPost);
                secondContentItem[nameof(ContentItem.ContentItemId)]                 = "secondcontentitemid";
                secondContentItem[nameof(ContentItem.ContentItemVersionId)]          = "secondcontentitemversionid";
                secondContentItem[nameof(ContentItem.DisplayText)]                   = "second content item display text";
                secondContentItem[nameof(AutoroutePart)][nameof(AutoroutePart.Path)] = "new-path";
                data.Add(secondContentItem);

                await context.PostRecipeAsync(recipe);

                // Test
                var result = await context
                             .GraphQLClient
                             .Content
                             .Query("RecentBlogPosts", builder =>
                {
                    builder
                    .WithField("displayText");
                });

                var nodes = result["data"]["recentBlogPosts"];

                Assert.Equal(2, nodes.Count());
                Assert.Equal("new version", nodes[0]["displayText"].ToString());
                Assert.Equal("second content item display text", nodes[1]["displayText"].ToString());
            }
        }
示例#7
0
        public async Task ShouldProduceSameOutcomeForNewContentOnMultipleExecutions()
        {
            using (var context = new BlogPostDeploymentContext())
            {
                // Setup
                await context.InitializeAsync();

                // Act
                var recipe = context.GetContentStepRecipe(context.OriginalBlogPost, jItem =>
                {
                    jItem[nameof(ContentItem.ContentItemVersionId)] = "newversion";
                    jItem[nameof(ContentItem.DisplayText)]          = "new version";
                });

                for (var i = 0; i < 2; i++)
                {
                    await context.PostRecipeAsync(recipe);

                    // Test
                    var shellScope = await BlogPostDeploymentContext.ShellHost.GetScopeAsync(context.TenantName);

                    await shellScope.UsingAsync(async scope =>
                    {
                        var session   = scope.ServiceProvider.GetRequiredService <ISession>();
                        var blogPosts = await session.Query <ContentItem, ContentItemIndex>(x =>
                                                                                            x.ContentType == "BlogPost").ListAsync();

                        Assert.Equal(2, blogPosts.Count());

                        var originalVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == context.OriginalBlogPostVersionId);
                        Assert.False(originalVersion?.Latest);
                        Assert.False(originalVersion?.Published);

                        var newVersion = blogPosts.FirstOrDefault(x => x.ContentItemVersionId == "newversion");
                        Assert.Equal("new version", newVersion?.DisplayText);
                        Assert.True(newVersion?.Latest);
                        Assert.True(newVersion?.Published);
                    });
                }
            }
        }