Skip to content
Browse files

CDT-28: Delete profile functionality

Move CDTag.View namespace to CDTag.Views
Add GetInputWindow
  • Loading branch information...
1 parent 6a441b9 commit 82bdb25f2c297c19b0a3a6a979f7936d07a86dcf @judwhite committed
Showing with 301 additions and 82 deletions.
  1. +1 −1 CDTag.Common/ApplicationServices/IDialogService.cs
  2. +1 −1 CDTag.Common/Events/MessageBoxEvent.cs
  3. +4 −0 CDTag.Common/MVVM/ViewModelBase.cs
  4. +0 −1 CDTag.Model/Settings/SettingsFile.cs
  5. +1 −1 CDTag.View.Interfaces/About/IAboutWindow.cs
  6. +1 −0 CDTag.View.Interfaces/CDTag.View.Interfaces.csproj
  7. +1 −1 CDTag.View.Interfaces/Checksum/IChecksumWindow.cs
  8. +1 −1 CDTag.View.Interfaces/Checksum/IVerifyEACLogWindow.cs
  9. +9 −0 CDTag.View.Interfaces/General/IGetInputWindow.cs
  10. +1 −1 CDTag.View.Interfaces/IWindow.cs
  11. +1 −1 CDTag.View.Interfaces/Options/IOptionsWindow.cs
  12. +1 −1 CDTag.View.Interfaces/Profile/EditProfile/IEditProfileWindow.cs
  13. +1 −1 CDTag.View.Interfaces/Profile/NewProfile/INewProfileWindow.cs
  14. +1 −1 CDTag.View.Interfaces/Tag/EditTag/IEditTagWindow.cs
  15. +1 −1 CDTag.View.Interfaces/Tag/MassTag/IMassTagWindow.cs
  16. +1 −1 CDTag.View.Interfaces/Tag/TagAlbum/ITagAlbumWindow.cs
  17. +1 −1 CDTag.View.Interfaces/Tools/IEncodingInspectorWindow.cs
  18. +1 −1 CDTag.View.Interfaces/Tools/ISplitCueWindow.cs
  19. +2 −2 CDTag.View/About/AboutWindow.xaml.cs
  20. +7 −0 CDTag.View/CDTag.View.csproj
  21. +2 −2 CDTag.View/Checksum/ChecksumWindow.xaml.cs
  22. +2 −2 CDTag.View/Checksum/VerifyEACLogWindow.xaml.cs
  23. +2 −3 CDTag.View/DialogService.cs
  24. +42 −0 CDTag.View/General/GetInputWindow.xaml
  25. +15 −0 CDTag.View/General/GetInputWindow.xaml.cs
  26. +2 −2 CDTag.View/Options/OptionsWindow.xaml.cs
  27. +5 −4 CDTag.View/Profile/EditProfile/EditProfileWindow.xaml
  28. +2 −2 CDTag.View/Profile/EditProfile/EditProfileWindow.xaml.cs
  29. +1 −1 CDTag.View/Profile/NewProfile/NewProfileWindow.xaml.cs
  30. +1 −1 CDTag.View/Tag/EditTag/ID3v2Window.xaml.cs
  31. +2 −2 CDTag.View/Tag/MassTag/MassTagWindow.xaml.cs
  32. +2 −2 CDTag.View/Tag/TagAlbum/TagAlbumWindow.xaml.cs
  33. +2 −2 CDTag.View/Tools/EncodingInspectorWindow.xaml.cs
  34. +2 −2 CDTag.View/Tools/SplitCueWindow.xaml.cs
  35. +1 −2 CDTag.View/WindowViewBase.cs
  36. +51 −4 CDTag.ViewModel/Profile/EditProfile/EditProfileViewModel.cs
  37. +9 −9 CDTag.ViewModel/Tag/TagViewModel.cs
  38. +0 −7 CDTag/App.xaml.cs
  39. +9 −9 CDTag/Bootstrapper.cs
  40. +111 −7 Tests/CDTag.ViewModel.Tests/Profile/EditProfile/EditProfileViewModelTests.cs
  41. +1 −2 Tests/CDTag.ViewModel.Tests/UnitTestDialogService.cs
View
2 CDTag.Common/ApplicationServices/IDialogService.cs
@@ -1,6 +1,6 @@
using System;
using CDTag.Common.Wpf;
-using CDTag.View.Interfaces;
+using CDTag.Views.Interfaces;
namespace CDTag.Common.ApplicationServices
{
View
2 CDTag.Common/Events/MessageBoxEvent.cs
@@ -1,5 +1,5 @@
using System.Windows;
-using CDTag.View.Interfaces;
+using CDTag.Views.Interfaces;
namespace CDTag.Common.Events
{
View
4 CDTag.Common/MVVM/ViewModelBase.cs
@@ -52,6 +52,9 @@ public abstract class ViewModelBase : IViewModelBase
/// <summary>Path service.</summary>
protected static readonly IPathService _pathService;
+ /// <summary>Dialog service.</summary>
+ protected static readonly IDialogService _dialogService;
+
/// <summary>Occurs when a property value changes.</summary>
public event PropertyChangedEventHandler PropertyChanged;
@@ -67,6 +70,7 @@ static ViewModelBase()
{
_dispatcher = IoC.Resolve<IDispatcher>();
_pathService = IoC.Resolve<IPathService>();
+ _dialogService = IoC.Resolve<IDialogService>();
}
/// <summary>
View
1 CDTag.Model/Settings/SettingsFile.cs
@@ -3,7 +3,6 @@
using System.Text;
using CDTag.Common.ApplicationServices;
using CDTag.Common.Json;
-using CDTag.View;
namespace CDTag.Common.Settings
{
View
2 CDTag.View.Interfaces/About/IAboutWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.About
+namespace CDTag.Views.Interfaces.About
{
/// <summary>
/// IAboutWindow
View
1 CDTag.View.Interfaces/CDTag.View.Interfaces.csproj
@@ -52,6 +52,7 @@
<Compile Include="About\IAboutWindow.cs" />
<Compile Include="Checksum\IChecksumWindow.cs" />
<Compile Include="Checksum\IVerifyEACLogWindow.cs" />
+ <Compile Include="General\IGetInputWindow.cs" />
<Compile Include="IWindow.cs" />
<Compile Include="Options\IOptionsWindow.cs" />
<Compile Include="Profile\EditProfile\IEditProfileWindow.cs" />
View
2 CDTag.View.Interfaces/Checksum/IChecksumWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Checksum
+namespace CDTag.Views.Interfaces.Checksum
{
/// <summary>
/// IChecksumWindow
View
2 CDTag.View.Interfaces/Checksum/IVerifyEACLogWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Checksum
+namespace CDTag.Views.Interfaces.Checksum
{
/// <summary>
/// IVerifyEACLogWindow
View
9 CDTag.View.Interfaces/General/IGetInputWindow.cs
@@ -0,0 +1,9 @@
+namespace CDTag.Views.Interfaces.General
+{
+ /// <summary>
+ /// IGetInputWindow
+ /// </summary>
+ public interface IGetInputWindow : IWindow
+ {
+ }
+}
View
2 CDTag.View.Interfaces/IWindow.cs
@@ -1,6 +1,6 @@
using System.Windows;
-namespace CDTag.View.Interfaces
+namespace CDTag.Views.Interfaces
{
/// <summary>
/// IWindow
View
2 CDTag.View.Interfaces/Options/IOptionsWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Options
+namespace CDTag.Views.Interfaces.Options
{
/// <summary>
/// IOptionsWindow
View
2 CDTag.View.Interfaces/Profile/EditProfile/IEditProfileWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Profile.EditProfile
+namespace CDTag.Views.Interfaces.Profile.EditProfile
{
/// <summary>
/// IEditProfileWindow
View
2 CDTag.View.Interfaces/Profile/NewProfile/INewProfileWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Profile.NewProfile
+namespace CDTag.Views.Interfaces.Profile.NewProfile
{
/// <summary>
/// INewProfileWindow
View
2 CDTag.View.Interfaces/Tag/EditTag/IEditTagWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Tag.EditTag
+namespace CDTag.Views.Interfaces.Tag.EditTag
{
/// <summary>
/// IEditTagWindow
View
2 CDTag.View.Interfaces/Tag/MassTag/IMassTagWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Tag.MassTag
+namespace CDTag.Views.Interfaces.Tag.MassTag
{
/// <summary>
/// IMassTagWindow
View
2 CDTag.View.Interfaces/Tag/TagAlbum/ITagAlbumWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Tag.TagAlbum
+namespace CDTag.Views.Interfaces.Tag.TagAlbum
{
/// <summary>
/// ITagAlbumWindow
View
2 CDTag.View.Interfaces/Tools/IEncodingInspectorWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Tools
+namespace CDTag.Views.Interfaces.Tools
{
/// <summary>
/// IEncodingInspectorWindow
View
2 CDTag.View.Interfaces/Tools/ISplitCueWindow.cs
@@ -1,4 +1,4 @@
-namespace CDTag.View.Interfaces.Tools
+namespace CDTag.Views.Interfaces.Tools
{
/// <summary>
/// ISplitCueWindow
View
4 CDTag.View/About/AboutWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.About;
-using CDTag.ViewModels.About;
+using CDTag.ViewModels.About;
+using CDTag.Views.Interfaces.About;
namespace CDTag.Views.About
{
View
7 CDTag.View/CDTag.View.csproj
@@ -86,6 +86,9 @@
<Compile Include="Converters\PlayLengthConverter.cs" />
<Compile Include="Converters\ShortFileNameConverter.cs" />
<Compile Include="DialogService.cs" />
+ <Compile Include="General\GetInputWindow.xaml.cs">
+ <DependentUpon>GetInputWindow.xaml</DependentUpon>
+ </Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
@@ -167,6 +170,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="General\GetInputWindow.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
View
4 CDTag.View/Checksum/ChecksumWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Checksum;
-using CDTag.ViewModels.Checksum;
+using CDTag.ViewModels.Checksum;
+using CDTag.Views.Interfaces.Checksum;
namespace CDTag.Views.Checksum
{
View
4 CDTag.View/Checksum/VerifyEACLogWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Checksum;
-using CDTag.ViewModels.Checksum;
+using CDTag.ViewModels.Checksum;
+using CDTag.Views.Interfaces.Checksum;
namespace CDTag.Views.Checksum
{
View
5 CDTag.View/DialogService.cs
@@ -8,11 +8,10 @@
using CDTag.Common.Wpf;
using CDTag.Controls;
using CDTag.FileBrowser.Events;
-using CDTag.View.Interfaces;
-using CDTag.Views;
+using CDTag.Views.Interfaces;
using Microsoft.Win32;
-namespace CDTag.View
+namespace CDTag.Views
{
public class DialogService : IDialogService
{
View
42 CDTag.View/General/GetInputWindow.xaml
@@ -0,0 +1,42 @@
+<Views:WindowViewBase
+ x:Class="CDTag.Views.General.GetInputWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:Views="clr-namespace:CDTag.Views"
+ Title="{Binding WindowTitle, Mode=OneWay}"
+ MinHeight="200"
+ MinWidth="200"
+ Height="200"
+ Width="350"
+ CurrentVisualState="{Binding CurrentVisualState}"
+ FocusManager.FocusedElement="{Binding ElementName=InputTextBox}"
+>
+ <Grid Margin="8">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+
+ <TextBlock Text="{Binding LabelText, Mode=OneWay}" Margin="0,0,8,0" />
+ <TextBox x:Name="InputTextBox" Text="{Binding InputValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" />
+
+ <Path Grid.Row="1" Grid.ColumnSpan="2" Data="M0,0 L1,0" Stroke="#CCCCCC" Stretch="Fill" Margin="0,8" />
+
+ <Grid Grid.Row="2" Grid.ColumnSpan="2" Grid.IsSharedSizeScope="True">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" SharedSizeGroup="BottomButtons" MinWidth="80" />
+ <ColumnDefinition Width="Auto" SharedSizeGroup="BottomButtons" MinWidth="80" />
+ </Grid.ColumnDefinitions>
+
+ <Button Grid.Column="1" Content="_OK" Command="{Binding OKCommand}" Padding="7,2" Margin="8,0,0,0" />
+ <Button Grid.Column="2" Content="_Cancel" IsCancel="True" Padding="7,2" Margin="8,0,0,0" />
+ </Grid>
+
+ </Grid>
+</Views:WindowViewBase>
View
15 CDTag.View/General/GetInputWindow.xaml.cs
@@ -0,0 +1,15 @@
+using CDTag.Views.Interfaces.General;
+
+namespace CDTag.Views.General
+{
+ /// <summary>
+ /// Interaction logic for GetInputWindow.xaml
+ /// </summary>
+ public partial class GetInputWindow : WindowViewBase, IGetInputWindow
+ {
+ public GetInputWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
View
4 CDTag.View/Options/OptionsWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Options;
-using CDTag.ViewModel.Options;
+using CDTag.ViewModel.Options;
+using CDTag.Views.Interfaces.Options;
namespace CDTag.Views.Options
{
View
9 CDTag.View/Profile/EditProfile/EditProfileWindow.xaml
@@ -1,13 +1,14 @@
-<Views:WindowViewBase
+<Views:WindowViewBase
x:Class="CDTag.Views.Profile.EditProfile.EditProfileWindow"
x:Name="editProfileWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:Views="clr-namespace:CDTag.Views" xmlns:EditProfile="clr-namespace:CDTag.Views.Profile.EditProfile"
+ xmlns:Views="clr-namespace:CDTag.Views"
+ xmlns:EditProfile="clr-namespace:CDTag.Views.Profile.EditProfile"
Title="{Binding WindowTitle, Mode=OneWay}"
- MinHeight="540"
+ MinHeight="540"
MinWidth="600"
- Height="580"
+ Height="580"
Width="780"
CurrentVisualState="{Binding CurrentVisualState}"
FocusManager.FocusedElement="{Binding ElementName=ProfileNameTextBox}"
View
4 CDTag.View/Profile/EditProfile/EditProfileWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Profile.EditProfile;
-using CDTag.ViewModels.Profile.EditProfile;
+using CDTag.ViewModels.Profile.EditProfile;
+using CDTag.Views.Interfaces.Profile.EditProfile;
namespace CDTag.Views.Profile.EditProfile
{
View
2 CDTag.View/Profile/NewProfile/NewProfileWindow.xaml.cs
@@ -1,6 +1,6 @@
using System;
-using CDTag.View.Interfaces.Profile.NewProfile;
using CDTag.ViewModels.Profile.NewProfile;
+using CDTag.Views.Interfaces.Profile.NewProfile;
namespace CDTag.Views.Profile.NewProfile
{
View
2 CDTag.View/Tag/EditTag/ID3v2Window.xaml.cs
@@ -1,7 +1,7 @@
using System.Windows;
using CDTag.Model.Tag;
-using CDTag.View.Interfaces.Tag.EditTag;
using CDTag.ViewModels.Tag.EditTag;
+using CDTag.Views.Interfaces.Tag.EditTag;
using IdSharp.Common.Events;
using Microsoft.Win32;
View
4 CDTag.View/Tag/MassTag/MassTagWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Tag.MassTag;
-using CDTag.ViewModels.Tag.MassTag;
+using CDTag.ViewModels.Tag.MassTag;
+using CDTag.Views.Interfaces.Tag.MassTag;
namespace CDTag.Views.Tag.MassTag
{
View
4 CDTag.View/Tag/TagAlbum/TagAlbumWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Tag.TagAlbum;
-using CDTag.ViewModels.Tag.TagAlbum;
+using CDTag.ViewModels.Tag.TagAlbum;
+using CDTag.Views.Interfaces.Tag.TagAlbum;
namespace CDTag.Views.Tag.TagAlbum
{
View
4 CDTag.View/Tools/EncodingInspectorWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Tools;
-using CDTag.ViewModels.Tools;
+using CDTag.ViewModels.Tools;
+using CDTag.Views.Interfaces.Tools;
namespace CDTag.Views.Tools
{
View
4 CDTag.View/Tools/SplitCueWindow.xaml.cs
@@ -1,5 +1,5 @@
-using CDTag.View.Interfaces.Tools;
-using CDTag.ViewModels.Tools;
+using CDTag.ViewModels.Tools;
+using CDTag.Views.Interfaces.Tools;
namespace CDTag.Views.Tools
{
View
3 CDTag.View/WindowViewBase.cs
@@ -3,11 +3,10 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
-using CDTag.Common;
using CDTag.Common.Events;
using CDTag.Common.Mvvm;
using CDTag.Common.Settings;
-using CDTag.View.Interfaces;
+using CDTag.Views.Interfaces;
using IdSharp.Common.Events;
namespace CDTag.Views
View
55 CDTag.ViewModel/Profile/EditProfile/EditProfileViewModel.cs
@@ -3,8 +3,8 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Windows;
using System.Windows.Input;
-using CDTag.Common;
using CDTag.Common.ApplicationServices;
using CDTag.Common.Events;
using CDTag.Common.Mvvm;
@@ -31,7 +31,7 @@ public EditProfileViewModel(IEventAggregator eventAggregator)
_profiles = new ObservableCollection<UserProfile>();
- string[] files = Directory.GetFiles(_pathService.ProfileDirectory, "*.cfg");
+ string[] files = Directory.GetFiles(_pathService.ProfileDirectory, "*.cfg").OrderBy(p => p.ToLower()).ToArray();
foreach (string file in files)
{
try
@@ -45,9 +45,14 @@ public EditProfileViewModel(IEventAggregator eventAggregator)
}
}
+ if (_profiles.Count == 0)
+ {
+ CreateDefaultProfile();
+ }
+
EnhancedPropertyChanged += EditProfileViewModel_EnhancedPropertyChanged;
- Profile = _profiles.FirstOrDefault();
+ Profile = _profiles.First();
Header = "Select Profile";
UpdateWindowTitle();
}
@@ -144,7 +149,49 @@ private void CopyProfile()
private void DeleteProfile()
{
- throw new NotImplementedException();
+ var profile = Profile;
+ if (profile == null)
+ return;
+
+ string messageBoxText = string.Format("Do you want to delete the {0} profile?", profile.ProfileName);
+ if (_profiles.Count == 1)
+ {
+ messageBoxText += string.Format("{0}{0}If you delete this profile a Default profile will be created.", Environment.NewLine);
+ }
+
+ var result = MessageBox(messageBoxText, "Delete profile", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ if (result != MessageBoxResult.Yes)
+ return;
+
+ File.Delete(profile.GetProfileFileName());
+
+ Profile = null;
+
+ int index = _profiles.IndexOf(profile);
+ _profiles.RemoveAt(index);
+
+ if (_profiles.Count > 0)
+ {
+ if (index >= _profiles.Count)
+ index = _profiles.Count - 1;
+
+ Profile = _profiles[index];
+ }
+ else
+ {
+ Profile = CreateDefaultProfile();
+ }
+ }
+
+ private UserProfile CreateDefaultProfile()
+ {
+ UserProfile profile = new UserProfile();
+ profile.ProfileName = "Default";
+ profile.Save();
+
+ _profiles.Add(profile);
+
+ return profile;
}
public ObservableCollection<UserProfile> Profiles
View
18 CDTag.ViewModel/Tag/TagViewModel.cs
@@ -5,16 +5,16 @@
using CDTag.Common.Events;
using CDTag.Common.Mvvm;
using CDTag.FileBrowser.ViewModel;
-using CDTag.View.Interfaces.About;
-using CDTag.View.Interfaces.Checksum;
-using CDTag.View.Interfaces.Options;
-using CDTag.View.Interfaces.Profile.EditProfile;
-using CDTag.View.Interfaces.Profile.NewProfile;
-using CDTag.View.Interfaces.Tag.EditTag;
-using CDTag.View.Interfaces.Tag.MassTag;
-using CDTag.View.Interfaces.Tag.TagAlbum;
-using CDTag.View.Interfaces.Tools;
using CDTag.ViewModels.Events;
+using CDTag.Views.Interfaces.About;
+using CDTag.Views.Interfaces.Checksum;
+using CDTag.Views.Interfaces.Options;
+using CDTag.Views.Interfaces.Profile.EditProfile;
+using CDTag.Views.Interfaces.Profile.NewProfile;
+using CDTag.Views.Interfaces.Tag.EditTag;
+using CDTag.Views.Interfaces.Tag.MassTag;
+using CDTag.Views.Interfaces.Tag.TagAlbum;
+using CDTag.Views.Interfaces.Tools;
namespace CDTag.ViewModels.Tag
{
View
7 CDTag/App.xaml.cs
@@ -1,15 +1,8 @@
using System;
-using System.IO;
using System.Windows;
-using System.Windows.Controls;
using System.Windows.Threading;
using CDTag.Common;
using CDTag.Common.ApplicationServices;
-using CDTag.Controls;
-using CDTag.FileBrowser.Events;
-using CDTag.View;
-using CDTag.View.Interfaces;
-using CDTag.Views;
namespace CDTag
{
View
18 CDTag/Bootstrapper.cs
@@ -5,15 +5,6 @@
using CDTag.Common.Events;
using CDTag.FileBrowser.ViewModel;
using CDTag.View;
-using CDTag.View.Interfaces.About;
-using CDTag.View.Interfaces.Checksum;
-using CDTag.View.Interfaces.Options;
-using CDTag.View.Interfaces.Profile.EditProfile;
-using CDTag.View.Interfaces.Profile.NewProfile;
-using CDTag.View.Interfaces.Tag.EditTag;
-using CDTag.View.Interfaces.Tag.MassTag;
-using CDTag.View.Interfaces.Tag.TagAlbum;
-using CDTag.View.Interfaces.Tools;
using CDTag.ViewModel.Options;
using CDTag.ViewModels.About;
using CDTag.ViewModels.Checksum;
@@ -27,6 +18,15 @@
using CDTag.Views;
using CDTag.Views.About;
using CDTag.Views.Checksum;
+using CDTag.Views.Interfaces.About;
+using CDTag.Views.Interfaces.Checksum;
+using CDTag.Views.Interfaces.Options;
+using CDTag.Views.Interfaces.Profile.EditProfile;
+using CDTag.Views.Interfaces.Profile.NewProfile;
+using CDTag.Views.Interfaces.Tag.EditTag;
+using CDTag.Views.Interfaces.Tag.MassTag;
+using CDTag.Views.Interfaces.Tag.TagAlbum;
+using CDTag.Views.Interfaces.Tools;
using CDTag.Views.Options;
using CDTag.Views.Profile.EditProfile;
using CDTag.Views.Profile.NewProfile;
View
118 Tests/CDTag.ViewModel.Tests/Profile/EditProfile/EditProfileViewModelTests.cs
@@ -1,11 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
+using System.IO;
+using System.Windows;
using CDTag.Common;
using CDTag.Common.ApplicationServices;
using CDTag.Common.Dispatcher;
+using CDTag.Model.Profile;
using CDTag.ViewModels.Profile.EditProfile;
using NUnit.Framework;
@@ -15,7 +13,12 @@ namespace CDTag.ViewModel.Tests.Profile.EditProfile
public class EditProfileViewModelTests
{
private const string _profileName = "unittests";
+ private const string _profileName2 = "unittests2";
+ private const string _profileName3 = "unittests3";
+ private string _defaultProfile;
private string _unitTestsProfile;
+ private string _unitTestsProfile2;
+ private string _unitTestsProfile3;
private string _unitTestsNFO;
[TestFixtureSetUp]
@@ -28,7 +31,10 @@ public void Setup()
IoC.RegisterInstance<IDialogService>(new UnitTestDialogService());
string profileDirectory = IoC.Resolve<IPathService>().ProfileDirectory;
+ _defaultProfile = Path.Combine(profileDirectory, "Default.cfg");
_unitTestsProfile = Path.Combine(profileDirectory, _profileName + ".cfg");
+ _unitTestsProfile2 = Path.Combine(profileDirectory, _profileName2 + ".cfg");
+ _unitTestsProfile3 = Path.Combine(profileDirectory, _profileName3 + ".cfg");
_unitTestsNFO = Path.Combine(profileDirectory, _profileName + ".nfo");
DeleteUnitTestsProfile();
@@ -42,8 +48,14 @@ public void Teardown()
private void DeleteUnitTestsProfile()
{
+ if (File.Exists(_defaultProfile))
+ File.Delete(_defaultProfile);
if (File.Exists(_unitTestsProfile))
File.Delete(_unitTestsProfile);
+ if (File.Exists(_unitTestsProfile2))
+ File.Delete(_unitTestsProfile2);
+ if (File.Exists(_unitTestsProfile3))
+ File.Delete(_unitTestsProfile3);
if (File.Exists(_unitTestsNFO))
File.Delete(_unitTestsNFO);
}
@@ -52,6 +64,8 @@ private void DeleteUnitTestsProfile()
public void ConstructorTest()
{
// Arrange/Act
+ DeleteUnitTestsProfile();
+
EditProfileViewModel editProfileViewModel = IoC.Resolve<EditProfileViewModel>();
// Assert
@@ -61,9 +75,99 @@ public void ConstructorTest()
Assert.That(editProfileViewModel.NewProfileCommand, Is.Not.Null, "editProfileViewModel.NewProfileCommand");
Assert.That(editProfileViewModel.RenameProfileCommand, Is.Not.Null, "editProfileViewModel.RenameProfileCommand");
Assert.That(editProfileViewModel.Profiles, Is.Not.Null, "editProfileViewModel.Profiles");
- Assert.That(editProfileViewModel.Profile, Is.Null, "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profiles.Count, Is.EqualTo(1), "editProfileViewModel.Profiles.Count");
+ Assert.That(editProfileViewModel.Profile, Is.Not.Null, "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profile.ProfileName, Is.EqualTo("Default"), "editProfileViewModel.Profile");
Assert.That(editProfileViewModel.Header, Is.EqualTo("Select Profile"), "editProfileViewModel.Header");
- Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile"), "editProfileViewModel.Header");
+ Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile - Default"), "editProfileViewModel.WindowTitle");
+ Assert.That(File.Exists(_defaultProfile), Is.True, "File.Exists(_defaultProfile)");
+ }
+
+ [Test]
+ public void DeleteProfileTest()
+ {
+ // Arrange
+ DeleteUnitTestsProfile();
+
+ UserProfile profile = new UserProfile();
+ profile.ProfileName = _profileName;
+ profile.Save();
+
+ profile = new UserProfile();
+ profile.ProfileName = _profileName2;
+ profile.Save();
+
+ profile = new UserProfile();
+ profile.ProfileName = _profileName3;
+ profile.Save();
+
+ EditProfileViewModel editProfileViewModel = IoC.Resolve<EditProfileViewModel>();
+ bool confirmationShown = false;
+ editProfileViewModel.ShowMessageBox += (sender, args) => { confirmationShown = true; args.Data.Result = MessageBoxResult.Yes; }; // delete confirmation
+ var profiles = editProfileViewModel.Profiles;
+
+ Assert.That(profiles.Count, Is.EqualTo(3), "profiles.Count");
+ Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile - " + _profileName), "editProfileViewModel.WindowTitle");
+
+ // Act - Delete 2nd of 3 profiles
+ var deleteProfile = profiles[1];
+ editProfileViewModel.Profile = deleteProfile;
+ editProfileViewModel.DeleteProfileCommand.Execute(null);
+
+ // Assert
+ Assert.That(confirmationShown, Is.True, "confirmationShown");
+ Assert.That(editProfileViewModel.Profiles, Is.EqualTo(profiles), "editProfileViewModel.Profiles");
+ Assert.That(editProfileViewModel.Profiles.Count, Is.EqualTo(2), "editProfileViewModel.Profiles.Count");
+ Assert.That(editProfileViewModel.Profile, Is.Not.Null, "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profile, Is.EqualTo(profiles[1]), "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profiles.Contains(deleteProfile), Is.False, "editProfileViewModel.Profiles.Contains(deleteProfile)");
+ Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile - " + _profileName3), "editProfileViewModel.WindowTitle");
+ Assert.That(File.Exists(_defaultProfile), Is.False, "File.Exists(_defaultProfile)");
+ Assert.That(File.Exists(_unitTestsProfile), Is.True, "File.Exists(_unitTestsProfile)");
+ Assert.That(File.Exists(_unitTestsProfile2), Is.False, "File.Exists(_unitTestsProfile2)");
+ Assert.That(File.Exists(_unitTestsProfile3), Is.True, "File.Exists(_unitTestsProfile3)");
+
+ // Arrange
+ confirmationShown = false;
+
+ // Act - Delete 2nd of 2 profiles
+ deleteProfile = profiles[1];
+ editProfileViewModel.Profile = deleteProfile;
+ editProfileViewModel.DeleteProfileCommand.Execute(null);
+
+ // Assert
+ Assert.That(confirmationShown, Is.True, "confirmationShown");
+ Assert.That(editProfileViewModel.Profiles, Is.EqualTo(profiles), "editProfileViewModel.Profiles");
+ Assert.That(editProfileViewModel.Profiles.Count, Is.EqualTo(1), "editProfileViewModel.Profiles.Count");
+ Assert.That(editProfileViewModel.Profile, Is.Not.Null, "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profile, Is.EqualTo(profiles[0]), "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profiles.Contains(deleteProfile), Is.False, "editProfileViewModel.Profiles.Contains(deleteProfile)");
+ Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile - " + _profileName), "editProfileViewModel.WindowTitle");
+ Assert.That(File.Exists(_defaultProfile), Is.False, "File.Exists(_defaultProfile)");
+ Assert.That(File.Exists(_unitTestsProfile), Is.True, "File.Exists(_unitTestsProfile)");
+ Assert.That(File.Exists(_unitTestsProfile2), Is.False, "File.Exists(_unitTestsProfile2)");
+ Assert.That(File.Exists(_unitTestsProfile3), Is.False, "File.Exists(_unitTestsProfile3)");
+
+ // Arrange
+ confirmationShown = false;
+
+ // Act - Delete last remaining profile in list
+ deleteProfile = profiles[0];
+ editProfileViewModel.Profile = deleteProfile;
+ editProfileViewModel.DeleteProfileCommand.Execute(null);
+
+ // Assert
+ Assert.That(confirmationShown, Is.True, "confirmationShown");
+ Assert.That(editProfileViewModel.Profiles, Is.EqualTo(profiles), "editProfileViewModel.Profiles");
+ Assert.That(editProfileViewModel.Profiles.Count, Is.EqualTo(1), "editProfileViewModel.Profiles.Count");
+ Assert.That(editProfileViewModel.Profile, Is.Not.Null, "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.Profiles.Contains(deleteProfile), Is.False, "editProfileViewModel.Profiles.Contains(deleteProfile)");
+ Assert.That(editProfileViewModel.Profile.ProfileName, Is.EqualTo("Default"), "editProfileViewModel.Profile");
+ Assert.That(editProfileViewModel.WindowTitle, Is.EqualTo("Edit Profile - Default"), "editProfileViewModel.WindowTitle");
+ Assert.That(File.Exists(_defaultProfile), Is.True, "File.Exists(_defaultProfile)");
+ Assert.That(File.Exists(_unitTestsProfile), Is.False, "File.Exists(_unitTestsProfile)");
+ Assert.That(File.Exists(_unitTestsProfile2), Is.False, "File.Exists(_unitTestsProfile2)");
+ Assert.That(File.Exists(_unitTestsProfile3), Is.False, "File.Exists(_unitTestsProfile3)");
}
}
}
View
3 Tests/CDTag.ViewModel.Tests/UnitTestDialogService.cs
@@ -1,8 +1,7 @@
using System;
-using CDTag.Common;
using CDTag.Common.ApplicationServices;
using CDTag.Common.Wpf;
-using CDTag.View.Interfaces;
+using CDTag.Views.Interfaces;
namespace CDTag.ViewModel.Tests
{

0 comments on commit 82bdb25

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