/*
* Copyright (C) 2006-2007 Eskil Bylund
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections;
using System.Net;
using NUnit.Framework;
using DCSharp.Backend.Connections;
using DCSharp.Backend.Managers;
using DCSharp.Backend.Objects;
using DCSharp.Backend.Protocols;
namespace DCSharp.Backend.Managers.Test{
public class MockUserProtocol : MockProtocol, IUserProtocol
{
public void DownloadFile(DownloadFileInfo download, SourceInfo source) {}
}
[TestFixture()]
public class ConnectionManagerTest
{
private ConnectionManager manager;
private UserConnection connection;
[SetUp]
public void SetUp()
{
Uid pid = Uid.Generate();
LocalIdentity identity = new LocalIdentity(pid, "Nick");
connection = new UserConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234),
identity, new MockUserProtocol());
manager = new ConnectionManager(new HubManager());
}
[Test]
public void AddConnection()
{
Uid cid = Uid.Generate();
connection.RemoteIdentity = new Identity(User.Create(cid, "Remote User"));
manager.Add(connection);
manager.Add(connection);
Assert.IsTrue(manager.Count == 1);
Assert.IsTrue(manager.Contains(connection));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void AddConnectionWithoutRemoteIdentity()
{
manager.Add(connection);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AddNull()
{
manager.Add(null);
}
[Test]
public void Remove()
{
AddConnection();
manager.Remove(connection);
manager.Remove(connection);
Assert.IsTrue(manager.Count == 0);
Assert.IsFalse(manager.Contains(connection));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void RemoveNull()
{
manager.Remove(null);
}
[Test]
public void Contains()
{
Assert.IsFalse(manager.Contains(null));
}
}
}
|