コード例 #1
0
        public void Test05_LoadCharacterForms()
        {
            Debug.WriteLine("Unit test initialized for: Test05_LoadCharacterForms()");
            ChummerMainForm frmOldMainForm = Program.MainForm;
            ChummerMainForm frmTestForm    = null;

            // Try-finally pattern necessary in order prevent weird exceptions from disposal of MdiChildren
            try
            {
                frmTestForm = new ChummerMainForm(true)
                {
                    WindowState   = FormWindowState.Minimized,
                    ShowInTaskbar =
                        false                          // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used, but that forces the test to be interactive)
                };
                Program.MainForm = frmTestForm;        // Set program Main form to Unit test version
                frmTestForm.Show();                    // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it).
                while (!frmTestForm.IsFinishedLoading) // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo
                {
                    Utils.SafeSleep(true);
                }
                foreach (FileInfo objFileInfo in TestFiles)
                {
                    using (Character objCharacter = LoadCharacter(objFileInfo))
                    {
                        try
                        {
                            using (CharacterShared frmCharacterForm = objCharacter.Created
                                ? (CharacterShared) new CharacterCareer(objCharacter)
                                : new CharacterCreate(objCharacter))
                            {
                                frmCharacterForm.MdiParent     = frmTestForm;
                                frmCharacterForm.ShowInTaskbar = false;
                                frmCharacterForm.WindowState   = FormWindowState.Minimized;
                                frmCharacterForm.Show();
                            }
                        }
                        catch (Exception e)
                        {
                            string strErrorMessage = "Exception while loading form for " + objFileInfo.FullName + ":";
                            strErrorMessage += Environment.NewLine + e;
                            Debug.WriteLine(strErrorMessage);
                            Console.WriteLine(strErrorMessage);
                            Assert.Fail(strErrorMessage);
                        }
                    }
                }
                frmTestForm.Close();
            }
            finally
            {
                frmTestForm?.Dispose();
            }
            Program.MainForm = frmOldMainForm;
        }
コード例 #2
0
ファイル: ChummerTest.cs プロジェクト: Stexinator/chummer5a
        public void Test01_BasicStartup()
        {
            Debug.WriteLine("Unit test initialized for: Test01_BasicStartup()");
            ChummerMainForm frmOldMainForm = Program.MainForm;
            ChummerMainForm frmTestForm    = null;

            // Try-finally pattern necessary in order prevent weird exceptions from disposal of MdiChildren
            try
            {
                frmTestForm = new ChummerMainForm(true, true)
                {
                    ShowInTaskbar =
                        false                   // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used, but that forces the test to be interactve)
                };
                Program.MainForm = frmTestForm; // Set program Main form to Unit test version
                frmTestForm.Show();             // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it).
#if DEBUG
                frmTestForm.SendToBack();
#endif
                while
                (!frmTestForm
                 .IsFinishedLoading)        // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo
                {
                    Utils.SafeSleep();
                }

                frmTestForm.Close();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                frmTestForm?.Dispose();
            }
            Program.MainForm = frmOldMainForm;
        }