Permalink
Browse files

Support for saving project files

-Added icons for toolbar items
-Added Expression Dark skin and skinned UI elements
  • Loading branch information...
HEskandari committed Sep 1, 2010
1 parent 30c9743 commit a29a849b1fffec59a8e71bad7b9ff98052eacd9b
@@ -1,17 +1,16 @@
-using System.Windows.Forms;
using Rhino.Licensing.AdminTool.ViewModels;
using Rhino.Mocks;
using Xunit;
using System.Linq;
using Xunit.Extensions;
-using FileDialog = Rhino.Licensing.AdminTool.Dialogs.FileDialog;
-using DialogForm = System.Windows.Forms.FileDialog;
-
+using DialogForm = System.Windows.Forms.FileDialog;
+using OpenFileDialog = Rhino.Licensing.AdminTool.Dialogs.OpenFileDialog;
+
namespace Rhino.Licensing.AdminTool.Tests.Dialogs
{
public class FileDialogTests
{
- private DialogForm _dialogForm;
+ private readonly DialogForm _dialogForm;
public FileDialogTests()
{
@@ -21,10 +20,10 @@ public FileDialogTests()
[Fact]
public void ShowDialog_Sets_Selected_Files()
{
- var model = new OpenFileDialogViewModel();
- var dialog = new TestFileDialog(_dialogForm, model);
+ var model = new OpenFileDialogViewModel();
+ var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };
- _dialogForm.Expect(x => x.ShowDialog()).Return(DialogResult.OK);
+ _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"});
@@ -39,8 +38,8 @@ public void ShowDialog_Sets_Selected_Files()
[Fact]
public void Dialog_Disposes_Upon_Destruction()
{
- var model = new OpenFileDialogViewModel();
- var dialog = new TestFileDialog(_dialogForm, model);
+ var model = new OpenFileDialogViewModel();
+ var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };
dialog.ShowDialog();
dialog.Dispose();
@@ -49,13 +48,13 @@ public void Dialog_Disposes_Upon_Destruction()
}
[Theory]
- [InlineData(DialogResult.OK, true)]
- [InlineData(DialogResult.Cancel, false)]
- [InlineData(DialogResult.Abort, null)]
- public void DialogResult_Maps_To_ViewModel_Result(DialogResult dialogResult, bool? mappedResult)
+ [InlineData(System.Windows.Forms.DialogResult.OK, true)]
+ [InlineData(System.Windows.Forms.DialogResult.Cancel, false)]
+ [InlineData(System.Windows.Forms.DialogResult.Abort, null)]
+ public void DialogResult_Maps_To_ViewModel_Result(System.Windows.Forms.DialogResult dialogResult, bool? mappedResult)
{
var model = new OpenFileDialogViewModel();
- var dialog = new TestFileDialog(_dialogForm, model);
+ var dialog = new TestOpenFileDialog(_dialogForm) { ViewModel = model };
_dialogForm.Expect(x => x.ShowDialog()).Return(dialogResult);
@@ -64,26 +63,19 @@ public void DialogResult_Maps_To_ViewModel_Result(DialogResult dialogResult, boo
Assert.Equal(mappedResult, model.Result);
}
- public class TestFileDialog : FileDialog
- {
- private readonly System.Windows.Forms.FileDialog _dialog;
- private readonly IFileDialogViewModel _viewModel;
-
- public TestFileDialog(System.Windows.Forms.FileDialog dialog, IFileDialogViewModel viewModel)
- {
- _dialog = dialog;
- _viewModel = viewModel;
- }
-
- protected override System.Windows.Forms.FileDialog Dialog
- {
- get { return _dialog; }
- }
-
- public override IFileDialogViewModel ViewModel
- {
- get { return _viewModel; }
- }
+ public class TestOpenFileDialog : OpenFileDialog
+ {
+ private readonly DialogForm _form;
+
+ public TestOpenFileDialog(DialogForm form)
+ {
+ _form = form;
+ }
+
+ protected override DialogForm Dialog
+ {
+ get { return _form; }
+ }
}
}
}
@@ -53,8 +53,8 @@ private IOpenFileDialogViewModel CreateOpenFileDialogModel()
public class OpenFileDialogStub : OpenFileDialog
{
public OpenFileDialogStub(IOpenFileDialogViewModel viewModel)
- : base(viewModel)
{
+ base.ViewModel = viewModel;
}
public System.Windows.Forms.OpenFileDialog GetCoreDialog()
@@ -55,8 +55,8 @@ private ISaveFileDialogViewModel CreateSaveFileDialogModel()
public class SaveFileDialogStub : SaveFileDialog
{
public SaveFileDialogStub(ISaveFileDialogViewModel viewModel)
- : base(viewModel)
{
+ base.ViewModel = viewModel;
}
public System.Windows.Forms.SaveFileDialog GetCoreDialog()
@@ -15,12 +15,12 @@ public void Can_Show_OpenFileDialog()
{
var model = CreateOpenFileDialogModel(true);
var factory = MockRepository.GenerateMock<IDialogFactory>();
- var dialog = MockRepository.GenerateMock<OpenFileDialog>(model);
+ var dialog = MockRepository.GenerateMock<OpenFileDialog>();
- factory.Expect(x => x.Create<OpenFileDialog>()).Return(dialog);
+ factory.Expect(x => x.Create<OpenFileDialog, IOpenFileDialogViewModel>(Arg.Is(model))).Return(dialog);
dialog.Expect(x => x.ViewModel).Return(model);
- new DialogService(factory).ShowOpenFileDialog();
+ new DialogService(factory).ShowOpenFileDialog(model);
dialog.AssertWasCalled(x => x.ShowDialog(), x => x.Repeat.Once());
}
@@ -30,13 +30,13 @@ public void Can_Show_SaveFileDialog()
{
var model = CreateSaveFileDialogModel(true);
var factory = MockRepository.GenerateMock<IDialogFactory>();
- var dialog = MockRepository.GenerateMock<SaveFileDialog>(model);
+ var dialog = MockRepository.GenerateMock<SaveFileDialog>();
var service = new DialogService(factory) as IDialogService;
- factory.Expect(x => x.Create<SaveFileDialog>()).Return(dialog);
+ factory.Expect(x => x.Create<SaveFileDialog, ISaveFileDialogViewModel>(Arg.Is(model))).Return(dialog);
- service.ShowSaveFileDialog();
+ service.ShowSaveFileDialog(model);
dialog.AssertWasCalled(x => x.ShowDialog(), x => x.Repeat.Once());
}
@@ -82,33 +82,26 @@ public void Can_Save_If_Name_Is_Provided()
[Fact]
public void Save_Action_Will_Open_SaveDialog()
- {
- _dialogService.Expect(x => x.ShowSaveFileDialog())
- .Return(new SaveFileDialogViewModel
- {
- Result = true
- });
+ {
+ var dialogModel = new SaveFileDialogViewModel {Result = true};
+ _dialogService.Expect(x => x.ShowSaveFileDialog(dialogModel));
- var vm = CreateViewModel();
+ var vm = CreateViewModel(dialogModel);
vm.Save();
- _dialogService.AssertWasCalled(x => x.ShowSaveFileDialog(), x => x.Repeat.Once());
+ _dialogService.AssertWasCalled(x => x.ShowSaveFileDialog(Arg.Is(dialogModel)), x => x.Repeat.Once());
}
[Fact]
public void Save_Action_Will_Call_ProjectService_If_Proper_Result_Is_Set()
{
var existingFile = Path.GetTempFileName();
- var choosenFile = new FileInfo(existingFile);
+ var choosenFile = new FileInfo(existingFile);
+ var model = new SaveFileDialogViewModel {Result = true, FileName = existingFile};
- _dialogService.Expect(x => x.ShowSaveFileDialog())
- .Return(new SaveFileDialogViewModel
- {
- Result = true,
- FileName = existingFile
- });
+ _dialogService.Expect(x => x.ShowSaveFileDialog(model));
- var vm = CreateViewModel();
+ var vm = CreateViewModel(model);
vm.Save();
_projectService.Expect(x => x.Save(Arg<Project>.Is.Anything, Arg.Is(choosenFile))).Repeat.Once();
@@ -117,15 +110,10 @@ public void Save_Action_Will_Call_ProjectService_If_Proper_Result_Is_Set()
[Fact]
public void Will_Not_Proceed_To_Save_When_No_File_Is_Selected()
{
- var vm = CreateViewModel();
-
- _dialogService.Expect(x => x.ShowSaveFileDialog())
- .Return(new SaveFileDialogViewModel
- {
- Result = true,
- FileName = null
- });
-
+ var dialogModel = new SaveFileDialogViewModel {Result = true, FileName = null};
+ _dialogService.Expect(x => x.ShowSaveFileDialog(dialogModel));
+
+ var vm = CreateViewModel(dialogModel);
vm.Save();
_projectService.AssertWasNotCalled(x => x.Save(Arg<Project>.Is.Anything, Arg<FileInfo>.Is.Anything));
@@ -143,11 +131,42 @@ public void Can_Generate_Key_Pair()
Assert.NotNull(vm.CurrentProject.Product.PrivateKey);
Assert.Contains("<P>", vm.CurrentProject.Product.PrivateKey); //Makes sure it is only private
Assert.Contains("<Modulus>", vm.CurrentProject.Product.PublicKey); //Makes sure it is public
+ }
+
+ [Fact]
+ public void Default_Project_Save_Dialog()
+ {
+ var vm = new ProjectViewModel(_projectService, _dialogService);
+ var dialogModel = vm.CreateSaveDialogModel();
+
+ Assert.Equal("Rhino License|*.rlic", dialogModel.Filter);
+ Assert.True(dialogModel.OverwritePrompt);
}
- private ProjectViewModel CreateViewModel()
+ private ProjectViewModel CreateViewModel(ISaveFileDialogViewModel model)
{
- return new ProjectViewModel(_projectService, _dialogService);
+ return new TestProjectViewModel(_projectService, _dialogService, model);
+ }
+
+ private ProjectViewModel CreateViewModel()
+ {
+ return new TestProjectViewModel(_projectService, _dialogService, null);
+ }
+
+ public class TestProjectViewModel : ProjectViewModel
+ {
+ private readonly ISaveFileDialogViewModel _dialogModel;
+
+ public TestProjectViewModel(IProjectService projectService, IDialogService dialogService, ISaveFileDialogViewModel model)
+ : base(projectService, dialogService)
+ {
+ _dialogModel = model;
+ }
+
+ public override ISaveFileDialogViewModel CreateSaveDialogModel()
+ {
+ return _dialogModel;
+ }
}
}
}
@@ -6,6 +6,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Theme/ExpressionDark.xaml" />
+ <ResourceDictionary Source="/Theme/AppStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
@@ -4,8 +4,11 @@
namespace Rhino.Licensing.AdminTool.Dialogs
{
- public abstract class FileDialog : IDisposable
- {
+ public abstract class FileDialog<T> : IDisposable
+ where T : IFileDialogViewModel
+ {
+ private T _viewModel;
+
public virtual void ShowDialog()
{
var result = Dialog.ShowDialog();
@@ -15,16 +18,25 @@ public virtual void ShowDialog()
ViewModel.Result = MappedResult(result);
}
- protected abstract System.Windows.Forms.FileDialog Dialog
+ protected abstract FileDialog Dialog
{
get;
- }
-
- public abstract IFileDialogViewModel ViewModel
- {
- get;
- }
-
+ }
+
+ public virtual T ViewModel
+ {
+ get { return _viewModel; }
+ set
+ {
+ _viewModel = value;
+ BindDialogToViewModel();
+ }
+ }
+
+ protected virtual void BindDialogToViewModel()
+ {
+ }
+
public void Dispose()
{
Dispose(true);
@@ -1,38 +1,36 @@
-using Rhino.Licensing.AdminTool.ViewModels;
-using OpenDialog = System.Windows.Forms.OpenFileDialog;
-
-namespace Rhino.Licensing.AdminTool.Dialogs
-{
- public class OpenFileDialog : FileDialog
- {
- private readonly OpenDialog _openFileDialog;
- private readonly IOpenFileDialogViewModel _viewModel;
-
- public OpenFileDialog(IOpenFileDialogViewModel viewModel)
- {
- _viewModel = viewModel;
- _openFileDialog = new OpenDialog
- {
- AddExtension = viewModel.AddExtension,
- CheckFileExists = viewModel.CheckFileExists,
- CheckPathExists = viewModel.CheckPathExists,
- DefaultExt = viewModel.DefaultExtension,
- FileName = viewModel.FileName,
- Filter = viewModel.Filter,
- InitialDirectory = viewModel.InitialDirectory,
- Multiselect = viewModel.MultiSelect,
- Title = viewModel.Title
- };
- }
-
- protected override System.Windows.Forms.FileDialog Dialog
- {
- get { return _openFileDialog; }
- }
-
- public override IFileDialogViewModel ViewModel
- {
- get { return _viewModel; }
- }
- }
+using System.Windows.Forms;
+using Rhino.Licensing.AdminTool.ViewModels;
+using OpenDialog = System.Windows.Forms.OpenFileDialog;
+
+namespace Rhino.Licensing.AdminTool.Dialogs
+{
+ public class OpenFileDialog : FileDialog<IOpenFileDialogViewModel>
+ {
+ private readonly OpenDialog _openFileDialog;
+
+ public OpenFileDialog()
+ {
+ _openFileDialog = new OpenDialog();
+ }
+
+ protected override FileDialog Dialog
+ {
+ get { return _openFileDialog; }
+ }
+
+ protected override void BindDialogToViewModel()
+ {
+ base.BindDialogToViewModel();
+
+ _openFileDialog.AddExtension = ViewModel.AddExtension;
+ _openFileDialog.CheckFileExists = ViewModel.CheckFileExists;
+ _openFileDialog.CheckPathExists = ViewModel.CheckPathExists;
+ _openFileDialog.DefaultExt = ViewModel.DefaultExtension;
+ _openFileDialog.FileName = ViewModel.FileName;
+ _openFileDialog.Filter = ViewModel.Filter;
+ _openFileDialog.InitialDirectory = ViewModel.InitialDirectory;
+ _openFileDialog.Multiselect = ViewModel.MultiSelect;
+ _openFileDialog.Title = ViewModel.Title;
+ }
+ }
}
Oops, something went wrong.

0 comments on commit a29a849

Please sign in to comment.