Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a test for marking a message's IsCommand flag if a command is s…

…ent.

- Renamed SignalCommad to Command
  • Loading branch information...
commit d35e8fcc970fbb91847acd4d1d7e9ca642cee02d 1 parent ab7bba1
David Fowler davidfowl authored
38 SignalR.Tests/Server/ConnectionFacts.cs
View
@@ -0,0 +1,38 @@
+using Moq;
+using SignalR.Infrastructure;
+using Xunit;
+
+namespace SignalR.Tests.Server
+{
+ public class ConnectionFacts
+ {
+ [Fact]
+ public void SendingCommandObjectSetsCommandOnBus()
+ {
+ var messageBus = new Mock<INewMessageBus>();
+ Message message = null;
+ messageBus.Setup(m => m.Publish(It.IsAny<Message>())).Callback<Message>(m => message = m);
+ var serializer = new JsonNetSerializer();
+ var traceManager = new Mock<ITraceManager>();
+ var connection = new Connection(messageBus.Object,
+ serializer,
+ "signal",
+ "connectonid",
+ new[] { "a", "signal", "connectionid" },
+ new string[] { },
+ traceManager.Object);
+
+ connection.Send("a", new Command
+ {
+ Type = CommandType.AddToGroup,
+ Value = "foo"
+ });
+
+ Assert.NotNull(message);
+ Assert.True(message.IsCommand);
+ var command = serializer.Parse<Command>(message.Value);
+ Assert.Equal(CommandType.AddToGroup, command.Type);
+ Assert.Equal(@"{""Name"":""foo"",""Cursor"":null}", command.Value);
+ }
+ }
+}
1  SignalR.Tests/SignalR.Tests.csproj
View
@@ -56,6 +56,7 @@
</Compile>
<Compile Include="ChunkBufferFacts.cs" />
<Compile Include="Infrastructure\CountDownRange.cs" />
+ <Compile Include="Server\ConnectionFacts.cs" />
<Compile Include="Server\Connections\ConnectionFacts.cs" />
<Compile Include="CursorFacts.cs" />
<Compile Include="DefaultHubResolverFacts.cs" />
2  SignalR/SignalCommand.cs → SignalR/Command.cs
View
@@ -2,7 +2,7 @@
namespace SignalR
{
- public class SignalCommand
+ public class Command
{
public CommandType Type { get; set; }
public string Value { get; set; }
6 SignalR/Connection.cs
View
@@ -106,7 +106,7 @@ private object PreprocessValue(object value, out bool isCommand)
isCommand = false;
// If this isn't a command then ignore it
- var command = value as SignalCommand;
+ var command = value as Command;
if (command == null)
{
return value;
@@ -216,14 +216,14 @@ private void ProcessResults(MessageResult result)
Message message = result.Messages[i].Array[j];
if (message.IsCommand)
{
- var command = _serializer.Parse<SignalCommand>(message.Value);
+ var command = _serializer.Parse<Command>(message.Value);
ProcessCommand(command);
}
}
}
}
- private void ProcessCommand(SignalCommand command)
+ private void ProcessCommand(Command command)
{
switch (command.Type)
{
4 SignalR/GroupManager.cs
View
@@ -41,7 +41,7 @@ public Task Send(string groupName, object value)
/// <returns>A task that represents the connection id being added to the group.</returns>
public Task Add(string connectionId, string groupName)
{
- var command = new SignalCommand
+ var command = new Command
{
Type = CommandType.AddToGroup,
Value = CreateQualifiedName(groupName)
@@ -58,7 +58,7 @@ public Task Add(string connectionId, string groupName)
/// <returns>A task that represents the connection id being removed from the group.</returns>
public Task Remove(string connectionId, string groupName)
{
- var command = new SignalCommand
+ var command = new Command
{
Type = CommandType.RemoveFromGroup,
Value = CreateQualifiedName(groupName)
4 SignalR/Infrastructure/ConnectionExtensions.cs
View
@@ -6,7 +6,7 @@ internal static class ConnectionExtensions
{
public static Task Close(this ITransportConnection connection, string connectionId)
{
- var command = new SignalCommand
+ var command = new Command
{
Type = CommandType.Disconnect
};
@@ -16,7 +16,7 @@ public static Task Close(this ITransportConnection connection, string connection
public static Task Abort(this ITransportConnection connection, string connectionId)
{
- var command = new SignalCommand
+ var command = new Command
{
Type = CommandType.Abort
};
2  SignalR/SignalR.csproj
View
@@ -143,7 +143,7 @@
<Compile Include="Infrastructure\ServerCommand.cs" />
<Compile Include="Infrastructure\ServerCommandType.cs" />
<Compile Include="Infrastructure\ServerCommandHandler.cs" />
- <Compile Include="SignalCommand.cs" />
+ <Compile Include="Command.cs" />
<Compile Include="Transports\ForeverFrameTransport.cs" />
<Compile Include="Transports\ForeverTransport.cs" />
<Compile Include="Configuration\IConfigurationManager.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.