This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test TagHelperScopeManager functionality.
- Loading branch information
1 parent
6408884
commit aab46c4
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperScopeManagerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNet.Razor.Runtime.TagHelpers; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.Razor.Runtime.Test.TagHelpers | ||
{ | ||
public class TagHelperScopeManagerTest | ||
{ | ||
[Fact] | ||
public void TagHelperScopeManager_BeginCreatesContextWithAppropriateTagName() | ||
{ | ||
// Arrange | ||
var scopeManager = new TagHelperScopeManager(); | ||
|
||
// Act | ||
var executionContext = scopeManager.Begin("p"); | ||
|
||
// Assert | ||
Assert.Equal("p", executionContext.TagName); | ||
} | ||
|
||
[Fact] | ||
public void TagHelperScopeManager_BeginCanNest() | ||
{ | ||
// Arrange | ||
var scopeManager = new TagHelperScopeManager(); | ||
|
||
// Act | ||
var executionContext = scopeManager.Begin("p"); | ||
executionContext = scopeManager.Begin("div"); | ||
|
||
// Assert | ||
Assert.Equal("div", executionContext.TagName); | ||
} | ||
|
||
[Fact] | ||
public void TagHelperScopeManager_EndReturnsParentExecutionContext() | ||
{ | ||
// Arrange | ||
var scopeManager = new TagHelperScopeManager(); | ||
|
||
// Act | ||
var executionContext = scopeManager.Begin("p"); | ||
executionContext = scopeManager.Begin("div"); | ||
executionContext = scopeManager.End(); | ||
|
||
// Assert | ||
Assert.Equal("p", executionContext.TagName); | ||
} | ||
|
||
[Fact] | ||
public void TagHelperScopeManager_EndReturnsNullIfNoNestedContext() | ||
{ | ||
// Arrange | ||
var scopeManager = new TagHelperScopeManager(); | ||
|
||
// Act | ||
var executionContext = scopeManager.Begin("p"); | ||
executionContext = scopeManager.Begin("div"); | ||
executionContext = scopeManager.End(); | ||
executionContext = scopeManager.End(); | ||
|
||
// Assert | ||
Assert.Null(executionContext); | ||
} | ||
|
||
[Fact] | ||
public void TagHelperScopeManager_EndThrowsIfNoScope() | ||
{ | ||
// Arrange | ||
var scopeManager = new TagHelperScopeManager(); | ||
var expectedError = | ||
"You cannot call 'End' without first calling 'Begin' on the " + nameof(TagHelperScopeManager) + "."; | ||
|
||
// Act & Assert | ||
var ex = Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
scopeManager.End(); | ||
}); | ||
|
||
Assert.Equal(expectedError, ex.Message); | ||
|
||
} | ||
} | ||
} |