using Chernobyl.Mathematics.Geometry; using NUnit.Framework; using System; namespace Chernobyl.Mathematics.Collision { [TestFixture, Description("A TestFixture that tests the " + "CollisionMediator class.")] public class CollisionMediatorTests { [Test, Description("Ensures the CollisionMediator(IExtendedCollidable) " + "constructor throws an ArgumentNullException if the parameter passed to it is null.")] public void ConstructorArgumentNullException() { Assert.Throws(() => new CollisionMediator(null)); } [Test, Description("A test that ensures that OnCollisionStarted and " + "OnCollisionEnded events are not sent to the IExtendedCollidable " + "that is used for the CollisionMediator's implementation")] public void CollidableImplementorDoesNotInvokeEvents() { Rectangle collidableImplementor = new Rectangle(0, 0, 100, 100); CollisionMediator collisionMediator = new CollisionMediator(collidableImplementor); collidableImplementor.OnCollisionStarted += (sender, e) => Assert.Fail("The implementing collidable should not have had its OnCollisionStarted event invoked."); collidableImplementor.OnCollisionEnded += (sender, e) => Assert.Fail("The implementing collidable should not have had its OnCollisionEnded event invoked."); Point2D collider = new Point2D(50, 50); collisionMediator.HandleCollisionStarted(collider); collisionMediator.HandleCollisionEnded(collider); Assert.Pass("The implementing collidable did not have its OnCollisionStarted event invoked."); } [Test, Description("A test that ensures that the OnCollisionStarted " + "event is properly invoked on the CollisionMediator " + "when the IExtendedCollidable used for that " + "CollisionMediator's implementation has it's " + "OnCollisionStarted event invoked.")] public void CollidableMediatorPassesImplementorsOnCollisionStartedEventForward() { Rectangle collidableImplementor = new Rectangle(0, 0, 100, 100); CollisionMediator collisionMediator = new CollisionMediator(collidableImplementor); collisionMediator.OnCollisionStarted += (sender, e) => Assert.Pass("The CollisionMediator had its OnCollisionStarted event invoked."); Point2D collider = new Point2D(50, 50); collidableImplementor.HandleCollisionStarted(collider); Assert.Fail("The CollisionMediator did not have its OnCollisionStarted event invoked."); } [Test, Description("A test that ensures that the OnCollisionEnded " + "event is properly invoked on the CollisionMediator " + "when the IExtendedCollidable used for that " + "CollisionMediator's implementation has it's " + "OnCollisionEnded event invoked.")] public void CollidableMediatorPassesImplementorsOnCollisionEndedEventForward() { Rectangle collidableImplementor = new Rectangle(0, 0, 100, 100); CollisionMediator collisionMediator = new CollisionMediator(collidableImplementor); collisionMediator.OnCollisionEnded += (sender, e) => Assert.Pass("The CollisionMediator had its OnCollisionEnded event invoked."); Point2D collider = new Point2D(50, 50); collidableImplementor.HandleCollisionEnded(collider); Assert.Fail("The CollisionMediator did not have its OnCollisionEnded event invoked."); } [TestFixture, Description("Tests the IShape and ITransform portion " + "of the CollisionMediator.")] public class CollisionMediatorShapeTests : RectangleTests.RectangleShapeTests { protected override IShape CreateShape() { return new CollisionMediator((Rectangle)base.CreateShape()); } } [TestFixture, Description("Tests the IExtendedCollidable " + "portion of the Rectangle.")] public class CollisionMediatorExtendedCollidableTests : RectangleTests.RectangleExtendedCollidableTests { protected override IExtendedCollidable CreateExtendedCollidable() { return new CollisionMediator(base.CreateExtendedCollidable()); } } } }