public void Dialog_Disposes_Upon_Destruction()
        {
            var model = new OpenFileDialogViewModel();
            var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };

            dialog.ShowDialog();
            dialog.Dispose();

            _dialogForm.AssertWasCalled(x => x.Dispose(), x => x.Repeat.Once());
        }
        public void DialogResult_Maps_To_ViewModel_Result(System.Windows.Forms.DialogResult dialogResult, bool? mappedResult)
        {
            var model = new OpenFileDialogViewModel();
            var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };

            _dialogForm.Expect(x => x.ShowDialog()).Return(dialogResult);

            dialog.ShowDialog();
            
            Assert.Equal(mappedResult, model.Result);
        }
        public void ShowDialog_Sets_Selected_Files()
        {
            var model = new OpenFileDialogViewModel();
            var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };

            _dialogForm.Expect(x => x.ShowDialog()).Return(System.Windows.Forms.DialogResult.OK);
            _dialogForm.Expect(x => x.FileName).Return("License.lic");
            _dialogForm.Expect(x => x.FileNames).Return(new[] {"License.lic", "License2.lic"});

            dialog.ShowDialog();

            Assert.Equal("License.lic", model.FileName);
            Assert.Contains("License.lic", model.FileNames);
            Assert.Contains("License2.lic", model.FileNames);
            Assert.Equal(2, model.FileNames.Count());
        }
        private IOpenFileDialogViewModel CreateOpenFileDialogModel()
        {
            var model = new OpenFileDialogViewModel
            {
                AddExtension = true,
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExtension = "rlic",
                Filter = "Rhino License Project|*.rlic",
                InitialDirectory = "C:\\",
                MultiSelect = false,
                Title = "Open File Dialog"
            };

            return model;
        }
        public void Open_Loads_Project()
        {
            var p = new Project();
            _projectService.Expect(x => x.Open(Arg<FileInfo>.Is.Anything)).Return(p);

            var dialogModel = new OpenFileDialogViewModel { Result = true, FileName = "C:\\" };
            _viewModelFactory.Expect(x => x.Create<IOpenFileDialogViewModel>()).Return(dialogModel);

            var vm = CreateProjectViewModel();
            vm.Open();

            Assert.NotNull(vm.CurrentProject);
            Assert.Same(p, vm.CurrentProject);
        }
        public void Open_Returns_False_When_User_Cancels_The_Open_Dialog()
        {
            var dialogModel = new OpenFileDialogViewModel { Result = false, FileName = "C:\\" };
            _viewModelFactory.Expect(x => x.Create<IOpenFileDialogViewModel>()).Return(dialogModel);

            var vm = CreateProjectViewModel();
            var opened = vm.Open();

            Assert.False(opened);
        }
        public void Open_Shows_OpenDialog()
        {
            var dialogModel = new OpenFileDialogViewModel { Result = true, FileName = "C:\\" };
            _viewModelFactory.Expect(x => x.Create<IOpenFileDialogViewModel>()).Return(dialogModel);

            var vm = CreateProjectViewModel();
            vm.Open();

            _dialogService.AssertWasCalled(x => x.ShowOpenFileDialog(Arg.Is(dialogModel)), options => options.Repeat.Once());
        }
        public void Default_Project_Open_Dialog_Has_Correct_Filter()
        {
            var dialogViewModel = new OpenFileDialogViewModel { Result = true };
            _viewModelFactory.Expect(x => x.Create<IOpenFileDialogViewModel>()).Return(dialogViewModel);

            var vm = CreateProjectViewModel();
            vm.Open();

            Assert.Equal("Rhino Project|*.rlic", dialogViewModel.Filter);
        }
        public void Open_Shows_OpenDialog()
        {
            var dialogModel = new OpenFileDialogViewModel { Result = true, FileName = "C:\\" };
            var vm = CreateViewModel(dialogModel);

            vm.Open();

            _dialogService.AssertWasCalled(x => x.ShowOpenFileDialog(Arg.Is(dialogModel)), options => options.Repeat.Once());
        }
        public void Open_Returns_False_When_User_Cancels_The_Open_Dialog()
        {
            var dialogModel = new OpenFileDialogViewModel { Result = false, FileName = "C:\\" };
            var vm = CreateViewModel(dialogModel);

            var opened = vm.Open();

            Assert.False(opened);
        }