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 Castel
.SvnHooks
.CastleProject
.Tests
19 using NUnit
.Framework
;
21 using Castle
.SvnHooks
;
22 using Castle
.SvnHooks
.CastleProject
;
25 /// Summary description for PreCommitEolStyleTestCase.
27 [TestFixture
] public class PreCommitEolStyleTestCase
32 #region Setup / Teardown
34 [TestFixtureSetUp
] public void FixtureSetUp()
36 hook
= new PreCommitEolStyle("cs");
42 [Test
] public void NoProperties()
45 "This file must have svn:eol-style set to native");
47 [Test
] public void EolStyleLF()
50 "This file must have svn:eol-style set to native");
52 [Test
] public void EolStyleCR()
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}
;
143 public System
.IO
.Stream
GetFileContents(string path
)
151 private readonly String EolStyle
;