Skip to content

Commit

Permalink
Added more EndpointConfiguration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson J Morais committed Feb 5, 2017
1 parent a70d5c7 commit 50e496f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
14 changes: 10 additions & 4 deletions NuBus/EndPointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NuBus.Adapter;
using NuBus.Util;

Expand Down Expand Up @@ -158,22 +159,27 @@ protected void AddMessage(Type Message, MessageType mType)

public void ClearHandlers()
{
throw new NotImplementedException();
Interlocked.Exchange(ref _handlers, new ConcurrentBag<Type>());
}

public void ClearMessages()
{
throw new NotImplementedException();
_messages.Clear();
}

public Type GetHandler(Type messageHandled)
{
throw new NotImplementedException();
Condition.NotNull(messageHandled);

return GetHandlers()
.FirstOrDefault(
h => h.FullName == messageHandled.FullName);
}

public Type GetHandler(string messageHandledFQCN)
{
throw new NotImplementedException();
return GetHandlers()
.FirstOrDefault(h => h.FullName == messageHandledFQCN);
}

public IReadOnlyCollection<Type> GetHandlers()
Expand Down
53 changes: 53 additions & 0 deletions NuBusTest/EndpointConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,58 @@ public void TestMessageReceivedNotThrows()
Assert.DoesNotThrow(() => SpyAdapter.FireMessageReceivedHandlers(eventArgs));
Assert.IsTrue(Called);
}

[Test]
public void TestClearMessages()
{
var endpoint = new EndPointConfiguration(HostName, SpyAdapter);
Assert.Multiple(() =>
{
Assert.IsEmpty(endpoint.GetMessages());
endpoint.AddMessage(typeof(CommandOne));
Assert.IsNotEmpty(endpoint.GetMessages());
endpoint.ClearMessages();
Assert.IsEmpty(endpoint.GetMessages());
});
}

[Test]
public void TestGetHandler()
{
var endpoint = new EndPointConfiguration(HostName, SpyAdapter);
Assert.Multiple(() =>
{
var handlerType = typeof(Handler.CommandOneHandler);
var handleName = handlerType.FullName;
Assert.IsNull(endpoint.GetHandler(handlerType));
endpoint.AddHandler(handlerType);
Assert.IsNotNull(endpoint.GetHandler(handleName));
endpoint.ClearHandlers();
Assert.IsEmpty(endpoint.GetHandlers());
Assert.IsNull(endpoint.GetHandler(string.Empty));
});
}

[Test]
public void TestClearHandlers()
{
var endpoint = new EndPointConfiguration(HostName, SpyAdapter);
Assert.Multiple(() =>
{
Assert.IsEmpty(endpoint.GetHandlers());
endpoint.AddHandler(typeof(Handler.CommandOneHandler));
Assert.IsNotEmpty(endpoint.GetHandlers());
endpoint.ClearHandlers();
Assert.IsEmpty(endpoint.GetHandlers());
});
}
}
}

0 comments on commit 50e496f

Please sign in to comment.