2
// RazorDirectivesParsingTests.cs
5
// Piotr Dowgiallo <sparekd@gmail.com>
7
// Copyright (c) 2012 Piotr Dowgiallo
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
31
using MonoDevelop.Xml.StateEngine;
32
using MonoDevelop.AspNet.Mvc.StateEngine;
33
using NUnit.Framework;
35
namespace UnitTests.MonoDevelop.AspNet.Mvc.StateEngine
37
public class RazorDirectivesParsingTests : RazorParsingTests
40
public void InheritsDirective ()
42
parser.Parse ("@inherits Class.Foo.Bar$\n$", () => {
43
parser.AssertStateIs<RazorDirectiveState> ();
44
parser.AssertPath ("//@inherits");
46
parser.AssertStateIs<RazorFreeState> ();
47
parser.AssertPath ("/");
52
public void ModelDirective ()
54
parser.Parse ("@model Foo.Bar$\n$", () => {
55
parser.AssertStateIs<RazorDirectiveState> ();
56
parser.AssertPath ("//@model");
58
parser.AssertStateIs<RazorFreeState> ();
59
parser.AssertPath ("/");
64
public void SessionstateDirective ()
66
parser.Parse ("@sessionstate Bar$\n$", () => {
67
parser.AssertStateIs<RazorDirectiveState> ();
68
parser.AssertPath ("//@sessionstate");
70
parser.AssertStateIs<RazorFreeState> ();
71
parser.AssertPath ("/");
76
public void LayoutDirective ()
78
parser.Parse ("@layout Foo Bar$\n$", () => {
79
parser.AssertStateIs<RazorDirectiveState> ();
80
parser.AssertPath ("//@layout");
82
parser.AssertStateIs<RazorFreeState> ();
83
parser.AssertPath ("/");
88
public void UsingDirective ()
90
parser.Parse ("@using System.Foo.Bar$\n", () => {
91
parser.AssertStateIs<RazorDirectiveState> ();
92
parser.AssertPath ("//@using");
94
parser.AssertStateIs<RazorFreeState> ();
95
parser.AssertPath ("/");
100
public void UsingDirectiveAsTypeAlias ()
102
parser.Parse ("@using Foo = System.Foo.Bar$\n$", () => {
103
parser.AssertStateIs<RazorDirectiveState> ();
104
parser.AssertPath ("//@using");
106
parser.AssertStateIs<RazorFreeState> ();
107
parser.AssertPath ("/");
112
public void UsingDirectivesCanBeInOneLine ()
114
parser.Parse ("@using Foo.Bar$ @using Bar.Foo$\n$", () => {
115
parser.AssertStateIs<RazorDirectiveState> ();
116
parser.AssertPath ("//@using");
118
parser.AssertStateIs<RazorDirectiveState> ();
119
parser.AssertPath ("//@using");
121
parser.AssertStateIs<RazorFreeState> ();
122
parser.AssertPath ("/");
127
public void SimpleDirectiveSupportsGenerics ()
129
parser.Parse ("@inherits Web.Foo<IEnumerable<Model<Bar>>$\n$", () => {
130
parser.AssertStateIs<RazorDirectiveState> ();
131
parser.AssertPath ("//@inherits");
133
parser.AssertStateIs<RazorFreeState> ();
134
parser.AssertPath ("/");
139
public void SimpleDirectiveSupportsArray ()
141
parser.Parse ("@inherits Web.Foo[][]$\n$", () => {
142
parser.AssertStateIs<RazorDirectiveState> ();
143
parser.AssertPath ("//@inherits");
145
parser.AssertStateIs<RazorFreeState> ();
146
parser.AssertPath ("/");
151
public void SimpleDirectiveSupportsSpacesInsideName ()
153
parser.Parse ("@model Web.Foo [] [] $\n$", () => {
154
parser.AssertStateIs<RazorDirectiveState> ();
155
parser.AssertPath ("//@model");
157
parser.AssertStateIs<RazorFreeState> ();
158
parser.AssertPath ("/");
163
public void FunctionsDirective ()
165
parser.Parse ("@functions ${ foo();$\n bar(); }$", () => {
166
parser.AssertStateIs<RazorDirectiveState> ();
167
parser.AssertPath ("//@functions");
169
parser.AssertStateIs<RazorDirectiveState> ();
170
parser.AssertPath ("//@functions");
172
parser.AssertStateIs<RazorFreeState> ();
173
parser.AssertPath ("/");
178
public void SectionDirective ()
180
parser.Parse ("@section $Section { <p>Foo $ Bar</p> }$", () => {
181
parser.AssertStateIs<RazorDirectiveState> ();
182
parser.AssertPath ("//@section");
184
parser.AssertStateIs<RazorDirectiveState> ();
185
parser.AssertPath ("//@section/p");
187
parser.AssertStateIs<RazorFreeState> ();
188
parser.AssertPath ("/");
193
public void HelperDirective ()
195
parser.Parse ("@helper $Strong(string value) {\n foo($); }$", () => {
196
parser.AssertStateIs<RazorDirectiveState> ();
197
parser.AssertPath ("//@helper");
199
parser.AssertStateIs<RazorDirectiveState> ();
200
parser.AssertPath ("//@helper");
202
parser.AssertStateIs<RazorFreeState> ();
203
parser.AssertPath ("/");
208
public void DirectiveWithNestedBrackets ()
210
parser.Parse ("@helper Strong (string value) { { { $ } } $}$", () => {
211
parser.AssertStateIs<RazorDirectiveState> ();
212
parser.AssertPath ("//@helper");
214
parser.AssertStateIs<RazorDirectiveState> ();
215
parser.AssertPath ("//@helper");
217
parser.AssertStateIs<RazorFreeState> ();
218
parser.AssertPath ("/");
223
public void DirectiveInHtml ()
225
parser.Parse ("<foo><bar>@section Section { Foo $ bar }</bar></foo>", () => {
226
parser.AssertStateIs<RazorDirectiveState> ();
227
parser.AssertPath ("//foo/bar/@section");
232
public void DirectiveSupportsHtml ()
234
parser.Parse ("@section Section {<foo><bar>$</bar></foo> }", () => {
235
parser.AssertStateIs<RazorDirectiveState> ();
236
parser.AssertPath ("//@section/foo/bar");