using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LiveLogger4Log4Net;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;
namespace Log4NetLiveTest
{
[TestFixture]
public class RegistrationListTests
{
private MockRepository repo;
[SetUp]
public void SetUp()
{
repo = new MockRepository();
}
[TearDown]
public void TearDown()
{
repo.VerifyAll();
}
///
/// Can I iterate in a empty registrationlist?
///
[Test]
public void VerifyEnumerationForEmpty()
{
RegistrationList sut = new RegistrationList();
foreach (IL4NClient client in sut.GetEnumerator("Logger"))
{
}
}
///
///
///
[Test]
public void VerifyEnumerationForGlobalListener()
{
RegistrationList sut = new RegistrationList();
sut.Add(null);
Assert.That(sut.GetEnumerator("Logger").Count(), Is.EqualTo(1));
}
///
///
///
[Test]
public void VerifyEnumerationForGlobalListenerPlusASpecificOne()
{
RegistrationList sut = new RegistrationList();
IL4NClient c1 = repo.DynamicMock();
IL4NClient c2 = repo.DynamicMock();
repo.ReplayAll();
sut.Add(c1);
sut.Add(c2, "Logger");
Assert.That(sut.GetEnumerator("Logger").Count(), Is.EqualTo(2));
}
///
/// if I add duplicate client the enumeration dischardes duplicates one?
///
[Test]
public void VerifyEnumerationDischardDuplicate()
{
RegistrationList sut = new RegistrationList();
IL4NClient c1 = repo.DynamicMock();
repo.ReplayAll();
sut.Add(c1);
sut.Add(c1, "Logger");
Assert.That(sut.GetEnumerator("Logger").Count(), Is.EqualTo(1));
}
[Test]
public void VerifyEnumerationWithMultiple()
{
RegistrationList sut = new RegistrationList();
sut.Add(repo.DynamicMock());
sut.Add(repo.DynamicMock(), "Logger1");
sut.Add(repo.DynamicMock(), "Logger2");
repo.ReplayAll();
Assert.That(sut.GetEnumerator("Logger1").Count(), Is.EqualTo(2));
Assert.That(sut.GetEnumerator("Logger2").Count(), Is.EqualTo(2));
}
[Test]
public void VerifyEnumerationWithNoRegisteredClients()
{
RegistrationList sut = new RegistrationList();
sut.Add(repo.DynamicMock());
sut.Add(repo.DynamicMock(), "Logger1");
repo.ReplayAll();
Assert.That(sut.GetEnumerator("XXXXXXX").Count(), Is.EqualTo(1));
}
[Test]
public void VerifyAutomaticCalling()
{
RegistrationList sut = new RegistrationList();
IL4NClient c1 = repo.DynamicMock();
Expect.Call(() => c1.ReceiveLog(null))
.IgnoreArguments();
repo.ReplayAll();
sut.Add(c1);
sut.InvokeOnAllClients(c => c.ReceiveLog(null), "XXX");
}
[Test]
public void VerifyAutomaticRemoveForFailing()
{
RegistrationList sut = new RegistrationList();
IL4NClient c1 = repo.DynamicMock();
Expect.Call(() => c1.ReceiveLog(null))
.IgnoreArguments()
.Throw(new Exception());
repo.ReplayAll();
sut.Add(c1);
sut.InvokeOnAllClients(c => c.ReceiveLog(null), "XXX");
Assert.That(sut.GetEnumerator("XXXXXXX").Count(), Is.EqualTo(0));
}
[Test]
public void VerifyAutomaticRemoveForFailingSelective()
{
RegistrationList sut = new RegistrationList();
IL4NClient c1 = repo.DynamicMock();
Expect.Call(() => c1.ReceiveLog(null))
.IgnoreArguments()
.Throw(new Exception());
IL4NClient c2 = repo.DynamicMock();
Expect.Call(() => c2.ReceiveLog(null))
.IgnoreArguments();
repo.ReplayAll();
sut.Add(c1);
sut.Add(c2);
sut.InvokeOnAllClients(c => c.ReceiveLog(null), "XXX");
Assert.That(sut.GetEnumerator("XXXXXXX").Count(), Is.EqualTo(1));
}
}
}