/*
* 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.Text;
using System.Collections;
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 MockProtocol : IProtocol
{
public string MessageSeparator
{
get { return "\n"; }
}
public Encoding Encoding
{
get { return Encoding.UTF8; }
}
public void Handle(string message) {}
public void Initialize() {}
}
public class MockHubProtocol : MockProtocol, IHubProtocol
{
public void SendPrivateMessage(Identity identity, string message) {}
public void SendMessage(string message) {}
public void Search(SearchInfo searchInfo) {}
public void RequestConnection(Identity identity) {}
}
[TestFixture()]
public class HubManagerTest
{
private HubConnection connection;
private HubManager manager;
[SetUp]
public void SetUp()
{
Uid pid = Uid.Generate();
LocalIdentity identity = new LocalIdentity(pid, "Nick");
connection = new HubConnection("localhost:4012", identity,
new MockHubProtocol());
manager = new HubManager();
}
[Test]
public void Add()
{
manager.Add(connection);
manager.Add(connection);
Assert.IsTrue(manager.Count == 1);
Assert.IsTrue(manager.Contains(connection));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AddNull()
{
manager.Add(null);
}
[Test]
public void Remove()
{
Add();
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));
}
}
}
|