public void ImportOn_NoImportInfos_GivesMessageBox() { // Setup var mockRepository = new MockRepository(); var dialogParent = mockRepository.Stub <IViewParent>(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); mockRepository.ReplayAll(); string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; messageBox.ClickOk(); }; var importHandler = new GuiImportHandler(dialogParent, Enumerable.Empty <ImportInfo>(), inquiryHelper); // Call importHandler.ImportOn(3, Enumerable.Empty <ImportInfo>()); // Assert Assert.AreEqual("Fout", messageBoxTitle); Assert.AreEqual("Geen enkele 'Importer' is beschikbaar voor dit element.", messageBoxText); mockRepository.VerifyAll(); }
public void ImportOn_MultipleSupportedImportInfos_ShowsDialogWithOptions(bool hasFileFilterGenerator) { // Setup const string importInfoAName = "nameA"; var importInfoA = new ImportInfo <object> { Name = importInfoAName, FileFilterGenerator = hasFileFilterGenerator ? new FileFilterGenerator("extensionA") : null }; const string importInfoBName = "nameB"; var importInfoB = new ImportInfo <object> { Name = importInfoBName, FileFilterGenerator = hasFileFilterGenerator ? new FileFilterGenerator("extensionB") : null }; var mockRepository = new MockRepository(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); mockRepository.ReplayAll(); var listViewItems = new ListViewItem[0]; DialogBoxHandler = (name, wnd) => { using (new FormTester(name)) { var listView = (ListView) new ControlTester("listViewItemTypes").TheObject; listViewItems = listView.Items.OfType <ListViewItem>().ToArray(); } }; using (var form = new TestViewParentForm()) { var importHandler = new GuiImportHandler(form, Enumerable.Empty <ImportInfo>(), inquiryHelper); // Call importHandler.ImportOn(new object(), new ImportInfo[] { importInfoA, importInfoB }); } // Assert Assert.AreEqual(2, listViewItems.Length); string expectedItemNameA = hasFileFilterGenerator ? $"{importInfoA.Name} (*.{importInfoA.FileFilterGenerator.Extension})" : importInfoA.Name; Assert.AreEqual(expectedItemNameA, listViewItems[0].Name); string expectedItemNameB = hasFileFilterGenerator ? $"{importInfoB.Name} (*.{importInfoB.FileFilterGenerator.Extension})" : importInfoB.Name; Assert.AreEqual(expectedItemNameB, listViewItems[1].Name); mockRepository.VerifyAll(); }
public void ImportOn_SupportedImportInfoAndVerifyUpdatesUnsuccessful_ActivityNotCreated() { // Setup var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Stub(ih => ih.GetSourceFileLocation(generator.Filter)).Return("/some/path"); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); var isVerifyUpdatedCalled = false; using (var form = new TestViewParentForm()) { var supportedImportInfo = new ImportInfo <object> { CreateFileImporter = (o, s) => { Assert.Fail("CreateFileImporter is not expected to be called when VerifyUpdates function returns false."); return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => { Assert.AreSame(o, targetObject); isVerifyUpdatedCalled = true; return(false); } }; var importHandler = new GuiImportHandler(form, Enumerable.Empty <ImportInfo>(), inquiryHelper); // Call importHandler.ImportOn(targetObject, new ImportInfo[] { supportedImportInfo }); } // Assert Assert.IsTrue(isVerifyUpdatedCalled); mockRepository.VerifyAll(); }
public void ImportOn_InquiryHelperReturnsNoPath_ImportCancelledWithLogMessage() { // Setup var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Expect(ih => ih.GetSourceFileLocation(generator.Filter)).Return(null); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); using (var form = new TestViewParentForm()) { var supportedImportInfo = new ImportInfo <object> { CreateFileImporter = (o, s) => { Assert.Fail("CreateFileImporter is not expected to be called when no file path is chosen."); return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => true }; var importHandler = new GuiImportHandler(form, Enumerable.Empty <ImportInfo>(), inquiryHelper); // Call void Call() => importHandler.ImportOn(targetObject, new ImportInfo[] { supportedImportInfo }); // Assert TestHelper.AssertLogMessageIsGenerated(Call, "Importeren van gegevens is geannuleerd."); } mockRepository.VerifyAll(); }
public void ImportOn_SupportedImportInfoAndVerifyUpdatesSuccessful_ExpectedImportInfoFunctionsCalledAndActivityCreated() { // Setup const string filePath = "/some/path"; var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Expect(ih => ih.GetSourceFileLocation(generator.Filter)).Return(filePath); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); const string dataDescription = "Random data"; var isCreateFileImporterCalled = false; var isVerifyUpdatedCalled = false; DialogBoxHandler = (name, wnd) => { // Activity closes itself }; using (var form = new TestViewParentForm()) { var supportedImportInfo = new ImportInfo <object> { Name = dataDescription, CreateFileImporter = (o, s) => { Assert.AreSame(o, targetObject); Assert.AreEqual(filePath, s); isCreateFileImporterCalled = true; return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => { Assert.AreSame(o, targetObject); isVerifyUpdatedCalled = true; return(true); } }; var importHandler = new GuiImportHandler(form, Enumerable.Empty <ImportInfo>(), inquiryHelper); // Call void Call() => importHandler.ImportOn(targetObject, new ImportInfo[] { supportedImportInfo }); // Assert TestHelper.AssertLogMessagesAreGenerated(Call, new[] { $"Importeren van '{dataDescription}' is gestart.", $"Importeren van '{dataDescription}' is mislukt." }); } // Assert Assert.IsTrue(isCreateFileImporterCalled); Assert.IsTrue(isVerifyUpdatedCalled); mockRepository.VerifyAll(); }