Skip to content

Commit

Permalink
Added Moq dll. Moved test libs. Server creates ListenerSocket in cons…
Browse files Browse the repository at this point in the history
…tructor
  • Loading branch information
statianzo committed Mar 5, 2011
1 parent 195bba4 commit 7282510
Show file tree
Hide file tree
Showing 7 changed files with 5,171 additions and 9 deletions.
Binary file added libs/TestingLibs/Moq.dll
Binary file not shown.
5,120 changes: 5,120 additions & 0 deletions libs/TestingLibs/Moq.xml

Large diffs are not rendered by default.

Binary file added libs/TestingLibs/nunit.framework.dll
Binary file not shown.
15 changes: 13 additions & 2 deletions src/Fleck.Tests/Fleck.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\libs\nunit.framework.dll</HintPath>
<Reference Include="Moq">
<HintPath>..\..\libs\TestingLibs\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\libs\TestingLibs\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -44,6 +48,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebSocketServerTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fleck\Fleck.csproj">
<Project>{8B12D929-AFA9-4307-BEFF-2ED0F1070FEE}</Project>
<Name>Fleck</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
33 changes: 33 additions & 0 deletions src/Fleck.Tests/WebSocketServerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Net;
using Moq;
using NUnit.Framework;

namespace Fleck.Tests
{
[TestFixture]
public class WebSocketServerTests
{
private WebSocketServer _server;
private MockRepository _repository;

[SetUp]
public void Setup()
{
_repository = new MockRepository(MockBehavior.Default);
_server = new WebSocketServer("ws://localhost:8000");
}

[Test]
public void ShouldStart()
{
var socketMock = _repository.Create<ISocket>();

_server.ListenerSocket = socketMock.Object;
_server.Start(connection => { });

socketMock.Verify(s => s.Bind(It.Is<IPEndPoint>(i => i.Port == 8000)));
socketMock.Verify(s => s.BeginAccept(It.IsAny<AsyncCallback>(), It.IsAny<object>()));
}
}
}
1 change: 0 additions & 1 deletion src/Fleck/WebSocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ public void Close()
Socket.Close();
}
}

}
11 changes: 5 additions & 6 deletions src/Fleck/WebSocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ public class WebSocketServer : IDisposable
{
private Action<IWebSocketConnection> _config;

public WebSocketServer(string location)
public WebSocketServer(string location) : this(0, location)
{
var uri = new Uri(location);
Port = uri.Port > 0 ? uri.Port : 8181;
Location = location;
}
public WebSocketServer(int port, string location)
{
Port = port;
Location = location;
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
ListenerSocket = new SocketWrapper(socket);
}

public WebSocketServer(int port, string location, string origin)
Expand All @@ -27,10 +28,10 @@ public WebSocketServer(int port, string location, string origin)
Origin = origin;
}

public ISocket ListenerSocket { get; private set; }
public ISocket ListenerSocket { get; set; }
public string Location { get; private set; }
public int Port { get; private set; }
public string Origin { get; private set; }
public string Origin { get; set; }

public void Dispose()
{
Expand All @@ -39,8 +40,6 @@ public void Dispose()

public void Start(Action<IWebSocketConnection> config)
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
ListenerSocket = new SocketWrapper(socket);
var ipLocal = new IPEndPoint(IPAddress.Any, Port);
ListenerSocket.Bind(ipLocal);
ListenerSocket.Listen(100);
Expand Down

0 comments on commit 7282510

Please sign in to comment.