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
.MonoRail
.Framework
.Test
17 using System
.Collections
;
18 using System
.Collections
.Specialized
;
21 /// Represents a mock implementation of <see cref="ICacheProvider"/> for unit test purposes.
23 public class MockCacheProvider
: ICacheProvider
25 private IDictionary dictionary
= new HybridDictionary(true);
28 /// Services the specified provider.
30 /// <param name="provider">The provider.</param>
31 public void Service(IMonoRailServices provider
)
36 /// Determines whether the specified key is on the cache.
38 /// <param name="key">The key.</param>
40 /// <c>true</c> if the cache has the key; otherwise, <c>false</c>.
42 public bool HasKey(string key
)
44 return dictionary
.Contains(key
);
48 /// Gets the cache item by the specified key.
50 /// <param name="key">The key.</param>
51 /// <returns></returns>
52 public object Get(string key
)
54 return dictionary
[key
];
58 /// Stores the cache item by the specified key.
60 /// <param name="key">The key.</param>
61 /// <param name="data">The data.</param>
62 public void Store(string key
, object data
)
64 dictionary
[key
] = data
;
68 /// Deletes the cache item by the specified key.
70 /// <param name="key">The key.</param>
71 public void Delete(string key
)
73 dictionary
.Remove(key
);