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
.SvnHooks
.Tests
.RepositoryFileTestCases
18 using System
.Collections
;
21 using NUnit
.Framework
;
23 using Castle
.SvnHooks
;
26 /// Summary description for GetContentsTestCase.
28 [TestFixture
] public class GetContentsTestCase
30 private const String SVN_MIME_TYPE
= "svn:mime-type";
32 //private const String NO_CONTENTS_PATH = "nocontents";
33 private const String BINARY_WITH_CONTENTS_PATH
= "bin";
34 private const String CONTENTS_PATH
= "text";
36 private IRepository repository
;
38 #region Setup / Teardown
40 [TestFixtureSetUp
] public void FixtureSetUp()
42 MockRepository mockRepository
= new MockRepository();
43 //mockRepository.AddFile(NO_CONTENTS_PATH, null, null, null);
44 mockRepository
.AddFile(BINARY_WITH_CONTENTS_PATH
, null, MimeType("application/octet-stream"), "Contents");
45 mockRepository
.AddFile(CONTENTS_PATH
, null, null, "This is the first line\nSecond Line...\nAnd the third\n\nFinal line!");
47 repository
= mockRepository
;
51 private static IDictionary
MimeType(String mimeType
)
53 IDictionary dictionary
= new Hashtable();
54 dictionary
.Add(SVN_MIME_TYPE
, new String
[]{mimeType}
);
62 [ExpectedException(typeof(InvalidOperationException
))]
63 [Test
] public void BinaryWithContents()
65 RepositoryFile file
= new RepositoryFile(repository
, BINARY_WITH_CONTENTS_PATH
, RepositoryStatus
.Unchanged
, RepositoryStatus
.Unchanged
);
67 Stream stream
= file
.GetContents();
71 [Test
] public void Contents()
73 RepositoryFile file
= new RepositoryFile(repository
, CONTENTS_PATH
, RepositoryStatus
.Unchanged
, RepositoryStatus
.Unchanged
);
75 using(Stream stream
= file
.GetContents())
76 using(TextReader reader
= new StreamReader(stream
))
79 Assert
.AreEqual("This is the first line", reader
.ReadLine());
80 Assert
.AreEqual("Second Line...", reader
.ReadLine());
81 Assert
.AreEqual("And the third", reader
.ReadLine());
82 Assert
.AreEqual("", reader
.ReadLine());
83 Assert
.AreEqual("Final line!", reader
.ReadLine());
84 Assert
.AreEqual(null, reader
.ReadLine());
89 [Test
] public void RepeatedGetContents()
91 RepositoryFile file
= new RepositoryFile(repository
, CONTENTS_PATH
, RepositoryStatus
.Unchanged
, RepositoryStatus
.Unchanged
);
93 for(int i
= 0; i
< 2; i
++)
95 using(Stream stream
= file
.GetContents())
96 using(TextReader reader
= new StreamReader(stream
))
99 Assert
.AreEqual("This is the first line", reader
.ReadLine());
100 Assert
.AreEqual("Second Line...", reader
.ReadLine());
101 Assert
.AreEqual("And the third", reader
.ReadLine());
102 Assert
.AreEqual("", reader
.ReadLine());
103 Assert
.AreEqual("Final line!", reader
.ReadLine());
104 Assert
.AreEqual(null, reader
.ReadLine());