test for sync list using interface (#1767)

This commit is contained in:
James Frowen 2020-04-23 20:51:33 +01:00 committed by GitHub
parent a2eb666f15
commit d4f834ac08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 0 deletions

View File

@ -158,6 +158,23 @@ public void SyncListGenericStructWithCustomMethods()
Assert.That(weaverErrors, Is.Empty); Assert.That(weaverErrors, Is.Empty);
} }
[Test]
public void SyncListErrorForInterface()
{
Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
string weaverError = @"Mirror\.Weaver error:";
string type = @"MirrorTest\.MyInterfaceList";
string errorMessage = @"cannot have item of type MirrorTest\.MyInterface\. Use a type supported by mirror instead";
Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}"));
}
[Test]
public void SyncListInterfaceWithCustomMethods()
{
Assert.That(CompilationFinishedHook.WeaveFailed, Is.False);
Assert.That(weaverErrors, Is.Empty);
}
[Test] [Test]
public void SyncListErrorWhenUsingGenericListInNetworkBehaviour() public void SyncListErrorWhenUsingGenericListInNetworkBehaviour()
{ {

View File

@ -0,0 +1,15 @@
using UnityEngine;
using Mirror;
namespace MirrorTest
{
class SyncListErrorForInterface : NetworkBehaviour
{
MyInterfaceList Foo;
}
interface MyInterface
{
int someNumber { get; set; }
}
class MyInterfaceList : SyncList<MyInterface> { }
}

View File

@ -0,0 +1,32 @@
using UnityEngine;
using Mirror;
namespace MirrorTest
{
class SyncListInterfaceWithCustomMethods : NetworkBehaviour
{
MyInterfaceList Foo;
}
interface IMyInterface
{
int someNumber { get; set; }
}
class MyUser : IMyInterface
{
public int someNumber { get; set; }
}
class MyInterfaceList : SyncList<IMyInterface>
{
protected override void SerializeItem(NetworkWriter writer, IMyInterface item)
{
writer.WriteInt32(item.someNumber);
}
protected override IMyInterface DeserializeItem(NetworkReader reader)
{
return new MyUser { someNumber = reader.ReadInt32() };
}
}
}