~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/UnitTests/MonoDevelop.AspNet.Mvc.StateEngine/RazorDirectivesParsingTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ//
 
2
// RazorDirectivesParsingTests.cs
 
3
//
 
4
// Author:
 
5
//              Piotr Dowgiallo <sparekd@gmail.com>
 
6
//
 
7
// Copyright (c) 2012 Piotr Dowgiallo
 
8
//
 
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:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using System.Linq;
 
30
using System.Text;
 
31
using MonoDevelop.Xml.StateEngine;
 
32
using MonoDevelop.AspNet.Mvc.StateEngine;
 
33
using NUnit.Framework;
 
34
 
 
35
namespace UnitTests.MonoDevelop.AspNet.Mvc.StateEngine
 
36
{
 
37
        public class RazorDirectivesParsingTests : RazorParsingTests
 
38
        {
 
39
                [Test ()]
 
40
                public void InheritsDirective ()
 
41
                {
 
42
                        parser.Parse ("@inherits Class.Foo.Bar$\n$", () => {
 
43
                                parser.AssertStateIs<RazorDirectiveState> ();
 
44
                                parser.AssertPath ("//@inherits");
 
45
                        }, () => {
 
46
                                parser.AssertStateIs<RazorFreeState> ();
 
47
                                parser.AssertPath ("/");
 
48
                        });
 
49
                }
 
50
 
 
51
                [Test ()]
 
52
                public void ModelDirective ()
 
53
                {
 
54
                        parser.Parse ("@model Foo.Bar$\n$", () => {
 
55
                                parser.AssertStateIs<RazorDirectiveState> ();
 
56
                                parser.AssertPath ("//@model");
 
57
                        }, () => {
 
58
                                parser.AssertStateIs<RazorFreeState> ();
 
59
                                parser.AssertPath ("/");
 
60
                        });
 
61
                }
 
62
 
 
63
                [Test ()]
 
64
                public void SessionstateDirective ()
 
65
                {
 
66
                        parser.Parse ("@sessionstate Bar$\n$", () => {
 
67
                                parser.AssertStateIs<RazorDirectiveState> ();
 
68
                                parser.AssertPath ("//@sessionstate");
 
69
                        }, () => {
 
70
                                parser.AssertStateIs<RazorFreeState> ();
 
71
                                parser.AssertPath ("/");
 
72
                        });
 
73
                }
 
74
 
 
75
                [Test ()]
 
76
                public void LayoutDirective ()
 
77
                {
 
78
                        parser.Parse ("@layout Foo Bar$\n$", () => {
 
79
                                parser.AssertStateIs<RazorDirectiveState> ();
 
80
                                parser.AssertPath ("//@layout");
 
81
                        }, () => {
 
82
                                parser.AssertStateIs<RazorFreeState> ();
 
83
                                parser.AssertPath ("/");
 
84
                        });
 
85
                }
 
86
 
 
87
                [Test ()]
 
88
                public void UsingDirective ()
 
89
                {
 
90
                        parser.Parse ("@using System.Foo.Bar$\n", () => {
 
91
                                parser.AssertStateIs<RazorDirectiveState> ();
 
92
                                parser.AssertPath ("//@using");
 
93
                        }, () => {
 
94
                                parser.AssertStateIs<RazorFreeState> ();
 
95
                                parser.AssertPath ("/");
 
96
                        });
 
97
                }
 
98
 
 
99
                [Test ()]
 
100
                public void UsingDirectiveAsTypeAlias ()
 
101
                {
 
102
                        parser.Parse ("@using Foo = System.Foo.Bar$\n$", () => {
 
103
                                parser.AssertStateIs<RazorDirectiveState> ();
 
104
                                parser.AssertPath ("//@using");
 
105
                        }, () => {
 
106
                                parser.AssertStateIs<RazorFreeState> ();
 
107
                                parser.AssertPath ("/");
 
108
                        });
 
109
                }
 
110
 
 
111
                [Test ()]
 
112
                public void UsingDirectivesCanBeInOneLine ()
 
113
                {
 
114
                        parser.Parse ("@using Foo.Bar$  @using Bar.Foo$\n$", () => {
 
115
                                parser.AssertStateIs<RazorDirectiveState> ();
 
116
                                parser.AssertPath ("//@using");
 
117
                        }, () => {
 
118
                                parser.AssertStateIs<RazorDirectiveState> ();
 
119
                                parser.AssertPath ("//@using");
 
120
                        }, () => {
 
121
                                parser.AssertStateIs<RazorFreeState> ();
 
122
                                parser.AssertPath ("/");
 
123
                        });
 
124
                }
 
125
 
 
126
                [Test ()]
 
127
                public void SimpleDirectiveSupportsGenerics ()
 
128
                {
 
129
                        parser.Parse ("@inherits Web.Foo<IEnumerable<Model<Bar>>$\n$", () => {
 
130
                                parser.AssertStateIs<RazorDirectiveState> ();
 
131
                                parser.AssertPath ("//@inherits");
 
132
                        }, () => {
 
133
                                parser.AssertStateIs<RazorFreeState> ();
 
134
                                parser.AssertPath ("/");
 
135
                        });
 
136
                }
 
137
 
 
138
                [Test ()]
 
139
                public void SimpleDirectiveSupportsArray ()
 
140
                {
 
141
                        parser.Parse ("@inherits Web.Foo[][]$\n$", () => {
 
142
                                parser.AssertStateIs<RazorDirectiveState> ();
 
143
                                parser.AssertPath ("//@inherits");
 
144
                        }, () => {
 
145
                                parser.AssertStateIs<RazorFreeState> ();
 
146
                                parser.AssertPath ("/");
 
147
                        });
 
148
                }
 
149
 
 
150
                [Test ()]
 
151
                public void SimpleDirectiveSupportsSpacesInsideName ()
 
152
                {
 
153
                        parser.Parse ("@model    Web.Foo [] [] $\n$", () => {
 
154
                                parser.AssertStateIs<RazorDirectiveState> ();
 
155
                                parser.AssertPath ("//@model");
 
156
                        }, () => {
 
157
                                parser.AssertStateIs<RazorFreeState> ();
 
158
                                parser.AssertPath ("/");
 
159
                        });
 
160
                }
 
161
 
 
162
                [Test ()]
 
163
                public void FunctionsDirective ()
 
164
                {
 
165
                        parser.Parse ("@functions ${ foo();$\n bar(); }$", () => {
 
166
                                parser.AssertStateIs<RazorDirectiveState> ();
 
167
                                parser.AssertPath ("//@functions");
 
168
                        }, () => {
 
169
                                parser.AssertStateIs<RazorDirectiveState> ();
 
170
                                parser.AssertPath ("//@functions");
 
171
                        }, () => {
 
172
                                parser.AssertStateIs<RazorFreeState> ();
 
173
                                parser.AssertPath ("/");
 
174
                        });
 
175
                }
 
176
 
 
177
                [Test ()]
 
178
                public void SectionDirective ()
 
179
                {
 
180
                        parser.Parse ("@section $Section { <p>Foo $ Bar</p> }$", () => {
 
181
                                parser.AssertStateIs<RazorDirectiveState> ();
 
182
                                parser.AssertPath ("//@section");
 
183
                        }, () => {
 
184
                                parser.AssertStateIs<RazorDirectiveState> ();
 
185
                                parser.AssertPath ("//@section/p");
 
186
                        }, () => {
 
187
                                parser.AssertStateIs<RazorFreeState> ();
 
188
                                parser.AssertPath ("/");
 
189
                        });
 
190
                }
 
191
 
 
192
                [Test ()]
 
193
                public void HelperDirective ()
 
194
                {
 
195
                        parser.Parse ("@helper $Strong(string value) {\n foo($); }$", () => {
 
196
                                parser.AssertStateIs<RazorDirectiveState> ();
 
197
                                parser.AssertPath ("//@helper");
 
198
                        }, () => {
 
199
                                parser.AssertStateIs<RazorDirectiveState> ();
 
200
                                parser.AssertPath ("//@helper");
 
201
                        }, () => {
 
202
                                parser.AssertStateIs<RazorFreeState> ();
 
203
                                parser.AssertPath ("/");
 
204
                        });
 
205
                }
 
206
 
 
207
                [Test ()]
 
208
                public void DirectiveWithNestedBrackets ()
 
209
                {
 
210
                        parser.Parse ("@helper Strong (string value) { { { $ } } $}$", () => {
 
211
                                parser.AssertStateIs<RazorDirectiveState> ();
 
212
                                parser.AssertPath ("//@helper");
 
213
                        }, () => {
 
214
                                parser.AssertStateIs<RazorDirectiveState> ();
 
215
                                parser.AssertPath ("//@helper");
 
216
                        }, () => {
 
217
                                parser.AssertStateIs<RazorFreeState> ();
 
218
                                parser.AssertPath ("/");
 
219
                        });
 
220
                }
 
221
 
 
222
                [Test ()]
 
223
                public void DirectiveInHtml ()
 
224
                {
 
225
                        parser.Parse ("<foo><bar>@section Section { Foo $ bar }</bar></foo>", () => {
 
226
                                parser.AssertStateIs<RazorDirectiveState> ();
 
227
                                parser.AssertPath ("//foo/bar/@section");
 
228
                        });
 
229
                }
 
230
 
 
231
                [Test ()]
 
232
                public void DirectiveSupportsHtml ()
 
233
                {
 
234
                        parser.Parse ("@section Section {<foo><bar>$</bar></foo> }", () => {
 
235
                                parser.AssertStateIs<RazorDirectiveState> ();
 
236
                                parser.AssertPath ("//@section/foo/bar");
 
237
                        });
 
238
                }
 
239
        }
 
240
}