Add generic ReadOnlyDictionary
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#if NET_2_0
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.SyntaxHelpers;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Collections.Generic
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for ReadOnlyDictionary
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
[TestFixture]
|
||||
public class ReadOnlyDictionaryTests
|
||||
{
|
||||
private IDictionary<string, int> personDictionary;
|
||||
private IDictionary<string, int> readonlyPersonDictionary;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
personDictionary = new Dictionary<string, int>();
|
||||
personDictionary.Add("Mark", 38);
|
||||
personDictionary.Add("Daniela", 38);
|
||||
readonlyPersonDictionary = new ReadOnlyDictionary<string, int>(personDictionary);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSunnyDay()
|
||||
{
|
||||
|
||||
Assert.That(readonlyPersonDictionary.IsReadOnly, Is.True);
|
||||
Assert.That(readonlyPersonDictionary.Contains(new KeyValuePair<string, int>("Mark", 38)));
|
||||
Assert.That(readonlyPersonDictionary.ContainsKey("Mark"), Is.True);
|
||||
Assert.That(readonlyPersonDictionary.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exceptions()
|
||||
{
|
||||
//updating to nunit 2.5 would be nice to use Assert.That( SomeMethod, Throws.Exception<ArgumentException>());
|
||||
// Execute(delegate { });
|
||||
|
||||
Execute(delegate { readonlyPersonDictionary["Mark"] = 4; });
|
||||
Execute(delegate { readonlyPersonDictionary.Add("Gabriel", 3); });
|
||||
Execute(delegate { readonlyPersonDictionary.Add(new KeyValuePair<string, int>("Mark", 38)); });
|
||||
Execute(delegate { readonlyPersonDictionary.Clear();});
|
||||
Execute(delegate { readonlyPersonDictionary.Remove("Mark"); });
|
||||
Execute(delegate { readonlyPersonDictionary.Remove(new KeyValuePair<string, int>("Mark", 38)); });
|
||||
}
|
||||
|
||||
public void Execute(DoInTryCatch exceptionDelegate)
|
||||
{
|
||||
try
|
||||
{
|
||||
exceptionDelegate.Invoke();
|
||||
Assert.Fail("Should throw NotSupportedException");
|
||||
} catch (NotSupportedException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void DoInTryCatch();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -120,6 +120,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Collections\CaseInsensitiveHashtableTests.cs" />
|
||||
<Compile Include="Collections\Generic\ReadOnlyDictionaryTests.cs" />
|
||||
<Compile Include="Collections\HashedSetTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user