public async Task LoadCharacter() { Settings.Default.SINnerUrl = "https://sinners.azurewebsites.net/"; Debug.WriteLine("Unit test initialized for: LoadCharacter()"); string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; path = Path.Combine(path, "data"); DirectoryInfo d = new DirectoryInfo(path); //Assuming Test is your Folder FileInfo[] Files = d.GetFiles("*.chum5"); //Getting Text files foreach (FileInfo file in Files) { try { Debug.WriteLine("Loading: " + file.Name); using (Character c = await MainForm.LoadCharacter(file.FullName)) { if (c == null) { continue; } Debug.WriteLine("Character loaded: " + c.Name); using (CharacterShared frmCharacterForm = c.Created ? (CharacterShared) new frmCareer(c) : new frmCreate(c)) { frmCharacterForm.MdiParent = MainForm; frmCharacterForm.WindowState = FormWindowState.Minimized; frmCharacterForm.Show(); using (ucSINnersUserControl sINnersUsercontrol = new ucSINnersUserControl()) { var ce = await sINnersUsercontrol.SetCharacterFrom(frmCharacterForm); await Utils.PostSINnerAsync(ce); await Utils.UploadChummerFileAsync(ce); } frmCharacterForm.Close(); } } } catch (Exception e) { string msg = "Exception while loading " + file.FullName + ":"; msg += Environment.NewLine + e; Debug.Write(msg); throw; } } }
public void Load3CharacterForms() { Debug.WriteLine("Unit test initialized for: Load3CharacterForms()"); frmChummerMain frmOldMainForm = Program.MainForm; Program.MainForm = MainForm; // Set program Main form to Unit test version MainForm.Show(); // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it). string strPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "TestFiles"); DirectoryInfo objPathInfo = new DirectoryInfo(strPath); //Assuming Test is your Folder FileInfo[] aobjFiles = objPathInfo.GetFiles("*.chum5"); //Getting Text files foreach (FileInfo objFileInfo in aobjFiles) { using (Character objCharacter = LoadCharacter(objFileInfo)) { try { using (CharacterShared frmCharacterForm = objCharacter.Created ? (CharacterShared) new frmCareer(objCharacter) : new frmCreate(objCharacter)) { frmCharacterForm.MdiParent = MainForm; frmCharacterForm.WindowState = FormWindowState.Minimized; frmCharacterForm.Show(); frmCharacterForm.Close(); } } 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); } } } MainForm.Close(); Program.MainForm = frmOldMainForm; }
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(); Utils.SafeSleep(true); while (frmCharacterForm.IsLoading) // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo { Utils.SafeSleep(true); } frmCharacterForm.Close(); Utils.SafeSleep(true); while (frmCharacterForm.IsLoading) // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo { Utils.SafeSleep(true); } } Utils.SafeSleep(true); } 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; }