<commit_before>﻿namespace MappyTest
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;

    using Mappy.Collections;
    using Mappy.Controllers.Tags;
    using Mappy.Data;
    using Mappy.Presentation;
    using Mappy.UI.Controls;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    [TestClass]
    public class MapCommandHandlerTest
    {
        private MapPresenter presenter;

        private Mock<IMysteryModel> model;

        private Mock<IMapView> view;

        [TestInitialize]
        public void SetUp()
        {
            this.model = new Mock<IMysteryModel>(MockBehavior.Strict);
            this.model.SetupGet(x => x.MapOpen).Returns(true);
            this.model.SetupGet(x => x.MapWidth).Returns(32);
            this.model.SetupGet(x => x.MapHeight).Returns(32);
            this.model.SetupGet(x => x.HeightmapVisible).Returns(false);
            this.model.SetupGet(x => x.BaseTile).Returns(new MapTile(32, 32));
            this.model.SetupGet(x => x.FloatingTiles).Returns(new List<Positioned<IMapTile>>());
            this.model.SetupGet(x => x.Features).Returns(new SparseGrid<Feature>(64, 64));
            this.model.Setup(x => x.GetStartPosition(It.IsAny<int>())).Returns((Point?)null);

            this.model.SetupGet(x => x.GridVisible).Returns(false);
            this.model.SetupGet(x => x.GridColor).Returns(Color.Black);
            this.model.SetupGet(x => x.GridSize).Returns(new Size(32, 32));

            this.view = new Mock<IMapView>(MockBehavior.Strict);
            this.view.SetupGet(x => x.Items).Returns(new List<ImageLayerCollection.Item>());
            this.view.SetupProperty(x => x.CanvasSize);
            this.view.SetupProperty(x => x.GridVisible);
            this.view.SetupProperty(x => x.GridColor);
            this.view.SetupProperty(x => x.GridSize);

            this.presenter = new MapPresenter(this.view.Object, this.model.Object);

            this.model.ResetCalls();
            this.view.ResetCalls();
        }

        [TestClass]
        public class SelectAtPoint : MapCommandHandlerTest
        {
            /// <summary>
            /// Tests that, when the mouse is clicked on something not selected,
            /// we attempt to select at that point.
            /// </summary>
            [TestMethod]
            public void TestSelectAtPoint()
            {
                var item = new ImageLayerCollection.Item(2, 4, 5, null);
                item.Tag = new SectionTag(3);

                this.view.Setup(x => x.IsInSelection(2, 4)).Returns(false);
                this.view.Setup(x => x.HitTest(2, 4)).Returns(item);

                this.model.Setup(x => x.SelectTile(3));

                this.presenter.MouseDown(2, 4);

                this.model.Verify(x => x.SelectTile(3), Times.Once);
            }

            /// <summary>
            /// Similar to previous test but with different coordinates.
            /// </summary>
            [TestMethod]
            public void TestSelectAtPoint2()
            {
                var item = new ImageLayerCollection.Item(3, 8, 7, null);
                item.Tag = new SectionTag(2);

                this.view.Setup(x => x.IsInSelection(3, 8)).Returns(false);
                this.view.Setup(x => x.HitTest(3, 8)).Returns(item);

                this.model.Setup(x => x.SelectTile(2));

                this.presenter.MouseDown(3, 8);

                this.model.Verify(x => x.SelectTile(2), Times.Once);
            }
        }

        [TestClass]
        public class DragTranslate : MapCommandHandlerTest
        {
            /// <summary>
            /// Tests that when the mouse is clicked down on a selection
            /// and dragged, we translate that selection.
            /// </summary><commit_msg>Add some tests and rename some<commit_after>﻿namespace MappyTest
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;

    using Mappy.Collections;
    using Mappy.Controllers.Tags;
    using Mappy.Data;
    using Mappy.Presentation;
    using Mappy.UI.Controls;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    [TestClass]
    public class MapCommandHandlerTest
    {
        private MapPresenter presenter;

        private Mock<IMysteryModel> model;

        private Mock<IMapView> view;

        [TestInitialize]
        public void SetUp()
        {
            this.model = new Mock<IMysteryModel>(MockBehavior.Strict);
            this.model.SetupGet(x => x.MapOpen).Returns(true);
            this.model.SetupGet(x => x.MapWidth).Returns(32);
            this.model.SetupGet(x => x.MapHeight).Returns(32);
            this.model.SetupGet(x => x.HeightmapVisible).Returns(false);
            this.model.SetupGet(x => x.BaseTile).Returns(new MapTile(32, 32));
            this.model.SetupGet(x => x.FloatingTiles).Returns(new List<Positioned<IMapTile>>());
            this.model.SetupGet(x => x.Features).Returns(new SparseGrid<Feature>(64, 64));
            this.model.Setup(x => x.GetStartPosition(It.IsAny<int>())).Returns((Point?)null);

            this.model.SetupGet(x => x.GridVisible).Returns(false);
            this.model.SetupGet(x => x.GridColor).Returns(Color.Black);
            this.model.SetupGet(x => x.GridSize).Returns(new Size(32, 32));

            this.view = new Mock<IMapView>(MockBehavior.Strict);
            this.view.SetupGet(x => x.Items).Returns(new List<ImageLayerCollection.Item>());
            this.view.SetupProperty(x => x.CanvasSize);
            this.view.SetupProperty(x => x.GridVisible);
            this.view.SetupProperty(x => x.GridColor);
            this.view.SetupProperty(x => x.GridSize);

            this.presenter = new MapPresenter(this.view.Object, this.model.Object);

            this.model.ResetCalls();
            this.view.ResetCalls();
        }

        [TestClass]
        public class SelectItems : MapCommandHandlerTest
        {
            /// <summary>
            /// Tests that, when the mouse is clicked on a tile
            /// that is not selected,
            /// we attempt to select the tile.
            /// </summary>
            [TestMethod]
            public void TestSelectTile()
            {
                var item = new ImageLayerCollection.Item(2, 4, 5, null);
                item.Tag = new SectionTag(3);

                this.view.Setup(x => x.IsInSelection(2, 4)).Returns(false);
                this.view.Setup(x => x.HitTest(2, 4)).Returns(item);

                this.model.Setup(x => x.SelectTile(3));

                this.presenter.MouseDown(2, 4);

                this.model.Verify(x => x.SelectTile(3), Times.Once);
            }

            /// <summary>
            /// Similar to previous test but with different coordinates.
            /// </summary>
            [TestMethod]
            public void TestSelectTile2()
            {
                var item = new ImageLayerCollection.Item(3, 8, 7, null);
                item.Tag = new SectionTag(2);

                this.view.Setup(x => x.IsInSelection(3, 8)).Returns(false);
                this.view.Setup(x => x.HitTest(3, 8)).Returns(item);

                this.model.Setup(x => x.SelectTile(2));

                this.presenter.MouseDown(3, 8);

                this.model.Verify(x => x.SelectTile(2), Times.Once);
            }

            /// <summary>
            /// Tests that, when the mouse is clicked on a feature
            /// that is not selected,
            /// we attempt to select the feature.
            /// </summary>
            [TestMethod]
            public void TestSelectFeature()
            {
                var item = new ImageLayerCollection.Item(2, 4, 5, null);
                item.Tag = new FeatureTag(new GridCoordinates(6, 7));

                this.view.Setup(x => x.IsInSelection(2, 4)).Returns(false);
                this.view.Setup(x => x.HitTest(2, 4)).Returns(item);

                this.model.Setup(x => x.SelectFeature(new GridCoordinates(6, 7)));

                this.presenter.MouseDown(2, 4);

                this.model.Verify(x => x.SelectFeature(new GridCoordinates(6, 7)), Times.Once);
            }

            /// <summary>
            /// Tests that, when the mouse is clicked on a start position
            /// that is not selected,
            /// we attempt to select the start position.
            /// </summary>
            [TestMethod]
            public void TestSelectStartPosition()
            {
                var item = new ImageLayerCollection.Item(2, 4, 5, null);
                item.Tag = new StartPositionTag(2);

                this.view.Setup(x => x.IsInSelection(2, 4)).Returns(false);
                this.view.Setup(x => x.HitTest(2, 4)).Returns(item);

                this.model.Setup(x => x.SelectStartPosition(2));

                this.presenter.MouseDown(2, 4);

                this.model.Verify(x => x.SelectStartPosition(2), Times.Once);
            }
        }

        [TestClass]
        public class DragTranslate : MapCommandHandlerTest
        {
            /// <summary>
            /// Tests that when the mouse is clicked down on a selection
            /// and dragged, we translate that selection.
            /// </summary>
{'fraction_non_alphanumeric': 0.1280206207711309, 'fraction_numerical': 0.011706583610782945, 'mean_word_length': 1.8132930513595167, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2867347', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2557, 'n_words': 520}