1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Configuration
;
21 using NUnit
.Framework
;
23 using Castle
.Core
.Resource
;
27 public class FileResourceFactoryTestCase
29 private FileResourceFactory resFactory
= new FileResourceFactory();
30 private String basePath
= Path
.Combine(ConfigurationManager
.AppSettings
["tests.src"], "Resources");
35 basePath
= Path
.Combine(Directory
.GetCurrentDirectory(), basePath
);
41 Assert
.IsTrue( resFactory
.Accept( new CustomUri("file://something") ) );
42 Assert
.IsFalse( resFactory
.Accept( new CustomUri("http://www.castleproject.org") ) );
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
);
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
);
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
);
84 [ExpectedException(typeof(ResourceException
))]
85 public void NonExistingResource()
87 resFactory
.Create( new CustomUri(basePath
+ "/Something/file1.txt") )