本文整理汇总了C#中ExecutionContext.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ExecutionContext.GetDocument方法的具体用法?C# ExecutionContext.GetDocument怎么用?C# ExecutionContext.GetDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext.GetDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultCtorIgnoresDelimiterOnFirstLine
public void DefaultCtorIgnoresDelimiterOnFirstLine()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"---
FM1
FM2
---
Content1
Content2")
};
string frontMatterContent = null;
FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
{
frontMatterContent = x.Content;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.AreEqual(@"FM1
FM2
", frontMatterContent);
Assert.AreEqual(@"Content1
Content2", documents.First().Content);
}
示例2: DashStringDoesNotSplitAtNonmatchingDashes
public void DashStringDoesNotSplitAtNonmatchingDashes()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"FM1
FM2
---
Content1
Content2")
};
bool executed = false;
FrontMatter frontMatter = new FrontMatter("-", new Execute((x, ctx) =>
{
executed = true;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.IsFalse(executed);
Assert.AreEqual(@"FM1
FM2
---
Content1
Content2", documents.First().Content);
}
示例3: SetUp
public void SetUp()
{
Engine = new Engine();
Engine.FileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());
Engine.FileSystem.RootPath = "/";
Engine.FileSystem.InputPaths.Clear();
Engine.FileSystem.InputPaths.Add("/TestFiles/Input");
Pipeline = new Pipeline("Pipeline", null);
Context = new ExecutionContext(Engine, Pipeline);
Inputs = new [] { Context.GetDocument() };
}
示例4: ExecuteGetsCorrectContent
public void ExecuteGetsCorrectContent()
{
// Given
Engine engine = new Engine();
engine.RootFolder = TestContext.CurrentContext.TestDirectory;
engine.InputFolder = @"TestFiles\Input";
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument() };
ReadFiles readFiles = new ReadFiles(@"test-a.txt");
// When
IDocument document = readFiles.Execute(inputs, context).First();
// Then
Assert.AreEqual("aaa", document.Content);
}
示例5: FileNameIsConvertedCorrectly
public void FileNameIsConvertedCorrectly(string input, string output)
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument(new MetadataItems
{
new MetadataItem(Keys.SourceFileName, input)
}) };
FileName fileName = new FileName();
// When
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.AreEqual(output, documents.First().FilePath(Keys.WriteFileName).FullPath);
}
示例6: FileNameIsConvertedCorrectlyWithReservedChar
public void FileNameIsConvertedCorrectlyWithReservedChar(string character)
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
string manyCharactersWow = new String(character[0], 10);
IDocument[] inputs = { context.GetDocument(new MetadataItems
{
new MetadataItem(Keys.SourceFileName,
string.Format("testing {0} some of {0} these {0}", manyCharactersWow))
}) };
FileName fileName = new FileName();
// When
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.AreEqual("testing-some-of-these-", documents.First()[Keys.WriteFileName]);
}
示例7: FileNameShouldBeLowercase
public void FileNameShouldBeLowercase()
{
// Given
string input = "FileName With MiXeD CapS";
string output = "filename-with-mixed-caps";
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument(new MetadataItems
{
new MetadataItem(Keys.SourceFileName, new FilePath(input))
}) };
FileName fileName = new FileName();
// When
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.AreEqual(output, documents.First().FilePath(Keys.WriteFileName).FullPath);
}
示例8: WithAllowedCharactersDoesNotReplaceProvidedCharacters
public void WithAllowedCharactersDoesNotReplaceProvidedCharacters()
{
// Given
string input = "this-is-a-.net-tag";
string output = "this-is-a-.net-tag";
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument(new MetadataItems
{
new MetadataItem(Keys.SourceFileName, new FilePath(input))
}) };
FileName fileName = new FileName();
// When
fileName = fileName.WithAllowedCharacters(new string[] { "-" });
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.AreEqual(output, documents.First().FilePath(Keys.WriteFileName).FullPath);
}
示例9: TrimWhitespace
public void TrimWhitespace()
{
// Given
string input = " myfile.html ";
string output = "myfile.html";
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(new MetadataItems
{
new MetadataItem("MyKey", input)
})
};
FileName fileName = new FileName("MyKey");
// When
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.AreEqual(output, documents.First().FilePath(Keys.WriteFileName).FullPath);
}
示例10: IgnoresNullOrWhiteSpaceStrings
public void IgnoresNullOrWhiteSpaceStrings(string input)
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument(new MetadataItems
{
new MetadataItem(Keys.SourceFileName, input)
}) };
FileName fileName = new FileName();
// When
IEnumerable<IDocument> documents = fileName.Execute(inputs, context);
// Then
Assert.IsFalse(documents.First().ContainsKey(Keys.WriteFileName));
}
示例11: SearchPatternFindsCorrectFiles
public void SearchPatternFindsCorrectFiles(string searchPattern, SearchOption searchOption,
int expectedCount)
{
// Given
Engine engine = new Engine();
engine.RootFolder = TestContext.CurrentContext.TestDirectory;
engine.InputFolder = @"TestFiles\Input\";
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument() };
ReadFiles readFiles = new ReadFiles(searchPattern).WithSearchOption(searchOption);
// When
IEnumerable<IDocument> documents = readFiles.Execute(inputs, context);
int count = documents.Count();
// Then
Assert.AreEqual(expectedCount, count);
}
示例12: SingleCharWithSingleDelimiterSplitsAtCorrectLocation
public void SingleCharWithSingleDelimiterSplitsAtCorrectLocation()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"FM1
FM2
!
Content1
Content2")
};
string frontMatterContent = null;
FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
{
frontMatterContent = x.Content;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.AreEqual(@"FM1
FM2
", frontMatterContent);
Assert.AreEqual(@"Content1
Content2", documents.First().Content);
}
示例13: SingleCharWithRepeatedDelimiterWithLeadingSpacesDoesNotSplit
public void SingleCharWithRepeatedDelimiterWithLeadingSpacesDoesNotSplit()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"FM1
FM2
!!!!
Content1
Content2")
};
bool executed = false;
FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
{
executed = true;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.IsFalse(executed);
Assert.AreEqual(@"FM1
FM2
!!!!
Content1
Content2", documents.First().Content);
}
示例14: MultipleInputDocumentsResultsInMultipleOutputs
public void MultipleInputDocumentsResultsInMultipleOutputs()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"AA
-
XX"),
context.GetDocument(@"BB
-
YY")
};
string frontMatterContent = string.Empty;
FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
{
frontMatterContent += x.Content;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(2, documents.Count());
Assert.AreEqual(@"AA
BB
", frontMatterContent);
Assert.AreEqual(@"XX", documents.First().Content);
Assert.AreEqual(@"YY", documents.Skip(1).First().Content);
}
示例15: ReadFilesSetsMetadata
public void ReadFilesSetsMetadata(string key, string expectedEnding)
{
// Given
Engine engine = new Engine();
engine.RootFolder = TestContext.CurrentContext.TestDirectory;
engine.InputFolder = @"TestFiles\Input";
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { context.GetDocument() };
ReadFiles readFiles = new ReadFiles(@"test-c.txt");
// When
IDocument output = readFiles.Execute(inputs, context).First();
foreach (IDocument document in inputs)
{
((IDisposable) document).Dispose();
}
// Then
Assert.That(output.Metadata[key], Does.EndWith(expectedEnding));
((IDisposable) output).Dispose();
}