-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better error for Command, ClientRpc and TargetRpc marked as abst…
…ract (#1947) * weaver test for virtual and abstract commands * adding error for abstract methods * adding base class for command tests and renaming file * adding tests for virutal commands * renaming classes to make more sense * removing whitespace * adding tests for Client Target Rpc too * fixing compile error * fixing message and typo * removing line * renaming namespace and base class to be used by Rpc * tests for calling Rpc * tests for virtual rpc * fixing typo
- Loading branch information
1 parent
cace9ab
commit 62257d8
Showing
31 changed files
with
761 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mirror.Tests.RemoteAttrributeTest | ||
{ | ||
class VirtualClientRpc : NetworkBehaviour | ||
{ | ||
public event Action<int> onVirtualSendInt; | ||
|
||
[ClientRpc] | ||
public virtual void RpcSendInt(int someInt) | ||
{ | ||
onVirtualSendInt?.Invoke(someInt); | ||
} | ||
} | ||
|
||
class VirtualOverrideClientRpc : VirtualClientRpc | ||
{ | ||
public event Action<int> onOverrideSendInt; | ||
|
||
[ClientRpc] | ||
public override void RpcSendInt(int someInt) | ||
{ | ||
onOverrideSendInt?.Invoke(someInt); | ||
} | ||
} | ||
|
||
public class ClientRpcOverrideTest : RemoteTestBase | ||
{ | ||
[Test] | ||
public void VirtualRpcIsCalled() | ||
{ | ||
VirtualClientRpc hostBehaviour = CreateHostObject<VirtualClientRpc>(true); | ||
|
||
const int someInt = 20; | ||
|
||
int virtualCallCount = 0; | ||
hostBehaviour.onVirtualSendInt += incomingInt => | ||
{ | ||
virtualCallCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
|
||
hostBehaviour.RpcSendInt(someInt); | ||
ProcessMessages(); | ||
Assert.That(virtualCallCount, Is.EqualTo(1)); | ||
} | ||
|
||
|
||
[Test] | ||
public void OverrideVirtualRpcIsCalled() | ||
{ | ||
VirtualOverrideClientRpc hostBehaviour = CreateHostObject<VirtualOverrideClientRpc>(true); | ||
|
||
const int someInt = 20; | ||
|
||
int virtualCallCount = 0; | ||
int overrideCallCount = 0; | ||
hostBehaviour.onVirtualSendInt += incomingInt => | ||
{ | ||
virtualCallCount++; | ||
}; | ||
hostBehaviour.onOverrideSendInt += incomingInt => | ||
{ | ||
overrideCallCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
|
||
hostBehaviour.RpcSendInt(someInt); | ||
ProcessMessages(); | ||
Assert.That(virtualCallCount, Is.EqualTo(0)); | ||
Assert.That(overrideCallCount, Is.EqualTo(1)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mirror.Tests.RemoteAttrributeTest | ||
{ | ||
class ClientRpcBehaviour : NetworkBehaviour | ||
{ | ||
public event Action<int> onSendInt; | ||
|
||
[ClientRpc] | ||
public void RpcSendInt(int someInt) | ||
{ | ||
onSendInt?.Invoke(someInt); | ||
} | ||
} | ||
|
||
public class ClientRpcTest : RemoteTestBase | ||
{ | ||
[Test] | ||
public void RpcIsCalled() | ||
{ | ||
ClientRpcBehaviour hostBehaviour = CreateHostObject<ClientRpcBehaviour>(true); | ||
|
||
const int someInt = 20; | ||
|
||
int callCount = 0; | ||
hostBehaviour.onSendInt += incomingInt => | ||
{ | ||
callCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
hostBehaviour.RpcSendInt(someInt); | ||
ProcessMessages(); | ||
Assert.That(callCount, Is.EqualTo(1)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mirror.Tests.RemoteAttrributeTest | ||
{ | ||
class VirtualCommand : NetworkBehaviour | ||
{ | ||
public event Action<int> onVirtualSendInt; | ||
|
||
[Command] | ||
public virtual void CmdSendInt(int someInt) | ||
{ | ||
onVirtualSendInt?.Invoke(someInt); | ||
} | ||
} | ||
|
||
class VirtualOverrideCommand : VirtualCommand | ||
{ | ||
public event Action<int> onOverrideSendInt; | ||
|
||
[Command] | ||
public override void CmdSendInt(int someInt) | ||
{ | ||
onOverrideSendInt?.Invoke(someInt); | ||
} | ||
} | ||
|
||
public class CommandOverrideTest : RemoteTestBase | ||
{ | ||
[Test] | ||
public void VirtualCommandIsCalled() | ||
{ | ||
VirtualCommand hostBehaviour = CreateHostObject<VirtualCommand>(true); | ||
|
||
const int someInt = 20; | ||
|
||
int virtualCallCount = 0; | ||
hostBehaviour.onVirtualSendInt += incomingInt => | ||
{ | ||
virtualCallCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
|
||
hostBehaviour.CmdSendInt(someInt); | ||
ProcessMessages(); | ||
Assert.That(virtualCallCount, Is.EqualTo(1)); | ||
} | ||
|
||
|
||
[Test] | ||
public void OverrideVirtualCommandIsCalled() | ||
{ | ||
VirtualOverrideCommand hostBehaviour = CreateHostObject<VirtualOverrideCommand>(true); | ||
|
||
const int someInt = 20; | ||
|
||
int virtualCallCount = 0; | ||
int overrideCallCount = 0; | ||
hostBehaviour.onVirtualSendInt += incomingInt => | ||
{ | ||
virtualCallCount++; | ||
}; | ||
hostBehaviour.onOverrideSendInt += incomingInt => | ||
{ | ||
overrideCallCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
|
||
hostBehaviour.CmdSendInt(someInt); | ||
ProcessMessages(); | ||
Assert.That(virtualCallCount, Is.EqualTo(0)); | ||
Assert.That(overrideCallCount, Is.EqualTo(1)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.