Exemplo n.º 1
0
            public async Task SitemapGeneratedWithSitemapItemAsString(string hostname, string formatterString, string expected)
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Settings[Keys.LinkHideExtensions] = "true";
                if (!string.IsNullOrWhiteSpace(hostname))
                {
                    context.Settings[Keys.Host] = hostname;
                }

                TestDocument doc = new TestDocument(new FilePath("sub/testfile.html"), "Test");

                IDocument[] inputs = { doc };

                AddMetadata m = new AddMetadata(
                    Keys.SitemapItem,
                    Config.FromDocument(d => d.Destination.FullPath));

                Func <string, string> formatter = null;

                if (!string.IsNullOrWhiteSpace(formatterString))
                {
                    formatter = f => string.Format(formatterString, f);
                }

                GenerateSitemap sitemap = new GenerateSitemap(formatter);

                // When
                TestDocument result = await ExecuteAsync(doc, context, m, sitemap).SingleAsync();

                // Then
                result.Content.ShouldContain($"<loc>{expected}</loc>");
            }
            public async Task IgnoresNull()
            {
                // Given
                TestDocument input       = new TestDocument();
                AddMetadata  addMetadata = new AddMetadata("Foo", (string)null).IgnoreNull();

                // When
                IReadOnlyList <TestDocument> results = await ExecuteAsync(input, addMetadata);

                // Then
                results.Single().Keys.ShouldNotContain("Foo");
            }
            public async Task AddsNull()
            {
                // Given
                TestDocument input       = new TestDocument();
                AddMetadata  addMetadata = new AddMetadata("Foo", (string)null);

                // When
                IReadOnlyList <TestDocument> results = await ExecuteAsync(input, addMetadata);

                // Then
                results.Single()["Foo"].ShouldBe((string)null);
            }
            public async Task OnlyIfNonExisting()
            {
                // Given
                TestDocument input = new TestDocument
                {
                    { "Foo", "Baz" }
                };
                AddMetadata addMetadata = new AddMetadata("Foo", "Bar").OnlyIfNonExisting();

                // When
                IReadOnlyList <TestDocument> results = await ExecuteAsync(input, addMetadata);

                // Then
                results.Single()["Foo"].ShouldBe("Baz");
            }
Exemplo n.º 5
0
            public async Task GroupByMetadataKey()
            {
                // Given
                List <int>  groupKey = new List <int>();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs   = 7,
                    EnsureInputDocument = true
                };
                AddMetadata     meta        = new AddMetadata("GroupMetadata", Config.FromDocument(d => new object[] { d.GetInt("A") % 3, 3 }));
                GroupDocuments  groupByMany = new GroupDocuments("GroupMetadata");
                ForEachDocument gatherData  = new ExecuteConfig(
                    Config.FromDocument(d =>
                {
                    groupKey.Add(d.GetInt(Keys.GroupKey));
                    return((object)null);
                })).ForEachDocument();

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(count, meta, groupByMany, gatherData);

                // Then
                CollectionAssert.AreEquivalent(new[] { 0, 1, 2, 3 }, groupKey);
            }
Exemplo n.º 6
0
        public void InsertMetadataElementBeforeSiblings(AddMetadata addMetadata, int position, string expectedItem)
        {
            Action<ProjectItemElement, ProjectMetadataElement, ProjectMetadataElement> act = (i, c, r) => { i.InsertBeforeChild(c, r);};

            AssertMetadataConstruction(addMetadata, position, expectedItem, act);
        }
Exemplo n.º 7
0
        private static void AssertMetadataConstruction(AddMetadata addMetadata, int position, string expectedItem, Action<ProjectItemElement, ProjectMetadataElement, ProjectMetadataElement> actOnTestData)
        {
            var project = ProjectRootElement.Create();
            var itemGroup = project.AddItemGroup();
            var item = itemGroup.AddItem("i", "a");

            addMetadata(item);

            var referenceSibling = item.Metadata.ElementAt(position);
            var m = project.CreateMetadataElement("m", "v");

            actOnTestData(item, m, referenceSibling);

            var expected = ComposeExpectedProjectString(expectedItem);

            Helpers.VerifyAssertProjectContent(expected, project);
        }
Exemplo n.º 8
0
        public void InsertMetadataAttributeAfterSiblings(AddMetadata addMetadata, int position, string expectedItem)
        {
            Action<ProjectItemElement, ProjectMetadataElement, ProjectMetadataElement> act = (i, c, r) =>
            {
                c.ExpressedAsAttribute = true;
                i.InsertAfterChild(c, r);
            };

            AssertMetadataConstruction(addMetadata, position, expectedItem, act);
        }