Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Experiments / SubversionHooks / CastleProjectHooks.Tests / PreCommitEolStyleTestCase.cs
blob7b29f4757c1aa5b4f942d288c56186b2c38dca75
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 Castel.SvnHooks.CastleProject.Tests
17 using System;
19 using NUnit.Framework;
21 using Castle.SvnHooks;
22 using Castle.SvnHooks.CastleProject;
24 /// <summary>
25 /// Summary description for PreCommitEolStyleTestCase.
26 /// </summary>
27 [TestFixture] public class PreCommitEolStyleTestCase
30 IPreCommit hook;
32 #region Setup / Teardown
34 [TestFixtureSetUp] public void FixtureSetUp()
36 hook = new PreCommitEolStyle("cs");
40 #endregion
42 [Test] public void NoProperties()
44 AssertErrors(null, 1,
45 "This file must have svn:eol-style set to native");
47 [Test] public void EolStyleLF()
49 AssertErrors("LF", 1,
50 "This file must have svn:eol-style set to native");
52 [Test] public void EolStyleCR()
54 AssertErrors("CR", 1,
55 "This file must have svn:eol-style set to native");
57 [Test] public void EolStyleCRLF()
59 AssertErrors("CRLF", 1,
60 "This file must have svn:eol-style set to native");
62 [Test] public void EolStyleNative()
64 AssertNoErrors("native");
68 [Test] public void UncheckedExtension()
70 AssertNoErrors(null, "trunk/file.txt");
74 [Test] public void Deleted()
77 using(RepositoryFile file = new RepositoryFile(new MockRepository(null), "File.cs", RepositoryStatus.Deleted, RepositoryStatus.Unchanged))
79 Error[] errors = hook.PreCommit(file);
81 Assert.AreEqual(0, errors.Length);
86 private void AssertNoErrors(String eolStyle, String fileName)
89 using(RepositoryFile file = MockRepository.GetFile(eolStyle, fileName))
91 Error[] errors = hook.PreCommit(file);
93 Assert.AreEqual(0, errors.Length);
97 private void AssertNoErrors(String eolStyle)
100 AssertNoErrors(eolStyle, "trunk/File.cs");
103 private void AssertErrors(String eolStyle, int count, params String[] messages)
106 using(RepositoryFile file = MockRepository.GetFile(eolStyle, "trunk/File.cs"))
108 Error[] errors = hook.PreCommit(file);
110 Assert.AreEqual(count, errors.Length);
111 for(int i = 0; i < count; i++)
113 Assert.AreEqual(messages[i], errors[i].Description);
114 Assert.AreEqual(file, errors[i].File);
121 private class MockRepository : IRepository
123 public MockRepository(String eolStyle)
125 this.EolStyle = eolStyle;
128 public static RepositoryFile GetFile(String eolStyle, String fileName)
130 return new RepositoryFile(new MockRepository(eolStyle), fileName, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged);
133 #region IRepository Members
135 public string[] GetProperty(string path, string property)
137 if (EolStyle != null && property == "svn:eol-style")
138 return new String[]{EolStyle};
140 return null;
143 public System.IO.Stream GetFileContents(string path)
145 return null;
149 #endregion
151 private readonly String EolStyle;