Skip to content

Commit

Permalink
Fixed failing test. Changed generic type name.
Browse files Browse the repository at this point in the history
For more info on change, why test failed and how to avoid it again see:
castleproject/Core#106
  • Loading branch information
HelloKitty committed Aug 4, 2015
1 parent 1523535 commit 463a0c5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/GladNet.Common/GladNet.Common.csproj
Expand Up @@ -11,6 +11,8 @@
<AssemblyName>GladNet.Common</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -68,8 +70,14 @@
<Compile Include="Packet\PacketPayload.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
18 changes: 9 additions & 9 deletions src/GladNet.Common/Network/Peer/ConcretePeers/ClientPeer.cs
Expand Up @@ -9,26 +9,26 @@ namespace GladNet.Common
{
public abstract class ClientPeer : Peer, IClientMessageSender
{
public sealed override bool CanSend(NetworkMessage.OperationType opType)
public override bool CanSend(NetworkMessage.OperationType opType)
{
return opType == NetworkMessage.OperationType.Request;
}

#region Message Senders
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public NetworkMessage.SendResult SendRequest<TRequestPacketType>(TRequestPacketType payload, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
where TRequestPacketType : PacketPayload, IRequestPayload
public NetworkMessage.SendResult SendRequest<TRequestPacket>(TRequestPacket payload, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
where TRequestPacket : PacketPayload, IRequestPayload
{
throw new NotImplementedException();
}

[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
/*[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public NetworkMessage.SendResult SendRequest(PacketPayload payload, IRequestPayload requestParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
{
throw new NotImplementedException();
}
}*/

protected sealed override void OnReceiveRequest(IRequestMessage message, IMessageParameters parameters)
protected override void OnReceiveRequest(IRequestMessage message, IMessageParameters parameters)
{
//ClientPeers don't handle requests. They send them.
//If this is occuring in live production it is the result of likely packet forging.
Expand All @@ -45,22 +45,22 @@ protected virtual void OnInvalidOperationRecieved(Type packetType, IMessageParam

//We can override because we no this is invalid.
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public sealed override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IEventPayload eventParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
public override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IEventPayload eventParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
{
//TODO: Logging.
return NetworkMessage.SendResult.Invalid;
}

[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public sealed override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IResponsePayload responseParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
public override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IResponsePayload responseParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
{
//TODO: Logging.
return NetworkMessage.SendResult.Invalid;
}

[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
//We can skip checks for efficiency and send directly.
public sealed override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IRequestPayload requestParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
public override NetworkMessage.SendResult TrySendMessage(PacketPayload payload, IRequestPayload requestParameters, NetworkMessage.DeliveryMethod deliveryMethod, bool encrypt = false, byte channel = 0)
{
//TODO: Implement sending.
throw new NotImplementedException();
Expand Down
8 changes: 3 additions & 5 deletions tests/GladNet.Common.Tests/GladNet.Common.Tests.csproj
Expand Up @@ -34,10 +34,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\moq4\Source\bin\Debug\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Lidgren.Network">
<HintPath>..\..\lib\Dependency Builds\Lidgren\DLLs\Lidgren.Network.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -67,7 +63,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\GladNet.Common\GladNet.Common.csproj">
<Project>{9603bbaf-5f68-4176-a032-3e8beaf8f9e2}</Project>
Expand Down
Expand Up @@ -17,9 +17,10 @@ public static void Test_CanSend_IsRequest()
//arrange
Mock<ClientPeer> peer = new Mock<ClientPeer>();
peer.CallBase = true;
//peer.Setup

//act
bool result = peer.Object.CanSend(NetworkMessage.OperationType.Request); //peer.As<INetPeer>().Object.CanSend(NetworkMessage.OperationType.Request);
bool result = peer.Object.CanSend(NetworkMessage.OperationType.Request);

//assert
Assert.IsTrue(result);
Expand Down

0 comments on commit 463a0c5

Please sign in to comment.