Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Core / Castle.Core.Tests / Resources / FileResourceFactoryTestCase.cs
blob21623cb1d83d352e5f1b927b330177a82e28c02a
1 // Copyright 2004-2007 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.Core.Tests.Resources
17 using System;
18 using System.Configuration;
19 using System.IO;
21 using NUnit.Framework;
23 using Castle.Core.Resource;
26 [TestFixture]
27 public class FileResourceFactoryTestCase
29 private FileResourceFactory resFactory = new FileResourceFactory();
30 private String basePath = Path.Combine(ConfigurationManager.AppSettings["tests.src"], "Resources");
32 [TestFixtureSetUp]
33 public void Init()
35 basePath = Path.Combine(Directory.GetCurrentDirectory(), basePath);
38 [Test]
39 public void Accept()
41 Assert.IsTrue( resFactory.Accept( new CustomUri("file://something") ) );
42 Assert.IsFalse( resFactory.Accept( new CustomUri("http://www.castleproject.org") ) );
45 [Test]
46 public void CreateWithAbsolutePath()
48 String file = Path.Combine(basePath, "file1.txt");
50 FileInfo fileInfo = new FileInfo(file);
52 CustomUri uri = new CustomUri(fileInfo.FullName);
54 IResource resource = resFactory.Create(uri, null);
56 Assert.IsNotNull(resource);
57 String line = resource.GetStreamReader().ReadLine();
58 Assert.AreEqual("Something", line);
61 [Test]
62 public void CreateWithRelativePath()
64 IResource resource = resFactory.Create( new CustomUri(basePath + "/file1.txt") );
66 Assert.IsNotNull(resource);
67 String line = resource.GetStreamReader().ReadLine();
68 Assert.AreEqual("Something", line);
71 [Test]
72 public void CreateWithRelativePathAndContext()
74 CustomUri uri = new CustomUri("file://file1.txt");
76 IResource resource = resFactory.Create( uri, basePath );
78 Assert.IsNotNull(resource);
79 String line = resource.GetStreamReader().ReadLine();
80 Assert.AreEqual("Something", line);
83 [Test]
84 [ExpectedException(typeof(ResourceException))]
85 public void NonExistingResource()
87 resFactory.Create( new CustomUri(basePath + "/Something/file1.txt") );