diff --git a/TrueCraft.Core.Test/Logic/BlockProviderTest.cs b/TrueCraft.Core.Test/Logic/BlockProviderTest.cs new file mode 100644 index 0000000..9dbb74f --- /dev/null +++ b/TrueCraft.Core.Test/Logic/BlockProviderTest.cs @@ -0,0 +1,73 @@ +using System; +using NUnit.Framework; +using Moq; +using Moq.Protected; +using TrueCraft.API.Logic; +using TrueCraft.Core.Logic; +using TrueCraft.API; +using TrueCraft.API.World; +using TrueCraft.API.Server; +using TrueCraft.API.Networking; +using TrueCraft.API.Entities; +using TrueCraft.Core.Entities; + +namespace TrueCraft.Core.Test.Logic +{ + [TestFixture] + public class BlockProviderTest + { + public Mock World { get; set; } + public Mock Server { get; set; } + public Mock EntityManager { get; set; } + public Mock User { get; set; } + + [TestFixtureSetUp] + public void SetUp() + { + World = new Mock(); + Server = new Mock(); + EntityManager = new Mock(); + User = new Mock(); + + User.SetupGet(u => u.World).Returns(World.Object); + User.SetupGet(u => u.Server).Returns(Server.Object); + + World.Setup(w => w.SetBlockID(It.IsAny(), It.IsAny())); + + Server.Setup(s => s.GetEntityManagerForWorld(It.IsAny())) + .Returns(w => EntityManager.Object); + + EntityManager.Setup(m => m.SpawnEntity(It.IsAny())); + } + + protected void ResetMocks() + { + World.ResetCalls(); + Server.ResetCalls(); + EntityManager.ResetCalls(); + User.ResetCalls(); + } + + [Test] + public void TestBlockMined() + { + ResetMocks(); + var blockProvider = new Mock { CallBase = true }; + var descriptor = new BlockDescriptor + { + ID = 10, + Coordinates = Coordinates3D.Zero + }; + + blockProvider.Object.BlockMined(descriptor, BlockFace.PositiveY, World.Object, User.Object); + EntityManager.Verify(m => m.SpawnEntity(It.Is(e => e.Item.ID == 10))); + World.Verify(w => w.SetBlockID(Coordinates3D.Zero, 0)); + + blockProvider.Protected().Setup("GetDrop", ItExpr.IsAny()) + .Returns(() => new[] { new ItemStack(12) }); + blockProvider.Object.BlockMined(descriptor, BlockFace.PositiveY, World.Object, User.Object); + EntityManager.Verify(m => m.SpawnEntity(It.Is(e => e.Item.ID == 12))); + World.Verify(w => w.SetBlockID(Coordinates3D.Zero, 0)); + } + } +} \ No newline at end of file diff --git a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj index d3b18da..48481ac 100644 --- a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj +++ b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj @@ -81,6 +81,7 @@ +