using ActionGame.UserInterface.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;


namespace ActionGame.Tests.UserInterfaceTests.Core
{
    [TestClass]
    public class ResolutionTests
    {
        [TestMethod]
        public void Resolution_BasicInitialization()
        {
            GraphicsDeviceManager gdm = null;
            IResolution resolution = new Resolution(gdm)
            {
                ActualWidth = 640,
                ActualHeight = 480,
                GameWidth = 640,
                GameHeight = 480
            };

            Assert.AreEqual(resolution.ActualWidth, 640);
            Assert.AreEqual(resolution.ActualHeight, 480);
            Assert.AreEqual(resolution.GameWidth, 640);
            Assert.AreEqual(resolution.GameHeight, 480);

            Assert.AreEqual(resolution.InvertMatrix.ToString(), "{M11:0 M12:0 M13:0 M14:0} {M21:0 M22:0 M23:0 M24:0} {M31:0 M32:0 M33:0 M34:0} {M41:0 M42:0 M43:0 M44:0}");
            Assert.AreEqual(resolution.TransformationMatrix.ToString(), "{M11:0 M12:0 M13:0 M14:0} {M21:0 M22:0 M23:0 M24:0} {M31:0 M32:0 M33:0 M34:0} {M41:0 M42:0 M43:0 M44:0}");
        }


        [TestMethod]
        public void Resolution_MatrixCreation()
        {
            Game game = new Game();
            GraphicsDeviceManager gdm = new GraphicsDeviceManager(game);
            
            IResolution resolution = new Resolution(gdm)
            {
                ActualWidth = 800,
                ActualHeight = 600,
                GameWidth = 640,
                GameHeight = 480
            };

            resolution.Update();

            Assert.AreEqual(resolution.InvertMatrix.ToString(), "{M11:0.8 M12:0 M13:0 M14:0} {M21:0 M22:0.8 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1}");
            Assert.AreEqual(resolution.TransformationMatrix.ToString(), "{M11:1.25 M12:0 M13:0 M14:0} {M21:0 M22:1.25 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1}");
        }


        [TestMethod]
        public void Resolution_LetterBoxedOnSides()
        {
            Game game = new Game();
            GraphicsDeviceManager gdm = new GraphicsDeviceManager(game);

            IResolution resolution = new Resolution(gdm)
            {
                ActualWidth = 800,
                ActualHeight = 600,
                GameWidth = 700,
                GameHeight = 600
            };

            resolution.Update();

            Assert.IsTrue(resolution.Viewport.X == (800 - 700) / 2);
            Assert.IsTrue(resolution.Viewport.Y == 0);
        }


        [TestMethod]
        public void Resolution_LetterBoxedOnTopBottom()
        {
            Game game = new Game();
            GraphicsDeviceManager gdm = new GraphicsDeviceManager(game);

            IResolution resolution = new Resolution(gdm)
            {
                ActualWidth = 800,
                ActualHeight = 600,
                GameWidth = 800,
                GameHeight = 500
            };

            resolution.Update();

            Assert.IsTrue(resolution.Viewport.X == 0);
            Assert.IsTrue(resolution.Viewport.Y == (600 - 500) / 2);
        }


    }
}
