public void NewUser()
        {
            var session = new SessionBuilder()
                          .WithAddOn(new GHAddOn())
                          .WithAddOn(new GHCAddOn())
                          .WithXmlFile(@"GHCTests\Integration\ActionButtonTemplate.xml")
                          .WithXmlFile(@"GHCTests\Integration\Cooldown.xml")
                          .WithIgnoredXmlTemplate("NumberFontNormalSmallGray")
                          .WithIgnoredXmlTemplate("NumberFontNormal")
                          .WithIgnoredXmlTemplate("GameFontHighlightSmallOutline")
                          .Build();

            var optionsContainer = session.FrameProvider.CreateFrame(BlizzardApi.WidgetEnums.FrameType.Frame, "InterfaceOptionsFramePanelContainer") as IFrame;

            optionsContainer.SetWidth(400);
            optionsContainer.SetHeight(500);


            session.RunStartup();

            var ghTestable = new GHAddOnTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface/ICONS/Ability_Stealth");

            session.Actor.VerifyVisible("Interface/ICONS/INV_Misc_Bag_11", true);
        }
        public void QuickButtonPositionOverMultipleSessions()
        {
            var cursorApiMock   = new CursorApiMock();
            var keyboardKeyMock = new KeyboardKeyApiMock();
            var session         = new SessionBuilder()
                                  .WithScreenDimensions(800, 600)
                                  .WithApiMock(cursorApiMock)
                                  .WithApiMock(keyboardKeyMock)
                                  .WithGH()
                                  .Build();

            session.RunStartup();

            var ghTestable = new GHAddOnTestable(session);

            var buttonLocation = ghTestable.GetMainButtonLocation();
            var distToExpected = GetDist(buttonLocation.Item1, buttonLocation.Item2, 600, 450);

            Assert.IsTrue(distToExpected < 30, $"The main button was not located as expected. Distance from actual to expected: {distToExpected}.");

            ghTestable.MouseOverMainButton();
            cursorApiMock.SetPosition(600, 450);
            keyboardKeyMock.ShiftKeyDown = true;
            ghTestable.StartDragMainButton();
            session.RunUpdate();
            cursorApiMock.SetPosition(550, 300);
            session.RunUpdate();
            cursorApiMock.SetPosition(500, 100);
            session.RunUpdate();
            ghTestable.StopDragMainButton();
            keyboardKeyMock.ShiftKeyDown = false;

            var buttonLocationAfterMove = ghTestable.GetMainButtonLocation();
            var distToExpectedAfterMove = GetDist(buttonLocationAfterMove.Item1, buttonLocationAfterMove.Item2, 500, 100);

            Assert.IsTrue(distToExpectedAfterMove < 30, $"The main button was not located as expected. Distance from actual to expected: {distToExpectedAfterMove}.");

            var savedVars = session.GetSavedVariables();

            var cursorApiMock2 = new CursorApiMock();
            var session2       = new SessionBuilder()
                                 .WithScreenDimensions(800, 600)
                                 .WithApiMock(cursorApiMock2)
                                 .WithSavedVariables(savedVars)
                                 .WithGH()
                                 .Build();

            var ghTestable2 = new GHAddOnTestable(session2);

            var buttonLocation2 = ghTestable2.GetMainButtonLocation();
            var distToExpected2 = GetDist(buttonLocation2.Item1, buttonLocation2.Item2, 500, 100);

            Assert.IsTrue(distToExpected2 < 30, $"The main button was not located as expected. Distance from actual to expected: {distToExpected2}.");
        }
        public void ProfileWithAdditionalFieldsTest()
        {
            var session = new SessionBuilder()
                          .WithPlayerName("Tester")
                          .WithPlayerClass("Priest")
                          .WithPlayerGuid("g1")
                          .WithPlayerRace("Human")
                          .WithPlayerSex(2)
                          .WithGH()
                          .WithGHF()
                          .Build();

            session.RunStartup();

            var ghTestable   = new GHAddOnTestable(session);
            var menuTestable = new GHMenuTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable.SelectMenu("GHF_CharacterMenu");

            session.Actor.Click("Add Additional Fields");
            session.Actor.Click("Title");

            menuTestable.VerifyLabelVisible("Title:");
            menuTestable.SetObjectValue("Title:", "Cleric");

            session.Actor.Click("Add Additional Fields");
            session.Actor.Click("Age");

            menuTestable.VerifyLabelVisible("Age:");
            menuTestable.SetObjectValue("Age:", "52");

            menuTestable.CloseMenu();

            var savedVars = session.GetSavedVariables();

            var savedProfiles    = (NativeLuaTable)savedVars[ModelProvider.SavedAccountProfiles];
            var additionalFields = TestUtil.GetTableValue <Profile>(savedProfiles, "Tester", "obj").AdditionalFields;

            Assert.AreEqual("Cleric", additionalFields["title"]);
            Assert.AreEqual("52", additionalFields["age"]);
        }
        public void RenderPageWithSeveralLines()
        {
            this.session = new SessionBuilder()
                           .WithGH()
                           .WithAddOn(new GHDAddOn())
                           .WithIgnoredXmlTemplate("GHM_ScrollFrameTemplate")
                           .WithFrameWrapper("GHM_ScrollFrameTemplate", GHM_ScrollFrameTemplateWrapper.Init)
                           .Build();

            this.session.RunStartup();

            var ghTestable = new GHAddOnTestable(this.session);

            ghTestable.MouseOverMainButton();
            this.initialFontStrings = this.session.Util.GetVisibleLayeredRegions().OfType <IFontString>().ToArray();
            ghTestable.ClickSubButton("Interface\\Icons\\INV_Misc_Book_08");

            this.ExpectStrings();

            var editBox = GlobalFrames.CurrentFocus;

            Assert.IsNotNull(editBox);

            var input = new KeyboardInputSimulator();

            input.TypeString("A");
            this.ExpectStrings("A");

            input.TypeString(" test");
            this.ExpectStrings("A test");

            input.PressLeftArrow(4);
            input.TypeString("short ");
            this.ExpectStrings("A short test");

            input.PressEnd();
            input.TypeString(". Adding a long sentance with the purpose of spilling over into the next line of text.");
            this.ExpectStrings("A short test. Adding a long sentance with the purpose of spilling", "over into the next line of text.");

            input.PressUpArrow();
            input.TypeString("1");
            this.ExpectStrings("A short test. Adding a long1 sentance with the purpose of", "spilling over into the next line of text.");
        }
        public void MultiCharProfileLifecycle()
        {
            var session = new SessionBuilder()
                          .WithPlayerName("Tester")
                          .WithPlayerClass("Mage")
                          .WithPlayerGuid("g1")
                          .WithPlayerRace("Human")
                          .WithPlayerSex(2)
                          .WithGH()
                          .WithGHF()
                          .Build();

            session.RunStartup();

            var ghTestable   = new GHAddOnTestable(session);
            var menuTestable = new GHMenuTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable.SelectMenu("GHF_CharacterMenu");
            Assert.AreEqual("Tester", menuTestable.GetObjectValue("First Name:"));
            Assert.AreEqual("", menuTestable.GetObjectValue("Middle Name(s):"));
            Assert.AreEqual("", menuTestable.GetObjectValue("Last Name:"));

            menuTestable.SetObjectValue("First Name:", "Testperson");
            menuTestable.SetObjectValue("Middle Name(s):", "von der");
            menuTestable.SetObjectValue("Last Name:", "Testa");

            menuTestable.CloseMenu();

            var savedVars = session.GetSavedVariables();

            var session2 = new SessionBuilder()
                           .WithPlayerName("Pilus")
                           .WithPlayerClass("Warrior")
                           .WithPlayerGuid("g2")
                           .WithPlayerRace("Human")
                           .WithPlayerSex(2)
                           .WithGH()
                           .WithGHF()
                           .WithSavedVariables(savedVars)
                           .Build();

            session2.RunStartup();

            var ghTestable2   = new GHAddOnTestable(session2);
            var menuTestable2 = new GHMenuTestable(session2);

            ghTestable2.MouseOverMainButton();
            ghTestable2.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable2.SelectMenu("GHF_CharacterMenu");
            Assert.AreEqual("Pilus", menuTestable2.GetObjectValue("First Name:"));
            Assert.AreEqual("", menuTestable2.GetObjectValue("Middle Name(s):"));
            Assert.AreEqual("", menuTestable2.GetObjectValue("Last Name:"));

            session2.Actor.Click("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up");
            session2.Actor.VerifyVisible("Testperson von der Testa");
            session2.Actor.VerifyVisible("Interface\\Icons\\INV_Staff_13"); // Mage
            session2.Actor.VerifyVisible("Pilus");
            session2.Actor.VerifyVisible("Interface\\Icons\\INV_Sword_27"); // Warrior
        }
        public void SimpleProfileLifecycle()
        {
            var session = new SessionBuilder()
                          .WithPlayerName("Tester")
                          .WithPlayerClass("Druid")
                          .WithPlayerGuid("g1")
                          .WithPlayerRace("Human")
                          .WithPlayerSex(2)
                          .WithGH()
                          .WithGHF()
                          .Build();

            session.RunStartup();

            var ghTestable   = new GHAddOnTestable(session);
            var menuTestable = new GHMenuTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable.SelectMenu("GHF_CharacterMenu");
            Assert.AreEqual("Tester", menuTestable.GetObjectValue("First Name:"));
            Assert.AreEqual("", menuTestable.GetObjectValue("Middle Name(s):"));
            Assert.AreEqual("", menuTestable.GetObjectValue("Last Name:"));
            Assert.AreEqual("", menuTestable.GetObjectValue("Background:"));

            menuTestable.SetObjectValue("First Name:", "Testperson");
            menuTestable.SetObjectValue("Middle Name(s):", "von der");
            menuTestable.SetObjectValue("Last Name:", "Testa");
            menuTestable.SetObjectValue("Appearance:", "Looks");
            menuTestable.SetObjectValue("Background:", "Background story.");

            menuTestable.CloseMenu();

            var savedVars = session.GetSavedVariables();

            var session2 = new SessionBuilder()
                           .WithPlayerName("Tester")
                           .WithPlayerClass("Druid")
                           .WithPlayerGuid("g1")
                           .WithPlayerRace("Human")
                           .WithPlayerSex(2)
                           .WithGH()
                           .WithGHF()
                           .WithSavedVariables(savedVars)
                           .Build();

            session2.RunStartup();

            var ghTestable2   = new GHAddOnTestable(session2);
            var menuTestable2 = new GHMenuTestable(session2);

            ghTestable2.MouseOverMainButton();
            ghTestable2.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable2.SelectMenu("GHF_CharacterMenu");
            Assert.AreEqual("Testperson", menuTestable2.GetObjectValue("First Name:"));
            Assert.AreEqual("von der", menuTestable2.GetObjectValue("Middle Name(s):"));
            Assert.AreEqual("Testa", menuTestable2.GetObjectValue("Last Name:"));
            Assert.AreEqual("Looks", menuTestable2.GetObjectValue("Appearance:"));
            Assert.AreEqual("Background story.", menuTestable2.GetObjectValue("Background:"));
        }
        public void VerifyMspPublishing()
        {
            var mspMock = new Mock <ILibMSPWrapper>();

            var session = new SessionBuilder()
                          .WithPlayerName("Tester")
                          .WithPlayerClass("Warrior")
                          .WithPlayerGuid("g1")
                          .WithPlayerRace("Human")
                          .WithPlayerSex(2)
                          .WithGH()
                          .WithGHF(mspMock)
                          .Build();


            var fieldsMock = new MspFieldsMock();

            mspMock.Setup(m => m.GetEmptyFieldsObj()).Returns(fieldsMock);

            session.RunStartup();

            mspMock.Verify(m => m.SetMy(It.IsAny <IMSPFields>()), Times.Once);
            mspMock.Verify(m => m.SetMy(It.Is <IMSPFields>(f => f == fieldsMock)), Times.Once);
            mspMock.Verify(m => m.Update(), Times.Once);

            var expectedValues = new Dictionary <string, string>()
            {
                { "VP", "1" },
                { "VA", "GH/3.0.1" },
                { "NA", "Tester" },
                { "GC", "WARRIOR" },
                { "GR", "Human" },
                { "GS", "2" },
                { "GU", "g1" },
                { "DE", null },
            };

            Assert.AreEqual(expectedValues.Count, fieldsMock.Count);

            foreach (var expected in expectedValues)
            {
                Assert.IsTrue(fieldsMock.ContainsKey(expected.Key));
                Assert.AreEqual(expected.Value, fieldsMock[expected.Key]);
            }


            var ghTestable   = new GHAddOnTestable(session);
            var menuTestable = new GHMenuTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface\\Icons\\Spell_Misc_EmotionHappy");

            menuTestable.SelectMenu("GHF_CharacterMenu");

            menuTestable.SetObjectValue("First Name:", "Testperson");
            menuTestable.SetObjectValue("Middle Name(s):", "von der");
            menuTestable.SetObjectValue("Last Name:", "Testa");
            menuTestable.SetObjectValue("Appearance:", "Looks");
            menuTestable.SetObjectValue("Background:", "Background story.");

            menuTestable.CloseMenu();

            expectedValues["NA"] = "Testperson von der Testa";
            expectedValues["DE"] = "Looks";

            Assert.AreEqual(expectedValues.Count, fieldsMock.Count);

            foreach (var expected in expectedValues)
            {
                Assert.IsTrue(fieldsMock.ContainsKey(expected.Key));
                Assert.AreEqual(expected.Value, fieldsMock[expected.Key]);
            }
        }