Beispiel #1
0
        public void SitemapGeneratedWithSitemapItem(string hostname, string formatterString, string expected)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());

            if (!string.IsNullOrWhiteSpace(hostname))
                engine.Metadata[Keys.Hostname] = hostname;

            Pipeline contentPipeline = new Pipeline("Content", engine, null);
            var doc = new Document(engine, contentPipeline).Clone("Test", new[] { new KeyValuePair<string, object>(Keys.RelativeFilePath, "sub/testfile.html") });
            IDocument[] inputs = { doc };

            IExecutionContext context = new ExecutionContext(engine, contentPipeline);
            Core.Modules.Metadata.Meta m = new Core.Modules.Metadata.Meta(Keys.SitemapItem, (d, c) => new SitemapItem(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>"));
        }
Beispiel #2
0
            public void GroupByMetadataKey()
            {
                // Given
                List <int>  groupKey = new List <int>();
                Engine      engine   = new Engine();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };

                Core.Modules.Metadata.Meta meta = new Core.Modules.Metadata.Meta("GroupMetadata", (d, c) => new[] { d.Get <int>("A") % 3, 3 });
                GroupByMany groupByMany         = new GroupByMany("GroupMetadata", count, meta);
                Execute     gatherData          = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get <int>(Keys.GroupKey));
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 0, 1, 2, 3 }, groupKey);
            }
Beispiel #3
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>"));
            }
Beispiel #4
0
            public void GroupByMetadataKey()
            {
                // Given
                List<int> groupKey = new List<int>();
                Engine engine = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                Core.Modules.Metadata.Meta meta = new Core.Modules.Metadata.Meta("GroupMetadata", (d, c) => d.Get<int>("A") % 3);
                GroupBy groupBy = new GroupBy("GroupMetadata", count, meta);
                Execute gatherData = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get<int>(Keys.GroupKey));
                    return null;
                });
                engine.Pipelines.Add(groupBy, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, groupKey);
            }