1 // Copyright 2004-2007 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
18 using System
.Collections
;
19 using System
.Collections
.Specialized
;
22 /// Represents a mock implementation of <see cref="ICacheProvider"/> for unit test purposes.
24 public class MockCacheProvider
: ICacheProvider
26 private IDictionary dictionary
= new HybridDictionary(true);
29 /// Services the specified provider.
31 /// <param name="provider">The provider.</param>
32 public void Service(IServiceProvider provider
)
37 /// Determines whether the specified key is on the cache.
39 /// <param name="key">The key.</param>
41 /// <c>true</c> if the cache has the key; otherwise, <c>false</c>.
43 public bool HasKey(string key
)
45 return dictionary
.Contains(key
);
49 /// Gets the cache item by the specified key.
51 /// <param name="key">The key.</param>
52 /// <returns></returns>
53 public object Get(string key
)
55 return dictionary
[key
];
59 /// Stores the cache item by the specified key.
61 /// <param name="key">The key.</param>
62 /// <param name="data">The data.</param>
63 public void Store(string key
, object data
)
65 dictionary
[key
] = data
;
69 /// Deletes the cache item by the specified key.
71 /// <param name="key">The key.</param>
72 public void Delete(string key
)
74 dictionary
.Remove(key
);