コード例 #1
0
            public void SitemapGeneratedWithSitemapItemAsString(string hostname, string formatterString, string expected)
            {
                // Given
                Engine engine = new Engine();

                if (!string.IsNullOrWhiteSpace(hostname))
                {
                    engine.Settings[Keys.Host] = hostname;
                }
                ExecutionPipeline contentPipeline = new ExecutionPipeline("Content", (IModuleList)null);
                IExecutionContext context         = new ExecutionContext(engine, Guid.Empty, contentPipeline);

                IDocument doc = context.GetDocument(context.GetContentStream("Test"), new[]
                {
                    new KeyValuePair <string, object>(Keys.RelativeFilePath, "sub/testfile.html")
                });

                IDocument[] inputs = { doc };

                Core.Modules.Metadata.Meta m = new Core.Modules.Metadata.Meta(
                    Keys.SitemapItem,
                    (d, c) => d[Keys.RelativeFilePath].ToString());
                var outputs = m.Execute(inputs, context);

                Func <string, string> formatter = null;

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

                // When
                Sitemap          sitemap = new Sitemap(formatter);
                List <IDocument> results = sitemap.Execute(outputs.ToList(), context).ToList();

                foreach (IDocument document in inputs.Concat(outputs.ToList()))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(1, results.Count);
                Assert.That(results[0].Content, Does.Contain($"<loc>{expected}</loc>"));
            }