#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Ingenious.Mvc.Configuration;
namespace Ingenious.Mvc.UnitTest.Configuration{
/// <summary>
/// Unit tests the <see cref="InfoCollection"/> class.
/// </summary>
public sealed class InfoCollectionTest : UnitTestBase
{
private InfoCollection<Id<IView>, ViewInfo> _infoCollection;
private const string _id = "id";
protected override void SetUp()
{
_infoCollection = new InfoCollection<Id<IView>, ViewInfo>();
}
[Test]
public void TestIndexer()
{
Assert.IsNull(_infoCollection[_id]);
ViewInfo info = new ViewInfo(_id);
_infoCollection.Add(info);
Assert.AreEqual(info, _infoCollection[_id]);
}
[Test]
public void TestReadOnly()
{
Assert.IsFalse(_infoCollection.IsReadOnly);
}
[Test]
public void TestCount()
{
Assert.AreEqual(0, _infoCollection.Count);
ViewInfo info = new ViewInfo(_id);
_infoCollection.Add(info);
Assert.AreEqual(1, _infoCollection.Count);
_infoCollection.Remove(info);
Assert.AreEqual(0, _infoCollection.Count);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestAddNull()
{
_infoCollection.Add(null);
}
[Test]
public void TestAdd()
{
Assert.IsNull(_infoCollection[_id]);
ViewInfo info = new ViewInfo(_id);
_infoCollection.Add(info);
Assert.AreEqual(1, _infoCollection.Count);
_infoCollection.Add(info);
//still only 1 because used the same ID
Assert.AreEqual(1, _infoCollection.Count);
info = new ViewInfo(_id + "changed");
_infoCollection.Add(info);
Assert.AreEqual(2, _infoCollection.Count);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestAddRangeNull()
{
_infoCollection.AddRange(null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestAddRangeNullEntry()
{
ViewInfo[] viewInfos = new ViewInfo[2];
viewInfos[0] = new ViewInfo(_id);
_infoCollection.AddRange(viewInfos);
}
[Test]
public void TestAddRange()
{
List<ViewInfo> viewInfos = new List<ViewInfo>();
for (int i = 0; i < 100; ++i)
{
viewInfos.Add(new ViewInfo(_id + i));
}
_infoCollection.AddRange(viewInfos);
Assert.AreEqual(100, _infoCollection.Count);
}
[Test]
public void TestClear()
{
Assert.AreEqual(0, _infoCollection.Count);
_infoCollection.Clear();
Assert.AreEqual(0, _infoCollection.Count);
for (int i = 0; i < 100; ++i)
{
_infoCollection.Add(new ViewInfo(_id + i));
}
Assert.AreEqual(100, _infoCollection.Count);
_infoCollection.Clear();
Assert.AreEqual(0, _infoCollection.Count);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestContainsNull()
{
_infoCollection.Contains(null);
}
[Test]
public void TestContains()
{
ViewInfo info = new ViewInfo(_id);
Assert.IsFalse(_infoCollection.Contains(info));
_infoCollection.Add(info);
Assert.IsTrue(_infoCollection.Contains(info));
Assert.IsFalse(_infoCollection.Contains(new ViewInfo(_id + "changed")));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestCopyToArrayNull()
{
_infoCollection.CopyTo(null, 0);
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), "Non-negative number required.\r\nParameter name: index")]
public void TestCopyToIndexNegative()
{
_infoCollection.CopyTo(new ViewInfo[2], -1);
}
[Test]
[ExpectedException(typeof(ArgumentException), "Destination array is not long enough to copy all the items in the collection. Check array index and length.")]
public void TestCopyToArrayTooSmall()
{
for (int i = 0; i < 100; ++i)
{
_infoCollection.Add(new ViewInfo(_id + i));
}
ViewInfo[] viewInfos = new ViewInfo[0];
_infoCollection.CopyTo(viewInfos, 0);
}
[Test]
public void TestCopyTo()
{
for (int i = 0; i < 100; ++i)
{
_infoCollection.Add(new ViewInfo(_id + i));
}
ViewInfo[] viewInfos = new ViewInfo[100];
_infoCollection.CopyTo(viewInfos, 0);
for (int i = 0; i < viewInfos.Length; ++i)
{
Assert.IsNotNull(viewInfos[i]);
}
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestRemoveNull()
{
_infoCollection.Remove(null);
}
[Test]
public void TestRemove()
{
ViewInfo info = new ViewInfo(_id);
Assert.AreEqual(0, _infoCollection.Count);
_infoCollection.Remove(info);
Assert.AreEqual(0, _infoCollection.Count);
_infoCollection.Add(info);
Assert.AreEqual(1, _infoCollection.Count);
_infoCollection.Remove(info);
Assert.AreEqual(0, _infoCollection.Count);
}
[Test]
public void TestEnumeratorGeneric()
{
for (int i = 0; i < 100; ++i)
{
_infoCollection.Add(new ViewInfo(_id + i));
}
foreach (ViewInfo info in _infoCollection)
{
Assert.IsNotNull(info);
}
}
[Test]
public void TestEnumerator()
{
for (int i = 0; i < 100; ++i)
{
_infoCollection.Add(new ViewInfo(_id + i));
}
System.Collections.IEnumerator enumerator = ((System.Collections.IEnumerable) _infoCollection).GetEnumerator();
while (enumerator.MoveNext())
{
Assert.IsNotNull(enumerator.Current);
}
}
}
}
|