public void ShowMockFileDialogService()
        {
            var fileDialogService = new MockFileDialogService();

            var owner = new object();
            var fileType = new FileType("description", ".fileExtension");
            var fileTypes = new[] { fileType };
            var result = new FileDialogResult("selectedName", fileType);
            fileDialogService.Result = result;

            Assert.AreEqual(result, fileDialogService.ShowOpenFileDialog(owner, fileTypes, fileType, "defaultFileName"));

            Assert.AreEqual(FileDialogType.OpenFileDialog, fileDialogService.FileDialogType);
            Assert.AreEqual(owner, fileDialogService.Owner);
            Assert.AreEqual(fileTypes, fileDialogService.FileTypes);
            Assert.AreEqual(fileType, fileDialogService.DefaultFileType);
            Assert.AreEqual("defaultFileName", fileDialogService.DefaultFileName);

            fileDialogService.Clear();

            Assert.AreEqual(FileDialogType.None, fileDialogService.FileDialogType);
            Assert.IsNull(fileDialogService.Owner);
            Assert.IsNull(fileDialogService.FileTypes);
            Assert.IsNull(fileDialogService.DefaultFileType);
            Assert.IsNull(fileDialogService.DefaultFileName);

            fileDialogService.Result = result;
            Assert.AreEqual(result, fileDialogService.ShowSaveFileDialog(owner, fileTypes, fileType, "defaultFileName"));

            Assert.AreEqual(FileDialogType.SaveFileDialog, fileDialogService.FileDialogType);
            Assert.AreEqual(owner, fileDialogService.Owner);
            Assert.AreEqual(fileTypes, fileDialogService.FileTypes);
            Assert.AreEqual(fileType, fileDialogService.DefaultFileType);
            Assert.AreEqual("defaultFileName", fileDialogService.DefaultFileName);
        }
        public void ShowSaveFileDialogExtensionTest()
        {
            FileType rtfFileType = new FileType("RichText Document", ".rtf");
            FileType xpsFileType = new FileType("XPS Document", ".xps");
            IEnumerable<FileType> fileTypes = new FileType[] { rtfFileType, xpsFileType };
            string defaultFileName = "Document 1.rtf";
            FileDialogResult result = new FileDialogResult("Document 2.rtf", rtfFileType);

            MockFileDialogService service = new MockFileDialogService();
            service.Result = result;

            Assert.AreEqual(result, service.ShowSaveFileDialog(rtfFileType));
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, rtfFileType));
            AssertHelper.ExpectedException<ArgumentNullException>(() => service.ShowSaveFileDialog((FileType)null));

            Assert.AreEqual(result, service.ShowSaveFileDialog(rtfFileType, defaultFileName));
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            Assert.AreEqual(defaultFileName, service.DefaultFileName);
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, rtfFileType, defaultFileName));
            AssertHelper.ExpectedException<ArgumentNullException>(() => service.ShowSaveFileDialog((FileType)null, defaultFileName));

            Assert.AreEqual(result, service.ShowSaveFileDialog(fileTypes));
            Assert.IsTrue(service.FileTypes.SequenceEqual(new FileType[] { rtfFileType, xpsFileType }));
            AssertHelper.ExpectedException<ArgumentNullException>(() => FileDialogServiceExtensions.ShowSaveFileDialog(null, fileTypes));
        }
Exemple #3
0
        public void ResultTest()
        {
            FileDialogResult result = new FileDialogResult();
            Assert.IsFalse(result.IsValid);

            FileType rtfFileType = new FileType("RichText Document", ".rtf");
            result = new FileDialogResult(@"C:\Document 1.rtf", rtfFileType);
            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(@"C:\Document 1.rtf", result.FileName);
            Assert.AreEqual(rtfFileType, result.SelectedFileType);
        }