Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / ViewComponents / AuthenticatedContentTestCase.cs
blob67dc86e966ade6c74253e38c4c9fbcac71850829
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Tests.ViewComponents
17 using System.Collections;
18 using System.IO;
19 using System.Security.Principal;
20 using Castle.MonoRail.Framework.ViewComponents;
21 using NUnit.Framework;
22 using Test;
24 [TestFixture]
25 public class AuthenticatedContentTestCase
27 private AuthenticatedContent authComponent;
28 private ViewEngineStub viewEngineStub;
29 private StringWriter writer;
30 private MockViewComponentContext componentContext;
31 private MockEngineContext engine;
33 [SetUp]
34 public void Init()
36 writer = new StringWriter();
37 viewEngineStub = new ViewEngineStub();
38 componentContext = new MockViewComponentContext("name", writer, viewEngineStub);
39 authComponent = new AuthenticatedContent();
40 engine = new MockEngineContext(null, null, null, null);
43 [Test]
44 public void RendersLoggedNestedSectionIfUserIsAuthenticated()
46 bool loggedRendered, notloggedRendered;
48 loggedRendered = notloggedRendered = false;
50 componentContext.SectionRender["logged"] = delegate { loggedRendered = true; };
51 componentContext.SectionRender["notlogged"] = delegate { notloggedRendered = true; };
53 engine.CurrentUser = new GenericPrincipal(new GenericIdentity("user", "test"), new string[0]);
54 authComponent.Init(engine, componentContext);
55 authComponent.Render();
57 Assert.IsTrue(loggedRendered);
58 Assert.IsFalse(notloggedRendered);
61 [Test]
62 public void RendersNotLoggedNestedSectionIfUserIsNotAuthenticated()
64 bool loggedRendered, notloggedRendered;
66 loggedRendered = notloggedRendered = false;
68 componentContext.SectionRender["logged"] = delegate(IDictionary context, TextWriter writer) { loggedRendered = true; };
69 componentContext.SectionRender["notlogged"] = delegate(IDictionary context, TextWriter writer) { notloggedRendered = true; };
71 engine.CurrentUser = null;
72 authComponent.Init(engine, componentContext);
73 authComponent.Render();
75 Assert.IsFalse(loggedRendered);
76 Assert.IsTrue(notloggedRendered);