本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext类的典型用法代码示例。如果您正苦于以下问题:C# TagHelperExecutionContext类的具体用法?C# TagHelperExecutionContext怎么用?C# TagHelperExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagHelperExecutionContext类属于Microsoft.AspNet.Razor.Runtime.TagHelpers命名空间,在下文中一共展示了TagHelperExecutionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RunAsync_CallsInitPriorToProcessAsync
public async Task RunAsync_CallsInitPriorToProcessAsync()
{
// Arrange
var runner = new TagHelperRunner();
var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
var incrementer = 0;
var callbackTagHelper = new CallbackTagHelper(
initCallback: () =>
{
Assert.Equal(0, incrementer);
incrementer++;
},
processAsyncCallback: () =>
{
Assert.Equal(1, incrementer);
incrementer++;
});
executionContext.Add(callbackTagHelper);
// Act
await runner.RunAsync(executionContext);
// Assert
Assert.Equal(2, incrementer);
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:27,代码来源:TagHelperRunnerTest.cs
示例2: RunAsync
/// <summary>
/// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s.
/// </summary>
/// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s.
/// </param>
/// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the
/// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns>
public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext)
{
if (executionContext == null)
{
throw new ArgumentNullException(nameof(executionContext));
}
var tagHelperContext = new TagHelperContext(
executionContext.AllAttributes,
executionContext.Items,
executionContext.UniqueId,
executionContext.GetChildContentAsync);
var tagHelperOutput = new TagHelperOutput(
executionContext.TagName,
executionContext.HTMLAttributes)
{
TagMode = executionContext.TagMode,
};
var orderedTagHelpers = executionContext.TagHelpers.OrderBy(tagHelper => tagHelper.Order);
foreach (var tagHelper in orderedTagHelpers)
{
await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);
}
return tagHelperOutput;
}
开发者ID:rahulchrty,项目名称:Razor,代码行数:34,代码来源:TagHelperRunner.cs
示例3: Begin
/// <summary>
/// Starts a <see cref="TagHelperExecutionContext"/> scope.
/// </summary>
/// <param name="tagName">The HTML tag name that the scope is associated with.</param>
/// <param name="selfClosing">
/// <see cref="bool"/> indicating whether or not the tag of this scope is self-closing.
/// </param>
/// <param name="uniqueId">An identifier unique to the HTML element this scope is for.</param>
/// <param name="executeChildContentAsync">A delegate used to execute the child content asynchronously.</param>
/// <param name="startTagHelperWritingScope">A delegate used to start a writing scope in a Razor page.</param>
/// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param>
/// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns>
public TagHelperExecutionContext Begin(
[NotNull] string tagName,
bool selfClosing,
[NotNull] string uniqueId,
[NotNull] Func<Task> executeChildContentAsync,
[NotNull] Action startTagHelperWritingScope,
[NotNull] Func<TagHelperContent> endTagHelperWritingScope)
{
IDictionary<object, object> items;
// If we're not wrapped by another TagHelper, then there will not be a parentExecutionContext.
if (_executionScopes.Count > 0)
{
items = new CopyOnWriteDictionary<object, object>(
_executionScopes.Peek().Items,
comparer: EqualityComparer<object>.Default);
}
else
{
items = new Dictionary<object, object>();
}
var executionContext = new TagHelperExecutionContext(
tagName,
selfClosing,
items,
uniqueId,
executeChildContentAsync,
startTagHelperWritingScope,
endTagHelperWritingScope);
_executionScopes.Push(executionContext);
return executionContext;
}
开发者ID:rohitpoudel,项目名称:Razor,代码行数:47,代码来源:TagHelperScopeManager.cs
示例4: GetChildContentAsync_CachesValue
public async Task GetChildContentAsync_CachesValue()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var expectedContent = string.Empty;
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: null,
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
if (string.IsNullOrEmpty(expectedContent))
{
expectedContent = "Hello from child content: " + Guid.NewGuid().ToString();
}
defaultTagHelperContent.SetContent(expectedContent);
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync();
var content2 = await executionContext.GetChildContentAsync();
// Assert
Assert.Equal(expectedContent, content1.GetContent());
Assert.Equal(expectedContent, content2.GetContent());
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:32,代码来源:TagHelperExecutionContextTest.cs
示例5: RunAsync
/// <summary>
/// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s.
/// </summary>
/// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s.
/// </param>
/// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the
/// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns>
public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext)
{
if (executionContext == null)
{
throw new ArgumentNullException(nameof(executionContext));
}
var tagHelperContext = new TagHelperContext(
executionContext.AllAttributes,
executionContext.Items,
executionContext.UniqueId);
OrderTagHelpers(executionContext.TagHelpers);
for (var i = 0; i < executionContext.TagHelpers.Count; i++)
{
executionContext.TagHelpers[i].Init(tagHelperContext);
}
var tagHelperOutput = new TagHelperOutput(
executionContext.TagName,
executionContext.HTMLAttributes,
executionContext.GetChildContentAsync)
{
TagMode = executionContext.TagMode,
};
for (var i = 0; i < executionContext.TagHelpers.Count; i++)
{
await executionContext.TagHelpers[i].ProcessAsync(tagHelperContext, tagHelperOutput);
}
return tagHelperOutput;
}
开发者ID:leloulight,项目名称:Razor,代码行数:41,代码来源:TagHelperRunner.cs
示例6: GetChildContentAsync_CachesValue
public async Task GetChildContentAsync_CachesValue()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var content = string.Empty;
var expectedContent = string.Empty;
var executionContext = new TagHelperExecutionContext(
"p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
if (string.IsNullOrEmpty(expectedContent))
{
content = "Hello from child content: " + Guid.NewGuid().ToString();
expectedContent = $"HtmlEncode[[{content}]]";
}
defaultTagHelperContent.SetContent(content);
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync(useCachedResult: true);
var content2 = await executionContext.GetChildContentAsync(useCachedResult: true);
// Assert
Assert.Equal(expectedContent, content1.GetContent(new HtmlTestEncoder()));
Assert.Equal(expectedContent, content2.GetContent(new HtmlTestEncoder()));
}
开发者ID:leloulight,项目名称:Razor,代码行数:34,代码来源:TagHelperExecutionContextTest.cs
示例7: SelfClosing_ReturnsTrueOrFalseAsExpected
public void SelfClosing_ReturnsTrueOrFalseAsExpected(bool selfClosing)
{
// Arrange & Act
var executionContext = new TagHelperExecutionContext("p", selfClosing);
// Assert
Assert.Equal(selfClosing, executionContext.SelfClosing);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:8,代码来源:TagHelperExecutionContextTest.cs
示例8: TagMode_ReturnsExpectedValue
public void TagMode_ReturnsExpectedValue(TagMode tagMode)
{
// Arrange & Act
var executionContext = new TagHelperExecutionContext("p", tagMode);
// Assert
Assert.Equal(tagMode, executionContext.TagMode);
}
开发者ID:leloulight,项目名称:Razor,代码行数:8,代码来源:TagHelperExecutionContextTest.cs
示例9: ParentItems_SetsItemsProperty
public void ParentItems_SetsItemsProperty()
{
// Arrange
var expectedItems = new Dictionary<object, object>
{
{ "test-entry", 1234 }
};
// Act
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: expectedItems,
uniqueId: string.Empty,
executeChildContentAsync: async () => await Task.FromResult(result: true),
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => new DefaultTagHelperContent());
// Assert
Assert.NotNull(executionContext.Items);
Assert.Same(expectedItems, executionContext.Items);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:22,代码来源:TagHelperExecutionContextTest.cs
示例10: RunAsync_OrdersTagHelpers
public async Task RunAsync_OrdersTagHelpers(
int[] tagHelperOrders,
int[] expectedTagHelperOrders)
{
// Arrange
var runner = new TagHelperRunner();
var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
var processOrder = new List<int>();
foreach (var order in tagHelperOrders)
{
var orderedTagHelper = new OrderedTagHelper(order)
{
ProcessOrderTracker = processOrder
};
executionContext.Add(orderedTagHelper);
}
// Act
await runner.RunAsync(executionContext);
// Assert
Assert.Equal(expectedTagHelperOrders, processOrder);
}
开发者ID:rahulchrty,项目名称:Razor,代码行数:24,代码来源:TagHelperRunnerTest.cs
示例11: Add_MaintainsMultipleTagHelpers
public void Add_MaintainsMultipleTagHelpers()
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", selfClosing: false);
var tagHelper1 = new PTagHelper();
var tagHelper2 = new PTagHelper();
// Act
executionContext.Add(tagHelper1);
executionContext.Add(tagHelper2);
// Assert
var tagHelpers = executionContext.TagHelpers.ToArray();
Assert.Equal(2, tagHelpers.Length);
Assert.Same(tagHelper1, tagHelpers[0]);
Assert.Same(tagHelper2, tagHelpers[1]);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:18,代码来源:TagHelperExecutionContextTest.cs
示例12: Add_MaintainsTagHelpers
public void Add_MaintainsTagHelpers()
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", selfClosing: false);
var tagHelper = new PTagHelper();
// Act
executionContext.Add(tagHelper);
// Assert
var singleTagHelper = Assert.Single(executionContext.TagHelpers);
Assert.Same(tagHelper, singleTagHelper);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:13,代码来源:TagHelperExecutionContextTest.cs
示例13: TagHelperExecutionContext_MaintainsAllAttributes
public void TagHelperExecutionContext_MaintainsAllAttributes()
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", selfClosing: false);
var expectedAttributes = new Dictionary<string, object>
{
{ "class", "btn" },
{ "something", true },
{ "foo", "bar" }
};
// Act
executionContext.AddHtmlAttribute("class", "btn");
executionContext.AddTagHelperAttribute("something", true);
executionContext.AddHtmlAttribute("foo", "bar");
// Assert
Assert.Equal(expectedAttributes, executionContext.AllAttributes);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:19,代码来源:TagHelperExecutionContextTest.cs
示例14: AddMinimizedHtmlAttribute_MaintainsHTMLAttributes_SomeMinimized
public void AddMinimizedHtmlAttribute_MaintainsHTMLAttributes_SomeMinimized()
{
// Arrange
var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.SelfClosing);
var expectedAttributes = new TagHelperAttributeList
{
{ "class", "btn" },
{ "foo", "bar" }
};
expectedAttributes.Add(new TagHelperAttribute { Name = "checked", Minimized = true });
expectedAttributes.Add(new TagHelperAttribute { Name = "visible", Minimized = true });
// Act
executionContext.AddHtmlAttribute("class", "btn");
executionContext.AddHtmlAttribute("foo", "bar");
executionContext.AddMinimizedHtmlAttribute("checked");
executionContext.AddMinimizedHtmlAttribute("visible");
// Assert
Assert.Equal(
expectedAttributes,
executionContext.HTMLAttributes,
CaseSensitiveTagHelperAttributeComparer.Default);
}
开发者ID:leloulight,项目名称:Razor,代码行数:24,代码来源:TagHelperExecutionContextTest.cs
示例15: ExecuteChildContentAsync_IsNotMemoized
public async Task ExecuteChildContentAsync_IsNotMemoized()
{
// Arrange
var childContentExecutionCount = 0;
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: null,
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
childContentExecutionCount++;
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => new DefaultTagHelperContent());
// Act
await executionContext.ExecuteChildContentAsync();
await executionContext.ExecuteChildContentAsync();
await executionContext.ExecuteChildContentAsync();
// Assert
Assert.Equal(3, childContentExecutionCount);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:26,代码来源:TagHelperExecutionContextTest.cs
示例16: GetChildContentAsync_CanExecuteChildrenMoreThanOnce
public async Task GetChildContentAsync_CanExecuteChildrenMoreThanOnce()
{
// Arrange
var executionCount = 0;
var executionContext = new TagHelperExecutionContext(
"p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
executionCount++;
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => new DefaultTagHelperContent());
// Act
await executionContext.GetChildContentAsync(useCachedResult: false);
await executionContext.GetChildContentAsync(useCachedResult: false);
// Assert
Assert.Equal(2, executionCount);
}
开发者ID:leloulight,项目名称:Razor,代码行数:25,代码来源:TagHelperExecutionContextTest.cs
示例17: Add_MaintainsTagHelpers
public void Add_MaintainsTagHelpers()
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
var tagHelper = new PTagHelper();
// Act
executionContext.Add(tagHelper);
// Assert
var singleTagHelper = Assert.Single(executionContext.TagHelpers);
Assert.Same(tagHelper, singleTagHelper);
}
开发者ID:leloulight,项目名称:Razor,代码行数:13,代码来源:TagHelperExecutionContextTest.cs
示例18: TagHelperExecutionContext_MaintainsAllAttributes
public void TagHelperExecutionContext_MaintainsAllAttributes()
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
var expectedAttributes = new TagHelperAttributeList
{
{ "class", "btn" },
{ "something", true },
{ "foo", "bar" }
};
// Act
executionContext.AddHtmlAttribute("class", "btn");
executionContext.AddTagHelperAttribute("something", true);
executionContext.AddHtmlAttribute("foo", "bar");
// Assert
Assert.Equal(
expectedAttributes,
executionContext.AllAttributes,
CaseSensitiveTagHelperAttributeComparer.Default);
}
开发者ID:leloulight,项目名称:Razor,代码行数:22,代码来源:TagHelperExecutionContextTest.cs
示例19: HtmlAttributes_IgnoresCase
public void HtmlAttributes_IgnoresCase(string originalName, string updatedName)
{
// Arrange
var executionContext = new TagHelperExecutionContext("p", selfClosing: false);
executionContext.HTMLAttributes[originalName] = "hello";
// Act
executionContext.HTMLAttributes[updatedName] = "something else";
// Assert
var attribute = Assert.Single(executionContext.HTMLAttributes);
Assert.Equal(new KeyValuePair<string, object>(originalName, "something else"), attribute);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:13,代码来源:TagHelperExecutionContextTest.cs
示例20: GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled
public async Task GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: null,
uniqueId: string.Empty,
executeChildContentAsync: () => { return Task.FromResult(result: true); },
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync();
content1.Append("Hello");
var content2 = await executionContext.GetChildContentAsync();
content2.Append("World!");
// Assert
Assert.NotSame(content1, content2);
Assert.Empty((await executionContext.GetChildContentAsync()).GetContent());
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:23,代码来源:TagHelperExecutionContextTest.cs
注:本文中的Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论