Add test for block support

This commit is contained in:
Drew DeVault 2015-06-06 22:19:36 -06:00
parent ccd972e6ac
commit c2ca8914ca

View File

@ -10,6 +10,7 @@ using TrueCraft.API.Server;
using TrueCraft.API.Networking;
using TrueCraft.API.Entities;
using TrueCraft.Core.Entities;
using TrueCraft.Core.TerrainGen;
namespace TrueCraft.Core.Test.Logic
{
@ -20,6 +21,7 @@ namespace TrueCraft.Core.Test.Logic
public Mock<IMultiplayerServer> Server { get; set; }
public Mock<IEntityManager> EntityManager { get; set; }
public Mock<IRemoteClient> User { get; set; }
public Mock<IBlockRepository> BlockRepository { get; set; }
[TestFixtureSetUp]
public void SetUp()
@ -28,6 +30,7 @@ namespace TrueCraft.Core.Test.Logic
Server = new Mock<IMultiplayerServer>();
EntityManager = new Mock<IEntityManager>();
User = new Mock<IRemoteClient>();
BlockRepository = new Mock<IBlockRepository>();
User.SetupGet(u => u.World).Returns(World.Object);
User.SetupGet(u => u.Server).Returns(Server.Object);
@ -36,6 +39,7 @@ namespace TrueCraft.Core.Test.Logic
Server.Setup(s => s.GetEntityManagerForWorld(It.IsAny<IWorld>()))
.Returns<IWorld>(w => EntityManager.Object);
Server.SetupGet(s => s.BlockRepository).Returns(BlockRepository.Object);
EntityManager.Setup(m => m.SpawnEntity(It.IsAny<IEntity>()));
}
@ -69,5 +73,36 @@ namespace TrueCraft.Core.Test.Logic
EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 12)));
World.Verify(w => w.SetBlockID(Coordinates3D.Zero, 0));
}
[Test]
public void TestSupport()
{
// We need an actual world for this
var world = new TrueCraft.Core.World.World("test", new FlatlandGenerator());
world.SetBlockID(Coordinates3D.Zero, 1);
world.SetBlockID(Coordinates3D.OneY, 2);
var blockProvider = new Mock<BlockProvider> { CallBase = true };
var updated = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Up };
var source = new BlockDescriptor { ID = 2, Coordinates = Coordinates3D.Right };
blockProvider.Setup(b => b.GetSupportDirection(It.IsAny<BlockDescriptor>())).Returns(Coordinates3D.Down);
var supportive = new Mock<IBlockProvider>();
supportive.SetupGet(p => p.Opaque).Returns(true);
var unsupportive = new Mock<IBlockProvider>();
unsupportive.SetupGet(p => p.Opaque).Returns(false);
BlockRepository.Setup(r => r.GetBlockProvider(It.Is<byte>(b => b == 1))).Returns(supportive.Object);
BlockRepository.Setup(r => r.GetBlockProvider(It.Is<byte>(b => b == 3))).Returns(unsupportive.Object);
blockProvider.Object.BlockUpdate(updated, source, Server.Object, world);
World.Verify(w => w.SetBlockID(Coordinates3D.OneY, 0), Times.Never);
world.SetBlockID(Coordinates3D.Zero, 3);
blockProvider.Object.BlockUpdate(updated, source, Server.Object, world);
Assert.AreEqual(0, world.GetBlockID(Coordinates3D.OneY));
EntityManager.Verify(m => m.SpawnEntity(It.Is<ItemEntity>(e => e.Item.ID == 2)));
}
}
}