Skip to content
Browse files

Open/Save file dialog view model tests

  • Loading branch information...
1 parent 71263aa commit 6b57193f653bc0f96fd11e309814f43aeba165f7 @HEskandari HEskandari committed
View
120 Rhino.Licensing.AdminTool.Tests/Dialogs/OpenFileDialogTests.cs
@@ -1,56 +1,66 @@
-using Rhino.Licensing.AdminTool.Dialogs;
-using Rhino.Licensing.AdminTool.ViewModels;
-using Xunit;
-
-namespace Rhino.Licensing.AdminTool.Tests.Dialogs
-{
- public class OpenFileDialogTests
- {
- [Fact]
- public void Dialog_Wires_Model_Properties()
- {
- var model = CreateOpenFileDialogModel();
- var dialog = new OpenFileDialogStub(model);
- var dialogForm = dialog.GetCoreDialog();
-
- Assert.True(dialogForm.AddExtension);
- Assert.True(dialogForm.CheckFileExists);
- Assert.True(dialogForm.CheckPathExists);
- Assert.False(dialogForm.Multiselect);
- Assert.Equal("rlic", dialogForm.DefaultExt);
- Assert.Equal("Rhino License Project|*.rlic", dialogForm.Filter);
- Assert.Equal("C:\\", dialogForm.InitialDirectory);
- Assert.Equal("Open File Dialog", dialogForm.Title);
- }
-
- 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 class OpenFileDialogStub : OpenFileDialog
- {
- public OpenFileDialogStub(IOpenFileDialogViewModel viewModel)
- : base(viewModel)
- {
- }
-
- public System.Windows.Forms.OpenFileDialog GetCoreDialog()
- {
- return base.Dialog as System.Windows.Forms.OpenFileDialog;
- }
- }
- }
+using Rhino.Licensing.AdminTool.Dialogs;
+using Rhino.Licensing.AdminTool.ViewModels;
+using Xunit;
+
+namespace Rhino.Licensing.AdminTool.Tests.Dialogs
+{
+ public class OpenFileDialogTests
+ {
+ [Fact]
+ public void Dialog_Wires_Model_Properties()
+ {
+ var model = CreateOpenFileDialogModel();
+ var dialog = new OpenFileDialogStub(model);
+ var dialogForm = dialog.GetCoreDialog();
+
+ Assert.True(dialogForm.AddExtension);
+ Assert.True(dialogForm.CheckFileExists);
+ Assert.True(dialogForm.CheckPathExists);
+ Assert.False(dialogForm.Multiselect);
+ Assert.Equal("rlic", dialogForm.DefaultExt);
+ Assert.Equal("Rhino License Project|*.rlic", dialogForm.Filter);
+ Assert.Equal("C:\\", dialogForm.InitialDirectory);
+ Assert.Equal("Open File Dialog", dialogForm.Title);
+ }
+
+ [Fact]
+ public void OpenFileDialog_ViewModel_Property()
+ {
+ var model = CreateOpenFileDialogModel();
+ var dialog = new OpenFileDialogStub(model);
+
+ Assert.NotNull(dialog.ViewModel);
+ Assert.Same(model, dialog.ViewModel);
+ }
+
+ 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 class OpenFileDialogStub : OpenFileDialog
+ {
+ public OpenFileDialogStub(IOpenFileDialogViewModel viewModel)
+ : base(viewModel)
+ {
+ }
+
+ public System.Windows.Forms.OpenFileDialog GetCoreDialog()
+ {
+ return base.Dialog as System.Windows.Forms.OpenFileDialog;
+ }
+ }
+ }
}
View
124 Rhino.Licensing.AdminTool.Tests/Dialogs/SaveFileDialogTests.cs
@@ -1,58 +1,68 @@
-using Rhino.Licensing.AdminTool.Dialogs;
-using Rhino.Licensing.AdminTool.ViewModels;
-using Xunit;
-
-namespace Rhino.Licensing.AdminTool.Tests.Dialogs
-{
- public class SaveFileDialogTests
- {
- [Fact]
- public void Dialog_Wires_Model_Properties()
- {
- var model = CreateOpenFileDialogModel();
- var dialog = new OpenFileDialogStub(model);
- var dialogForm = dialog.GetCoreDialog();
-
- Assert.True(dialogForm.AddExtension);
- Assert.True(dialogForm.CheckFileExists);
- Assert.True(dialogForm.CheckPathExists);
- Assert.True(dialogForm.OverwritePrompt);
- Assert.True(dialogForm.SupportMultiDottedExtensions);
- Assert.Equal("rlic", dialogForm.DefaultExt);
- Assert.Equal("Rhino License Project|*.rlic", dialogForm.Filter);
- Assert.Equal("C:\\", dialogForm.InitialDirectory);
- Assert.Equal("Save File Dialog", dialogForm.Title);
- }
-
- private ISaveFileDialogViewModel CreateOpenFileDialogModel()
- {
- var model = new SaveFileDialogViewModel
- {
- AddExtension = true,
- CheckFileExists = true,
- CheckPathExists = true,
- OverwritePrompt = true,
- SupportMultiDottedExtensions = true,
- DefaultExtension = "rlic",
- Filter = "Rhino License Project|*.rlic",
- InitialDirectory = "C:\\",
- Title = "Save File Dialog",
- };
-
- return model;
- }
-
- public class OpenFileDialogStub : SaveFileDialog
- {
- public OpenFileDialogStub(ISaveFileDialogViewModel viewModel)
- : base(viewModel)
- {
- }
-
- public System.Windows.Forms.SaveFileDialog GetCoreDialog()
- {
- return base.Dialog as System.Windows.Forms.SaveFileDialog;
- }
- }
- }
+using Rhino.Licensing.AdminTool.Dialogs;
+using Rhino.Licensing.AdminTool.ViewModels;
+using Xunit;
+
+namespace Rhino.Licensing.AdminTool.Tests.Dialogs
+{
+ public class SaveFileDialogTests
+ {
+ [Fact]
+ public void Dialog_Wires_Model_Properties()
+ {
+ var model = CreateSaveFileDialogModel();
+ var dialog = new SaveFileDialogStub(model);
+ var dialogForm = dialog.GetCoreDialog();
+
+ Assert.True(dialogForm.AddExtension);
+ Assert.True(dialogForm.CheckFileExists);
+ Assert.True(dialogForm.CheckPathExists);
+ Assert.True(dialogForm.OverwritePrompt);
+ Assert.True(dialogForm.SupportMultiDottedExtensions);
+ Assert.Equal("rlic", dialogForm.DefaultExt);
+ Assert.Equal("Rhino License Project|*.rlic", dialogForm.Filter);
+ Assert.Equal("C:\\", dialogForm.InitialDirectory);
+ Assert.Equal("Save File Dialog", dialogForm.Title);
+ }
+
+ [Fact]
+ public void OpenFileDialog_ViewModel_Property()
+ {
+ var model = CreateSaveFileDialogModel();
+ var dialog = new SaveFileDialogStub(model);
+
+ Assert.NotNull(dialog.ViewModel);
+ Assert.Same(model, dialog.ViewModel);
+ }
+
+ private ISaveFileDialogViewModel CreateSaveFileDialogModel()
+ {
+ var model = new SaveFileDialogViewModel
+ {
+ AddExtension = true,
+ CheckFileExists = true,
+ CheckPathExists = true,
+ OverwritePrompt = true,
+ SupportMultiDottedExtensions = true,
+ DefaultExtension = "rlic",
+ Filter = "Rhino License Project|*.rlic",
+ InitialDirectory = "C:\\",
+ Title = "Save File Dialog",
+ };
+
+ return model;
+ }
+
+ public class SaveFileDialogStub : SaveFileDialog
+ {
+ public SaveFileDialogStub(ISaveFileDialogViewModel viewModel)
+ : base(viewModel)
+ {
+ }
+
+ public System.Windows.Forms.SaveFileDialog GetCoreDialog()
+ {
+ return base.Dialog as System.Windows.Forms.SaveFileDialog;
+ }
+ }
+ }
}
View
126 Rhino.Licensing.AdminTool/ViewModels/ProjectViewModel.cs
@@ -1,67 +1,61 @@
-using System.IO;
-using System.Security.Cryptography;
-using Caliburn.PresentationFramework.Filters;
-using Caliburn.PresentationFramework.Screens;
-using Rhino.Licensing.AdminTool.Extensions;
-using Rhino.Licensing.AdminTool.Factories;
-using Rhino.Licensing.AdminTool.Model;
-using Rhino.Licensing.AdminTool.Services;
-
-namespace Rhino.Licensing.AdminTool.ViewModels
-{
- public class ProjectViewModel : Screen
- {
- private Project _project;
- private readonly IProjectService _projectService;
- private readonly IDialogService _dialogService;
-
- public ProjectViewModel(
- IProjectService projectService,
- IDialogService dialogService)
- {
- _projectService = projectService;
- _dialogService = dialogService;
- }
-
- public virtual Project CurrentProject
- {
- get { return _project; }
- set
- {
- _project = value;
- NotifyOfPropertyChange(() => CurrentProject);
- }
- }
-
- public virtual void GenerateKey()
- {
- var key = RSA.Create();
-
- CurrentProject.Product.PublicKey = key.ToXmlString(false);
- CurrentProject.Product.PrivateKey = key.ToXmlString(true);
- }
-
- public virtual bool CanSave()
- {
- return CurrentProject.Product != null &&
- CurrentProject.Product.Name.IsNotEmpty();
- }
-
- [AutoCheckAvailability]
- public virtual void Save()
- {
- var dialog = new SaveFileDialogViewModel();
- var result = _dialogService.ShowSaveFileDialog(dialog);
-
- if (result.GetValueOrDefault(false))
- {
- _projectService.Save(CurrentProject, new FileInfo(dialog.FileName));
- }
- }
-
- public override void TryClose(bool? dialogResult)
- {
- base.TryClose(dialogResult);
- }
- }
+using System.IO;
+using System.Security.Cryptography;
+using Caliburn.PresentationFramework.Filters;
+using Caliburn.PresentationFramework.Screens;
+using Rhino.Licensing.AdminTool.Extensions;
+using Rhino.Licensing.AdminTool.Model;
+using Rhino.Licensing.AdminTool.Services;
+
+namespace Rhino.Licensing.AdminTool.ViewModels
+{
+ public class ProjectViewModel : Screen
+ {
+ private Project _project;
+ private readonly IProjectService _projectService;
+ private readonly IDialogService _dialogService;
+
+ public ProjectViewModel(
+ IProjectService projectService,
+ IDialogService dialogService)
+ {
+ _projectService = projectService;
+ _dialogService = dialogService;
+ }
+
+ public virtual Project CurrentProject
+ {
+ get { return _project; }
+ set
+ {
+ _project = value;
+ NotifyOfPropertyChange(() => CurrentProject);
+ }
+ }
+
+ public virtual void GenerateKey()
+ {
+ var key = RSA.Create();
+
+ CurrentProject.Product.PublicKey = key.ToXmlString(false);
+ CurrentProject.Product.PrivateKey = key.ToXmlString(true);
+ }
+
+ public virtual bool CanSave()
+ {
+ return CurrentProject.Product != null &&
+ CurrentProject.Product.Name.IsNotEmpty();
+ }
+
+ [AutoCheckAvailability]
+ public virtual void Save()
+ {
+ var dialog = new SaveFileDialogViewModel();
+ var result = _dialogService.ShowSaveFileDialog(dialog);
+
+ if (result.GetValueOrDefault(false))
+ {
+ _projectService.Save(CurrentProject, new FileInfo(dialog.FileName));
+ }
+ }
+ }
}

0 comments on commit 6b57193

Please sign in to comment.
Something went wrong with that request. Please try again.