Ejemplo n.º 1
0
        public void ShowOpenFileDialogExtensionTest()
        {
            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.ShowOpenFileDialog(rtfFileType));
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, rtfFileType));
            AssertHelper.ExpectedException <ArgumentNullException>(() => service.ShowOpenFileDialog((FileType)null));

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

            Assert.AreEqual(result, service.ShowOpenFileDialog(fileTypes));
            Assert.IsTrue(service.FileTypes.SequenceEqual(new FileType[] { rtfFileType, xpsFileType }));
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, fileTypes));
        }
        public void ShowOpenFileDialogExtensionTest()
        {
            var rtfFileType = new FileType("RichText Document", ".rtf");
            var xpsFileType = new FileType("XPS Document", ".xps");
            IEnumerable <FileType> fileTypes = new[] { rtfFileType, xpsFileType };
            string defaultFileName           = "Document 1.rtf";
            var    result = new FileDialogResult("Document 2.rtf", rtfFileType);

            object owner   = new object();
            var    service = new MockFileDialogService();

            service.Result = result;

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

            service.Clear();
            Assert.AreEqual(result, service.ShowOpenFileDialog(owner, rtfFileType));
            Assert.AreEqual(FileDialogType.OpenFileDialog, service.FileDialogType);
            Assert.AreEqual(owner, service.Owner);
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, owner, rtfFileType));
            AssertHelper.ExpectedException <ArgumentNullException>(() => service.ShowOpenFileDialog(owner, (FileType)null));

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

            service.Clear();
            Assert.AreEqual(result, service.ShowOpenFileDialog(owner, rtfFileType, defaultFileName));
            Assert.AreEqual(FileDialogType.OpenFileDialog, service.FileDialogType);
            Assert.AreEqual(owner, service.Owner);
            Assert.AreEqual(rtfFileType, service.FileTypes.Single());
            Assert.AreEqual(defaultFileName, service.DefaultFileName);
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, owner, rtfFileType, defaultFileName));
            AssertHelper.ExpectedException <ArgumentNullException>(() => service.ShowOpenFileDialog(owner, (FileType)null, defaultFileName));

            service.Clear();
            Assert.AreEqual(result, service.ShowOpenFileDialog(fileTypes));
            Assert.AreEqual(FileDialogType.OpenFileDialog, service.FileDialogType);
            AssertHelper.SequenceEqual(new[] { rtfFileType, xpsFileType }, service.FileTypes);
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, fileTypes));

            service.Clear();
            Assert.AreEqual(result, service.ShowOpenFileDialog(owner, fileTypes));
            Assert.AreEqual(FileDialogType.OpenFileDialog, service.FileDialogType);
            Assert.AreEqual(owner, service.Owner);
            AssertHelper.SequenceEqual(new[] { rtfFileType, xpsFileType }, service.FileTypes);
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, owner, fileTypes));

            service.Clear();
            Assert.AreEqual(result, service.ShowOpenFileDialog(fileTypes, rtfFileType, defaultFileName));
            Assert.AreEqual(FileDialogType.OpenFileDialog, service.FileDialogType);
            AssertHelper.SequenceEqual(new[] { rtfFileType, xpsFileType }, service.FileTypes);
            Assert.AreEqual(rtfFileType, service.DefaultFileType);
            Assert.AreEqual(defaultFileName, service.DefaultFileName);
            AssertHelper.ExpectedException <ArgumentNullException>(() => FileDialogServiceExtensions.ShowOpenFileDialog(null, fileTypes, rtfFileType, defaultFileName));
        }