public void Constructor_WithParent_CreatesNewInquiryHelper() { // Setup mocks.ReplayAll(); // Call var helper = new DialogBasedInquiryHelper(dialogParent); // Assert Assert.IsInstanceOf <IInquiryHelper>(helper); }
public void InquirePerformOptionalStep_VariousScenarios_ReturnExpectedValue(DialogResult clickedResult, OptionalStepResult expectedResult) { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); string actualQuery = null; string title = null; DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); actualQuery = tester.Text; title = tester.Title; switch (clickedResult) { case DialogResult.Yes: tester.SendCommand(MessageBoxTester.Command.Yes); break; case DialogResult.No: tester.SendCommand(MessageBoxTester.Command.No); break; case DialogResult.Cancel: tester.SendCommand(MessageBoxTester.Command.Cancel); break; } }; const string description = "A"; const string query = "B"; // Call OptionalStepResult result = helper.InquirePerformOptionalStep(description, query); // Assert Assert.AreEqual(expectedResult, result); Assert.AreEqual(description, title); Assert.AreEqual(query, actualQuery); mocks.VerifyAll(); }
public void GetSourceFileLocation_CancelClicked_ResultFileSelectedIsFalse() { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); DialogBoxHandler = (name, wnd) => { var tester = new OpenFileDialogTester(wnd); tester.ClickCancel(); }; // Call string result = helper.GetSourceFileLocation(new FileFilterGenerator().Filter); // Assert Assert.IsNull(result); }
public void GetTargetFileLocation_FileSelected_ResultFileSelectedIsTrueFileNameSet() { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); string expectedFilePath = Path.GetFullPath(Path.GetRandomFileName()); DialogBoxHandler = (name, wnd) => { var tester = new SaveFileDialogTester(wnd); tester.SaveFile(expectedFilePath); }; // Call string result = helper.GetTargetFileLocation(new FileFilterGenerator().Filter, null); // Assert Assert.AreEqual(expectedFilePath, result); }
public void GetSourceFileLocation_Always_ShowsOpenFileDialog() { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); string windowName = null; DialogBoxHandler = (name, wnd) => { var tester = new OpenFileDialogTester(wnd); windowName = name; tester.ClickCancel(); }; // Call helper.GetSourceFileLocation(new FileFilterGenerator().Filter); // Assert Assert.AreEqual("Openen", windowName); }
public void GetTargetFolderLocation_Always_ShowsFolderBrowserDialog() { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); string windowName = null; DialogBoxHandler = (name, wnd) => { var tester = new FileDialogTester(wnd); windowName = name; tester.ClickCancel(); }; // Call helper.GetTargetFolderLocation(); // Assert Assert.AreEqual("Browse For Folder", windowName); }
public void InquireContinuation_OkOrCancelClicked_ReturnExpectedResult(bool confirm) { // Setup dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr)); mocks.ReplayAll(); var helper = new DialogBasedInquiryHelper(dialogParent); const string expectedQuery = "Are you sure you want to do this?"; const string expectedTitle = "Bevestigen"; string query = null; string title = null; DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); query = tester.Text; title = tester.Title; if (confirm) { tester.ClickOk(); } else { tester.ClickCancel(); } }; // Call bool result = helper.InquireContinuation(expectedQuery); // Assert Assert.AreEqual(expectedQuery, query); Assert.AreEqual(expectedTitle, title); Assert.AreEqual(confirm, result); }