diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate.sln b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate.sln new file mode 100644 index 000000000..f94f3c44a --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate.sln @@ -0,0 +1,67 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{658BD492-33FF-4995-AAE7-4F6894E92F0C}" + ProjectSection(SolutionItems) = preProject + MVVM_Tutorial.props = MVVM_Tutorial.props + MVVM_Tutorial_net.props = MVVM_Tutorial_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLib", "..\Libraries\MVVM_BaseLib\MVVM_BaseLib.csproj", "{890CF504-3814-443B-9EE6-E8BCACF68203}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{AF041458-CF94-4D6D-BB0F-8BC50F4F099C}" + ProjectSection(SolutionItems) = preProject + ..\Libraries\Libraries_net.props = ..\Libraries\Libraries_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLibTests", "..\Libraries\MVVM_BaseLibTests\MVVM_BaseLibTests.csproj", "{66EB60F2-523D-47C8-95EA-C7E10759E239}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00_IoCTemplate", "MVVM_00_IoCTemplate\MVVM_00_IoCTemplate.csproj", "{16A3E367-674C-4959-8B31-7681B0E8258C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00_IoCTemplate_net", "MVVM_00_IoCTemplate\MVVM_00_IoCTemplate_net.csproj", "{D6BFC652-822A-4E7D-9846-7F529C584BAC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00_IoCTemplate_netTests", "MVVM_00_IoCTemplateTests\MVVM_00_IoCTemplate_netTests.csproj", "{A7844F45-74D9-4A81-9C27-D0E17ED0F851}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00_IoCTemplateTests", "MVVM_00_IoCTemplateTests\MVVM_00_IoCTemplateTests.csproj", "{7FF12BBB-AA2E-48C1-B283-0665570902F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.Build.0 = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.ActiveCfg = Release|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.Build.0 = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.Build.0 = Release|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Release|Any CPU.Build.0 = Release|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Release|Any CPU.Build.0 = Release|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Release|Any CPU.Build.0 = Release|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {890CF504-3814-443B-9EE6-E8BCACF68203} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + {66EB60F2-523D-47C8-95EA-C7E10759E239} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + EndGlobalSection +EndGlobal diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml new file mode 100644 index 000000000..5368ab7d6 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml.cs new file mode 100644 index 000000000..7f3666eef --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/App.xaml.cs @@ -0,0 +1,43 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using BaseLib.Helper; +using BaseLib.Interfaces; +using Microsoft.Extensions.DependencyInjection; +using MVVM.View.Extension; +using MVVM_00_IoCTemplate.Models; +using System.Windows; + +namespace MVVM_00_IoCTemplate +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + var sc = new ServiceCollection() + .AddTransient() + .AddTransient() + .AddSingleton(); + + var bc = sc.BuildServiceProvider(); + + IoC.Configure(bc); + } + } +} +namespace MVVM_00_IoCTemplate.Models { } +namespace MVVM_00_IoCTemplate.ValueConverter { } +namespace MVVM_00_IoCTemplate.Services { } diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/AssemblyInfo.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/AssemblyInfo.cs new file mode 100644 index 000000000..f60efc019 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate.csproj b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate.csproj new file mode 100644 index 000000000..efc29a6e2 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate.csproj @@ -0,0 +1,40 @@ + + + + WinExe + net462-windows;net472-windows;net48-windows;net481-windows + true + + + + + + + + + + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + PublicSettingsSingleFileGenerator + Settings.Designer.cs + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate_net.csproj b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate_net.csproj new file mode 100644 index 000000000..7ff0e1ee2 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MVVM_00_IoCTemplate_net.csproj @@ -0,0 +1,40 @@ + + + + WinExe + net6.0-windows;net7.0-windows;net8.0-windows + true + + + + + + + + + + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + PublicSettingsSingleFileGenerator + Settings.Designer.cs + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml new file mode 100644 index 000000000..940bfcbab --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml.cs new file mode 100644 index 000000000..2d22996d5 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/MainWindow.xaml.cs @@ -0,0 +1,31 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using System.Windows; + +namespace MVVM_00_IoCTemplate +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + /// + /// Initializes a new instance of the class. + /// + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/.info b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/.info new file mode 100644 index 000000000..62f215ed0 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/.info @@ -0,0 +1 @@ +Folder for Models diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/ITemplateModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/ITemplateModel.cs new file mode 100644 index 000000000..3c8f3652a --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/ITemplateModel.cs @@ -0,0 +1,41 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using System; +using System.ComponentModel; + +/// +/// The Models namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Models +{ + /// + /// Interface ITemplateModel + /// + /// + public interface ITemplateModel + { + /// + /// Gets the now. + /// + /// The now. + /// + DateTime Now { get; } + /// + /// Occurs when [property changed]. + /// + /// + event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/SimpleLog.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/SimpleLog.cs new file mode 100644 index 000000000..15d506808 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/SimpleLog.cs @@ -0,0 +1,29 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using BaseLib.Interfaces; +using System; +using System.Diagnostics; +using System.Globalization; + +namespace MVVM_00_IoCTemplate; + +public class SimpleLog(ISysTime sysTime):ILog +{ + ISysTime _sysTime { get; } = sysTime; + + public void Log(string message) + => Debug.WriteLine($"{_sysTime.Now.ToString(CultureInfo.InvariantCulture)}: Msg: {message}"); + public void Log(string message, Exception exception) + => Debug.WriteLine($"{_sysTime.Now.ToString(CultureInfo.InvariantCulture)}: Err: {message}, {exception}"); +} \ No newline at end of file diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/TemplateModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/TemplateModel.cs new file mode 100644 index 000000000..a7858bf58 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Models/TemplateModel.cs @@ -0,0 +1,82 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using BaseLib.Interfaces; +using CommunityToolkit.Mvvm.ComponentModel; +using System; +using System.Timers; + +/// +/// The Models namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Models +{ + /// + /// Class TemplateModel. + /// Implements the + /// Implements the + /// + /// + /// + /// + public partial class TemplateModel :ObservableObject, ITemplateModel + { + private const string csApplStart = "Application startet"; + private const string csApplEnded = "Application ended"; + #region Properties + /// + /// The timer + /// + /// + private readonly Timer _timer; + private readonly ISysTime _systime; + private readonly ILog _log; + + /// + /// Gets the now. + /// + /// The now. + /// + public DateTime Now { get => _systime.Now; } + #endregion + + #region Methods + /// + /// Initializes a new instance of the class. + /// + /// + public TemplateModel(ISysTime sysTime,ILog log) + { + _systime = sysTime; + _log = log; + _log.Log(csApplStart); + _timer = new(250d); + _timer.Elapsed += (s, e) => OnPropertyChanged(nameof(Now)); + _timer.Start(); + } + +#if !NET5_0_OR_GREATER + /// + /// Finalizes an instance of the class. + /// + ~TemplateModel() + { + _timer.Stop(); + _log.Log(csApplEnded); + return; + } +#endif + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.Designer.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.Designer.cs new file mode 100644 index 000000000..92a066657 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.Designer.cs @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace MVVM_00_IoCTemplate.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MVVM_00_IoCTemplate.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die MVVM-Template using Community-Toolkit ähnelt. + /// + public static string Description { + get { + return ResourceManager.GetString("Description", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die <Page + /// xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + /// xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + /// xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + /// xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + /// xmlns:local="clr-namespace:MVVM_00_IoCTemplate.Views" + /// xmlns:p="clr-namespace:MVVM_00_IoCTemplate.Properties" + /// xmlns:vc="clr-namespace:MVVM_00_IoCTemplate.ValueConverter" + /// xmlns:mvvm="clr-namespace: [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt. + /// + public static string TemplateView { + get { + return ResourceManager.GetString("TemplateView", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die // *********************************************************************** + ///// Assembly : MVVM_00_IoCTemplate + ///// Author : Mir + ///// Created : 08-11-2022 + ///// + ///// Last Modified By : Mir + ///// Last Modified On : 08-24-2022 + ///// *********************************************************************** + ///// <copyright file="MainWindowViewModel.cs" company="JC-Soft"> + ///// Copyright © JC-Soft 2022 + ///// </copyright> + ///// <summary></summary> + ///// ************************************************** [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt. + /// + public static string TemplateViewModel { + get { + return ResourceManager.GetString("TemplateViewModel", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die CT-Template-View ähnelt. + /// + public static string Title { + get { + return ResourceManager.GetString("Title", resourceCulture); + } + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.resx b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.resx new file mode 100644 index 000000000..9225fb660 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + MVVM-Template using Community-Toolkit + + + + ..\Views\TemplateView.xaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\ViewModels\TemplateViewModel.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + CT-Template-View + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.Designer.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.Designer.cs new file mode 100644 index 000000000..6e9522f70 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace MVVM_00_IoCTemplate.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")] + public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.settings b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.settings new file mode 100644 index 000000000..049245f40 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/.info b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/.info new file mode 100644 index 000000000..b4bc464df --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/.info @@ -0,0 +1 @@ +Folder for ValueConverters diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/DateTimeValueConverter.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/DateTimeValueConverter.cs new file mode 100644 index 000000000..6cefce616 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ValueConverters/DateTimeValueConverter.cs @@ -0,0 +1,63 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 07-03-2022 +// +// Last Modified By : Mir +// Last Modified On : 07-04-2022 +// *********************************************************************** +// +// Copyright (c) JC-Soft. All rights reserved. +// +// +// *********************************************************************** +using System; +using System.Globalization; +using System.Windows.Data; + +namespace MVVM_00_IoCTemplate.ValueConverter +{ + /// + /// Class CurrencyValueConverter. + /// Implements the + /// + /// + public class DateTimeValueConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// The value produced by the binding source. + /// The type of the binding target property. + /// The converter parameter to use. + /// The culture to use in the converter. + /// A converted value. If the method returns , the valid null value is used. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is DateTime dt) + if (parameter is string spar) + return dt.ToString(spar); + else + return dt.ToString(culture); + else + return value?.ToString() ?? ""; + + } + + /// + /// Converts a value. + /// + /// The value that is produced by the binding target. + /// The type to convert to. + /// The converter parameter to use. + /// The culture to use in the converter. + /// A converted value. If the method returns , the valid null value is used. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string sval && DateTime.TryParse(sval.Trim(),culture, DateTimeStyles.AssumeLocal, out var dt)) + return dt; + else + return DateTime.MinValue; + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/.info b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/.info new file mode 100644 index 000000000..a3ed848fb --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/.info @@ -0,0 +1 @@ +Folder for ViewModels diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/MainWindowViewModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/MainWindowViewModel.cs new file mode 100644 index 000000000..213f90b8d --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,47 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using MVVM.ViewModel; + +namespace MVVM_00_IoCTemplate.ViewModels +{ + /// + /// Class MainWindowViewModel. + /// Implements the + /// + /// + public class MainWindowViewModel : BaseViewModelCT + { + #region Properties + #endregion + #region Methods + /// + /// Initializes a new instance of the class. + /// + public MainWindowViewModel() + { + + } + +#if !NET5_0_OR_GREATER + /// + /// Finalizes an instance of the class. + /// + ~MainWindowViewModel() + { + return; + } +#endif + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/TemplateViewModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/TemplateViewModel.cs new file mode 100644 index 000000000..6930a67dc --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/ViewModels/TemplateViewModel.cs @@ -0,0 +1,56 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using MVVM.View.Extension; +using MVVM.ViewModel; +using MVVM_00_IoCTemplate.Models; +using System; +using System.ComponentModel; + +namespace MVVM_00_IoCTemplate.ViewModels +{ + /// + /// Class MainWindowViewModel. + /// Implements the + /// + /// + public partial class TemplateViewModel : BaseViewModelCT + { + #region Properties + private readonly ITemplateModel _model; + + public DateTime Now => _model.Now; + #endregion + + #region Methods + /// + /// Initializes a new instance of the class. + /// + public TemplateViewModel():this(IoC.GetRequiredService()) + { + } + + public TemplateViewModel(ITemplateModel model) + { + _model = model; + _model.PropertyChanged += OnMPropertyChanged; + } + + private void OnMPropertyChanged(object sender, PropertyChangedEventArgs e) + { + OnPropertyChanged(e.PropertyName); + } + + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/.info b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/.info new file mode 100644 index 000000000..65a00d680 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/.info @@ -0,0 +1 @@ +Folder for Views diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml new file mode 100644 index 000000000..caa70bcd9 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml.cs new file mode 100644 index 000000000..32ed87a07 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplate/Views/TemplateView.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace MVVM_00_IoCTemplate.Views +{ + /// + /// Interaktionslogik für TemplateView.xaml + /// + public partial class TemplateView : Page + { + public TemplateView() + { + InitializeComponent(); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/AppTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/AppTests.cs new file mode 100644 index 000000000..8deb9a6c3 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/AppTests.cs @@ -0,0 +1,63 @@ +using BaseLib.Interfaces; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MVVM.View.Extension; +using MVVM_00_IoCTemplate.Models; +using NSubstitute; +using System; + +namespace MVVM_00_IoCTemplate.Tests +{ + internal class TestApp : App + { + public void DoStartUp() + { + OnStartup(null); + } + } + [TestClass()] + public class AppTests + { + static TestApp app = new(); + private Func _gsold; + private Func _grsold; + private ISysTime _sysTime; + private ILog _log; + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + _gsold = IoC.GetSrv; + _grsold = IoC.GetReqSrv; + IoC.GetReqSrv = (t) =>t switch { + _ when t == typeof(ILog) => _log ??= Substitute.For(), + _ when t == typeof(ISysTime) => _sysTime ??= Substitute.For(), + _ when t == typeof(ITemplateModel) => new TemplateModel(IoC.GetRequiredService(),IoC.GetRequiredService), + _ => throw new ArgumentException() }; + } + + [TestCleanup] + public void CleanUp() + { + IoC.GetSrv = _gsold; + IoC.GetReqSrv = _grsold; + } + + [TestMethod] + public void AppTest() + { + Assert.IsNotNull(app); + } + + [TestMethod] + public void AppTest2() + { + app.DoStartUp(); + Assert.IsNotNull(IoC.GetReqSrv(typeof(ITemplateModel))); + Assert.IsNull(IoC.GetSrv(typeof(App))); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplateTests.csproj b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplateTests.csproj new file mode 100644 index 000000000..6a44a0074 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplateTests.csproj @@ -0,0 +1,25 @@ + + + + net462-windows;net472-windows;net48-windows;net481-windows + true + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplate_netTests.csproj b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplate_netTests.csproj new file mode 100644 index 000000000..cb864bb06 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/MVVM_00_IoCTemplate_netTests.csproj @@ -0,0 +1,25 @@ + + + + net6.0-windows;net7.0-windows;net8.0-windows + true + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Models/TemplateModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Models/TemplateModelTests.cs new file mode 100644 index 000000000..125f90e03 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Models/TemplateModelTests.cs @@ -0,0 +1,67 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplateTests +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MVVM.ViewModel; +using System.ComponentModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Models.Tests +{ + /// + /// Defines test class TemplateModelTests. + /// Implements the + /// + /// + /// + [TestClass()] + public class TemplateModelTests : BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + TemplateModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchgn) + npchgn.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(TemplateModel)); + Assert.IsInstanceOfType(testModel, typeof(ObservableObject)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Properties/SettingsTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Properties/SettingsTests.cs new file mode 100644 index 000000000..7cdae4f7d --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Properties/SettingsTests.cs @@ -0,0 +1,71 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Configuration; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Properties.Tests +{ + /// + /// Defines test class SettingsTests. + /// + /// + [TestClass()] + public class SettingsTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test item + /// + /// + Settings testItem; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testItem = new(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testItem); + Assert.IsInstanceOfType(testItem, typeof(Settings)); + Assert.IsInstanceOfType(testItem, typeof(ApplicationSettingsBase)); + } + /// + /// Defines the test method DefaultInstanceTest. + /// + /// + [TestMethod()] + public void DefaultInstanceTest() + { + Assert.IsNotNull(Settings.Default); + Assert.IsInstanceOfType(Settings.Default, typeof(Settings)); + Assert.IsInstanceOfType(Settings.Default, typeof(ApplicationSettingsBase)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ValueConverters/DateTimeValueConverterTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ValueConverters/DateTimeValueConverterTests.cs new file mode 100644 index 000000000..f0eb53900 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ValueConverters/DateTimeValueConverterTests.cs @@ -0,0 +1,73 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplateTests +// Author : Mir +// Created : 05-11-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-11-2023 +// *********************************************************************** +// +// Copyright (c) JC-Soft. All rights reserved. +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Globalization; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.ValueConverter.Tests +{ + + /// + /// Defines test class CurrencyValueConverterTests. + /// + /// + [TestClass()] + public class DateTimeValueConverterTests + { + /// + /// The converter + /// + /// + readonly DateTimeValueConverter testConv = new(); + + /// + /// Converts the correctly formats value. + /// + /// The value. + /// The expected. + /// + [DataTestMethod] + [DataRow("2023-01-01 22:00",null, "01/01/2023 23:00:00")] + [DataRow("2023-05-02 12:30","MM/dd/yyyy", "05.02.2023")] + [DataRow("Hallo",null, "Hallo")] + [DataRow(null,null, "")] + public void ConvertTest(object? value, string? param, string expected) + { + if (value is string s && DateTime.TryParse(s, CultureInfo.InvariantCulture,DateTimeStyles.AssumeUniversal,out var dt)) value = dt; + var result = testConv.Convert(value, typeof(string), param, CultureInfo.InvariantCulture); + Assert.AreEqual(expected, result); + } + + /// + /// Defines the test method ConvertBackTest. + /// + /// + [DataTestMethod] + [DataRow("2023-01-01 22:30", null, "01/01/2023 22:30:00")] + [DataRow("2023-05-02", "MM/dd/yyyy", "05.02.2023")] + [DataRow("01.01.0001 00:00:00", null, "Hallo")] + [DataRow("01.01.0001 00:00:00", "", 100)] + [DataRow("01.01.0001 00:00:00", "", null)] + public void ConvertBackTest(object? value, string? param, object? expected) + { + if (value is string s && DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var dt)) value = dt; + var result = testConv.ConvertBack(expected, typeof(DateTime), param, CultureInfo.InvariantCulture); + Assert.AreEqual(value, result); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/MainWindowViewModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/MainWindowViewModelTests.cs new file mode 100644 index 000000000..c24537c58 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/MainWindowViewModelTests.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.ComponentModel; +using MVVM.ViewModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.ViewModels.Tests +{ + /// + /// Defines test class MainWindowViewModelTests. + /// + /// + [TestClass()] + public class MainWindowViewModelTests : BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + MainWindowViewModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchg) + npchg.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(MainWindowViewModel)); + Assert.IsInstanceOfType(testModel, typeof(BaseViewModelCT)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/TemplateViewModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/TemplateViewModelTests.cs new file mode 100644 index 000000000..c70b097e2 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/ViewModels/TemplateViewModelTests.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.ComponentModel; +using MVVM.ViewModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.ViewModels.Tests +{ + /// + /// Defines test class TemplateViewModelTests. + /// + /// + [TestClass()] + public class TemplateViewModelTests:BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + TemplateViewModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchgn) + npchgn.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(TemplateViewModel)); + Assert.IsInstanceOfType(testModel, typeof(BaseViewModelCT)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/MainWindowTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/MainWindowTests.cs new file mode 100644 index 000000000..3b03099c2 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/MainWindowTests.cs @@ -0,0 +1,62 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Views.Tests +{ + /// + /// Defines test class MainWindowTests. + /// + /// + [TestClass()] + public class MainWindowTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test view + /// + /// + MainWindow testView; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + var t = new Thread(() => testView = new()); + t.SetApartmentState(ApartmentState.STA); //Set the thread to STA + t.Start(); + t.Join(); //Wait for the thread to end + } + + /// + /// Defines the test method MainWindowTest. + /// + /// + [TestMethod()] + public void MainWindowTest() + { + Assert.IsNotNull(testView); + Assert.IsInstanceOfType(testView, typeof(MainWindow)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/TemplateViewTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/TemplateViewTests.cs new file mode 100644 index 000000000..f31673ea8 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00_IoCTemplateTests/Views/TemplateViewTests.cs @@ -0,0 +1,62 @@ +// *********************************************************************** +// Assembly : MVVM_00_IoCTemplate_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_00_IoCTemplate.Views.Tests +{ + /// + /// Defines test class TemplateViewTests. + /// + /// + [TestClass()] + public class TemplateViewTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test view + /// + /// + TemplateView testView; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + var t = new Thread(() => testView = new()); + t.SetApartmentState(ApartmentState.STA); //Set the thread to STA + t.Start(); + t.Join(); //Wait for the thread to end + } + + /// + /// Defines the test method MainWindowTest. + /// + /// + [TestMethod()] + public void MainWindowTest() + { + Assert.IsNotNull(testView); + Assert.IsInstanceOfType(testView, typeof(TemplateView)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_00a_CTTemplate.sln b/CSharpBible/MVVM_Tutorial/MVVM_00a_CTTemplate.sln new file mode 100644 index 000000000..2ca200c2d --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_00a_CTTemplate.sln @@ -0,0 +1,67 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{658BD492-33FF-4995-AAE7-4F6894E92F0C}" + ProjectSection(SolutionItems) = preProject + MVVM_Tutorial.props = MVVM_Tutorial.props + MVVM_Tutorial_net.props = MVVM_Tutorial_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLib", "..\Libraries\MVVM_BaseLib\MVVM_BaseLib.csproj", "{890CF504-3814-443B-9EE6-E8BCACF68203}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{AF041458-CF94-4D6D-BB0F-8BC50F4F099C}" + ProjectSection(SolutionItems) = preProject + ..\Libraries\Libraries_net.props = ..\Libraries\Libraries_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLibTests", "..\Libraries\MVVM_BaseLibTests\MVVM_BaseLibTests.csproj", "{66EB60F2-523D-47C8-95EA-C7E10759E239}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00a_CTTemplate", "MVVM_00a_CTTemplate\MVVM_00a_CTTemplate.csproj", "{16A3E367-674C-4959-8B31-7681B0E8258C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00a_CTTemplate_net", "MVVM_00a_CTTemplate\MVVM_00a_CTTemplate_net.csproj", "{D6BFC652-822A-4E7D-9846-7F529C584BAC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00a_CTTemplate_netTests", "MVVM_00a_CTTemplateTests\MVVM_00a_CTTemplate_netTests.csproj", "{A7844F45-74D9-4A81-9C27-D0E17ED0F851}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_00a_CTTemplateTests", "MVVM_00a_CTTemplateTests\MVVM_00a_CTTemplateTests.csproj", "{7FF12BBB-AA2E-48C1-B283-0665570902F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.Build.0 = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.ActiveCfg = Release|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.Build.0 = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.Build.0 = Release|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16A3E367-674C-4959-8B31-7681B0E8258C}.Release|Any CPU.Build.0 = Release|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6BFC652-822A-4E7D-9846-7F529C584BAC}.Release|Any CPU.Build.0 = Release|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7844F45-74D9-4A81-9C27-D0E17ED0F851}.Release|Any CPU.Build.0 = Release|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FF12BBB-AA2E-48C1-B283-0665570902F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {890CF504-3814-443B-9EE6-E8BCACF68203} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + {66EB60F2-523D-47C8-95EA-C7E10759E239} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + EndGlobalSection +EndGlobal diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard.sln b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard.sln new file mode 100644 index 000000000..85efab132 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard.sln @@ -0,0 +1,70 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{658BD492-33FF-4995-AAE7-4F6894E92F0C}" + ProjectSection(SolutionItems) = preProject + MVVM_Tutorial.props = MVVM_Tutorial.props + MVVM_Tutorial_net.props = MVVM_Tutorial_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLib", "..\Libraries\MVVM_BaseLib\MVVM_BaseLib.csproj", "{890CF504-3814-443B-9EE6-E8BCACF68203}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{AF041458-CF94-4D6D-BB0F-8BC50F4F099C}" + ProjectSection(SolutionItems) = preProject + ..\Libraries\Libraries_net.props = ..\Libraries\Libraries_net.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_BaseLibTests", "..\Libraries\MVVM_BaseLibTests\MVVM_BaseLibTests.csproj", "{66EB60F2-523D-47C8-95EA-C7E10759E239}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_40_Wizzard", "MVVM_40_Wizzard\MVVM_40_Wizzard.csproj", "{FF4043F1-C225-4C44-8BC5-7894D0248EED}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_40_Wizzard_net", "MVVM_40_Wizzard\MVVM_40_Wizzard_net.csproj", "{37266EB8-03A6-49C7-A4CF-13435E3E1048}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_40_Wizzard_netTests", "MVVM_40_WizzardTests\MVVM_40_Wizzard_netTests.csproj", "{1216F287-4219-4B39-9D0E-FDB077D3BF5A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM_40_WizzardTests", "MVVM_40_WizzardTests\MVVM_40_WizzardTests.csproj", "{F2700D0C-2BA9-4E6B-9FA6-BCBE8E6A8301}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Debug|Any CPU.Build.0 = Debug|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.ActiveCfg = Release|Any CPU + {890CF504-3814-443B-9EE6-E8BCACF68203}.Release|Any CPU.Build.0 = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66EB60F2-523D-47C8-95EA-C7E10759E239}.Release|Any CPU.Build.0 = Release|Any CPU + {FF4043F1-C225-4C44-8BC5-7894D0248EED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF4043F1-C225-4C44-8BC5-7894D0248EED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF4043F1-C225-4C44-8BC5-7894D0248EED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF4043F1-C225-4C44-8BC5-7894D0248EED}.Release|Any CPU.Build.0 = Release|Any CPU + {37266EB8-03A6-49C7-A4CF-13435E3E1048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37266EB8-03A6-49C7-A4CF-13435E3E1048}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37266EB8-03A6-49C7-A4CF-13435E3E1048}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37266EB8-03A6-49C7-A4CF-13435E3E1048}.Release|Any CPU.Build.0 = Release|Any CPU + {1216F287-4219-4B39-9D0E-FDB077D3BF5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1216F287-4219-4B39-9D0E-FDB077D3BF5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1216F287-4219-4B39-9D0E-FDB077D3BF5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1216F287-4219-4B39-9D0E-FDB077D3BF5A}.Release|Any CPU.Build.0 = Release|Any CPU + {F2700D0C-2BA9-4E6B-9FA6-BCBE8E6A8301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2700D0C-2BA9-4E6B-9FA6-BCBE8E6A8301}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2700D0C-2BA9-4E6B-9FA6-BCBE8E6A8301}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2700D0C-2BA9-4E6B-9FA6-BCBE8E6A8301}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {890CF504-3814-443B-9EE6-E8BCACF68203} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + {66EB60F2-523D-47C8-95EA-C7E10759E239} = {AF041458-CF94-4D6D-BB0F-8BC50F4F099C} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B71B7057-D83A-40F4-9692-58E1EC1BBADC} + EndGlobalSection +EndGlobal diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml new file mode 100644 index 000000000..d4beb2f72 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml.cs new file mode 100644 index 000000000..849a97705 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/App.xaml.cs @@ -0,0 +1,27 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using System.Windows; + +namespace MVVM_40_Wizzard +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} +namespace MVVM_40_Wizzard.Models { } +namespace MVVM_40_Wizzard.ValueConverter { } +namespace MVVM_40_Wizzard.Services { } diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/AssemblyInfo.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/AssemblyInfo.cs new file mode 100644 index 000000000..f60efc019 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard.csproj b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard.csproj new file mode 100644 index 000000000..49be83e8f --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard.csproj @@ -0,0 +1,37 @@ + + + + WinExe + net462-windows;net472-windows;net48-windows;net481-windows + true + + + + + + + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + PublicSettingsSingleFileGenerator + Settings.Designer.cs + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard_net.csproj b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard_net.csproj new file mode 100644 index 000000000..6eb754d68 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MVVM_40_Wizzard_net.csproj @@ -0,0 +1,37 @@ + + + + WinExe + net6.0-windows;net7.0-windows;net8.0-windows + true + + + + + + + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + PublicSettingsSingleFileGenerator + Settings.Designer.cs + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml new file mode 100644 index 000000000..29f695aaa --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml.cs new file mode 100644 index 000000000..93c9a5f14 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/MainWindow.xaml.cs @@ -0,0 +1,31 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using System.Windows; + +namespace MVVM_40_Wizzard +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + /// + /// Initializes a new instance of the class. + /// + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/.info b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/.info new file mode 100644 index 000000000..62f215ed0 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/.info @@ -0,0 +1 @@ +Folder for Models diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/ITemplateModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/ITemplateModel.cs new file mode 100644 index 000000000..e95ba0e1a --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/ITemplateModel.cs @@ -0,0 +1,41 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using System; +using System.ComponentModel; + +/// +/// The Models namespace. +/// +/// +namespace MVVM_40_Wizzard.Models +{ + /// + /// Interface ITemplateModel + /// + /// + public interface ITemplateModel + { + /// + /// Gets the now. + /// + /// The now. + /// + DateTime Now { get; } + /// + /// Occurs when [property changed]. + /// + /// + event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/TemplateModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/TemplateModel.cs new file mode 100644 index 000000000..c3c879b5a --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Models/TemplateModel.cs @@ -0,0 +1,78 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using CommunityToolkit.Mvvm.ComponentModel; +using System; +using System.Timers; + +/// +/// The Models namespace. +/// +/// +namespace MVVM_40_Wizzard.Models +{ + /// + /// Class TemplateModel. + /// Implements the + /// Implements the + /// + /// + /// + /// + public partial class TemplateModel :ObservableObject, ITemplateModel + { + #region Properties + /// + /// The timer + /// + /// + private readonly Timer _timer; + /// + /// Gets or sets the get now. + /// + /// The get now. + /// + public static Func GetNow { get; set; } = () => DateTime.Now; + /// + /// Gets the now. + /// + /// The now. + /// + public DateTime Now { get => GetNow(); } + #endregion + + #region Methods + /// + /// Initializes a new instance of the class. + /// + /// + public TemplateModel() + { + _timer = new(250d); + _timer.Elapsed += (s, e) => OnPropertyChanged(nameof(Now)); + _timer.Start(); + } + +#if !NET5_0_OR_GREATER + /// + /// Finalizes an instance of the class. + /// + ~TemplateModel() + { + _timer.Stop(); + return; + } +#endif + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.Designer.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.Designer.cs new file mode 100644 index 000000000..6f0cf276e --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.Designer.cs @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace MVVM_40_Wizzard.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MVVM_40_Wizzard.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die MVVM-Template using Community-Toolkit ähnelt. + /// + public static string Description { + get { + return ResourceManager.GetString("Description", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die <Page + /// xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + /// xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + /// xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + /// xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + /// xmlns:local="clr-namespace:MVVM_40_Wizzard.Views" + /// xmlns:p="clr-namespace:MVVM_40_Wizzard.Properties" + /// xmlns:vc="clr-namespace:MVVM_40_Wizzard.ValueConverter" + /// xmlns:mvvm="clr-namespace: [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt. + /// + public static string TemplateView { + get { + return ResourceManager.GetString("TemplateView", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die // *********************************************************************** + ///// Assembly : MVVM_40_Wizzard + ///// Author : Mir + ///// Created : 08-11-2022 + ///// + ///// Last Modified By : Mir + ///// Last Modified On : 08-24-2022 + ///// *********************************************************************** + ///// <copyright file="MainWindowViewModel.cs" company="JC-Soft"> + ///// Copyright © JC-Soft 2022 + ///// </copyright> + ///// <summary></summary> + ///// ************************************************** [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt. + /// + public static string TemplateViewModel { + get { + return ResourceManager.GetString("TemplateViewModel", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die CT-Template-View ähnelt. + /// + public static string Title { + get { + return ResourceManager.GetString("Title", resourceCulture); + } + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.resx b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.resx new file mode 100644 index 000000000..9225fb660 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + MVVM-Template using Community-Toolkit + + + + ..\Views\TemplateView.xaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\ViewModels\TemplateViewModel.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + CT-Template-View + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.Designer.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.Designer.cs new file mode 100644 index 000000000..dc7dd10a5 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace MVVM_40_Wizzard.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")] + public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.settings b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.settings new file mode 100644 index 000000000..049245f40 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/.info b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/.info new file mode 100644 index 000000000..b4bc464df --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/.info @@ -0,0 +1 @@ +Folder for ValueConverters diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/DateTimeValueConverter.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/DateTimeValueConverter.cs new file mode 100644 index 000000000..50414bc62 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ValueConverters/DateTimeValueConverter.cs @@ -0,0 +1,63 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 07-03-2022 +// +// Last Modified By : Mir +// Last Modified On : 07-04-2022 +// *********************************************************************** +// +// Copyright (c) JC-Soft. All rights reserved. +// +// +// *********************************************************************** +using System; +using System.Globalization; +using System.Windows.Data; + +namespace MVVM_40_Wizzard.ValueConverter +{ + /// + /// Class CurrencyValueConverter. + /// Implements the + /// + /// + public class DateTimeValueConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// The value produced by the binding source. + /// The type of the binding target property. + /// The converter parameter to use. + /// The culture to use in the converter. + /// A converted value. If the method returns , the valid null value is used. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is DateTime dt) + if (parameter is string spar) + return dt.ToString(spar); + else + return dt.ToString(culture); + else + return value?.ToString() ?? ""; + + } + + /// + /// Converts a value. + /// + /// The value that is produced by the binding target. + /// The type to convert to. + /// The converter parameter to use. + /// The culture to use in the converter. + /// A converted value. If the method returns , the valid null value is used. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string sval && DateTime.TryParse(sval.Trim(),culture, DateTimeStyles.AssumeLocal, out var dt)) + return dt; + else + return DateTime.MinValue; + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/.info b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/.info new file mode 100644 index 000000000..a3ed848fb --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/.info @@ -0,0 +1 @@ +Folder for ViewModels diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/MainWindowViewModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/MainWindowViewModel.cs new file mode 100644 index 000000000..e3e3832d6 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,47 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using MVVM.ViewModel; + +namespace MVVM_40_Wizzard.ViewModels +{ + /// + /// Class MainWindowViewModel. + /// Implements the + /// + /// + public class MainWindowViewModel : BaseViewModelCT + { + #region Properties + #endregion + #region Methods + /// + /// Initializes a new instance of the class. + /// + public MainWindowViewModel() + { + + } + +#if !NET5_0_OR_GREATER + /// + /// Finalizes an instance of the class. + /// + ~MainWindowViewModel() + { + return; + } +#endif + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/TemplateViewModel.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/TemplateViewModel.cs new file mode 100644 index 000000000..61ac23469 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/ViewModels/TemplateViewModel.cs @@ -0,0 +1,57 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard +// Author : Mir +// Created : 08-11-2022 +// +// Last Modified By : Mir +// Last Modified On : 08-24-2022 +// *********************************************************************** +// +// Copyright © JC-Soft 2022 +// +// +// *********************************************************************** +using MVVM.ViewModel; +using MVVM_40_Wizzard.Models; +using System; +using System.ComponentModel; + +namespace MVVM_40_Wizzard.ViewModels +{ + /// + /// Class MainWindowViewModel. + /// Implements the + /// + /// + public partial class TemplateViewModel : BaseViewModelCT + { + #region Properties + public static Func GetModel { get; set; } = () => new TemplateModel(); + + private readonly ITemplateModel _model; + + public DateTime Now => _model.Now; + #endregion + + #region Methods + /// + /// Initializes a new instance of the class. + /// + public TemplateViewModel():this(GetModel()) + { + } + + public TemplateViewModel(ITemplateModel model) + { + _model = model; + _model.PropertyChanged += OnMPropertyChanged; + } + + private void OnMPropertyChanged(object sender, PropertyChangedEventArgs e) + { + OnPropertyChanged(e.PropertyName); + } + + #endregion + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/.info b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/.info new file mode 100644 index 000000000..65a00d680 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/.info @@ -0,0 +1 @@ +Folder for Views diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml new file mode 100644 index 000000000..57fa66a5d --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml.cs new file mode 100644 index 000000000..54b1829bd --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_Wizzard/Views/TemplateView.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace MVVM_40_Wizzard.Views +{ + /// + /// Interaktionslogik für TemplateView.xaml + /// + public partial class TemplateView : Page + { + public TemplateView() + { + InitializeComponent(); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/AppTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/AppTests.cs new file mode 100644 index 000000000..d51b45577 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/AppTests.cs @@ -0,0 +1,57 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MVVM.View.Extension; +using MVVM_40_Wizzard.Models; +using System; + +namespace MVVM_40_Wizzard.Tests +{ + internal class TestApp : App + { + public void DoStartUp() + { + OnStartup(null); + } + } + [TestClass()] + public class AppTests + { + static TestApp app = new(); + private Func _gsold; + private Func _grsold; + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + _gsold = IoC.GetSrv; + _grsold = IoC.GetReqSrv; + IoC.GetReqSrv = (t) =>t switch { + _ when t == typeof(ITemplateModel) => new TemplateModel(), + _ => throw new ArgumentException() }; + } + + [TestCleanup] + public void CleanUp() + { + IoC.GetSrv = _gsold; + IoC.GetReqSrv = _grsold; + } + + [TestMethod] + public void AppTest() + { + Assert.IsNotNull(app); + } + + [TestMethod] + public void AppTest2() + { + app.DoStartUp(); + Assert.IsNotNull(IoC.GetReqSrv(typeof(ITemplateModel))); + Assert.IsNull(IoC.GetSrv(typeof(App))); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_WizzardTests.csproj b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_WizzardTests.csproj new file mode 100644 index 000000000..9012e48db --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_WizzardTests.csproj @@ -0,0 +1,24 @@ + + + + net462-windows;net472-windows;net48-windows;net481-windows + true + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_Wizzard_netTests.csproj b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_Wizzard_netTests.csproj new file mode 100644 index 000000000..08da3aebf --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/MVVM_40_Wizzard_netTests.csproj @@ -0,0 +1,24 @@ + + + + net6.0-windows;net7.0-windows;net8.0-windows + true + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Models/TemplateModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Models/TemplateModelTests.cs new file mode 100644 index 000000000..4eadb3c28 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Models/TemplateModelTests.cs @@ -0,0 +1,67 @@ +// *********************************************************************** +// Assembly : MVVM_40_WizzardTests +// Author : Mir +// Created : 05-19-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MVVM.ViewModel; +using System.ComponentModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.Models.Tests +{ + /// + /// Defines test class TemplateModelTests. + /// Implements the + /// + /// + /// + [TestClass()] + public class TemplateModelTests : BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + TemplateModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchgn) + npchgn.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(TemplateModel)); + Assert.IsInstanceOfType(testModel, typeof(ObservableObject)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Properties/SettingsTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Properties/SettingsTests.cs new file mode 100644 index 000000000..33cd75fdd --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Properties/SettingsTests.cs @@ -0,0 +1,71 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Configuration; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.Properties.Tests +{ + /// + /// Defines test class SettingsTests. + /// + /// + [TestClass()] + public class SettingsTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test item + /// + /// + Settings testItem; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testItem = new(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testItem); + Assert.IsInstanceOfType(testItem, typeof(Settings)); + Assert.IsInstanceOfType(testItem, typeof(ApplicationSettingsBase)); + } + /// + /// Defines the test method DefaultInstanceTest. + /// + /// + [TestMethod()] + public void DefaultInstanceTest() + { + Assert.IsNotNull(Settings.Default); + Assert.IsInstanceOfType(Settings.Default, typeof(Settings)); + Assert.IsInstanceOfType(Settings.Default, typeof(ApplicationSettingsBase)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ValueConverters/DateTimeValueConverterTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ValueConverters/DateTimeValueConverterTests.cs new file mode 100644 index 000000000..824ed02f8 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ValueConverters/DateTimeValueConverterTests.cs @@ -0,0 +1,73 @@ +// *********************************************************************** +// Assembly : MVVM_40_WizzardTests +// Author : Mir +// Created : 05-11-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-11-2023 +// *********************************************************************** +// +// Copyright (c) JC-Soft. All rights reserved. +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Globalization; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.ValueConverter.Tests +{ + + /// + /// Defines test class CurrencyValueConverterTests. + /// + /// + [TestClass()] + public class DateTimeValueConverterTests + { + /// + /// The converter + /// + /// + readonly DateTimeValueConverter testConv = new(); + + /// + /// Converts the correctly formats value. + /// + /// The value. + /// The expected. + /// + [DataTestMethod] + [DataRow("2023-01-01 22:00",null, "01/01/2023 23:00:00")] + [DataRow("2023-05-02 12:30","MM/dd/yyyy", "05.02.2023")] + [DataRow("Hallo",null, "Hallo")] + [DataRow(null,null, "")] + public void ConvertTest(object? value, string? param, string expected) + { + if (value is string s && DateTime.TryParse(s, CultureInfo.InvariantCulture,DateTimeStyles.AssumeUniversal,out var dt)) value = dt; + var result = testConv.Convert(value, typeof(string), param, CultureInfo.InvariantCulture); + Assert.AreEqual(expected, result); + } + + /// + /// Defines the test method ConvertBackTest. + /// + /// + [DataTestMethod] + [DataRow("2023-01-01 22:30", null, "01/01/2023 22:30:00")] + [DataRow("2023-05-02", "MM/dd/yyyy", "05.02.2023")] + [DataRow("01.01.0001 00:00:00", null, "Hallo")] + [DataRow("01.01.0001 00:00:00", "", 100)] + [DataRow("01.01.0001 00:00:00", "", null)] + public void ConvertBackTest(object? value, string? param, object? expected) + { + if (value is string s && DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var dt)) value = dt; + var result = testConv.ConvertBack(expected, typeof(DateTime), param, CultureInfo.InvariantCulture); + Assert.AreEqual(value, result); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/MainWindowViewModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/MainWindowViewModelTests.cs new file mode 100644 index 000000000..cbbf22548 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/MainWindowViewModelTests.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-19-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.ComponentModel; +using MVVM.ViewModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.ViewModels.Tests +{ + /// + /// Defines test class MainWindowViewModelTests. + /// + /// + [TestClass()] + public class MainWindowViewModelTests : BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + MainWindowViewModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchg) + npchg.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(MainWindowViewModel)); + Assert.IsInstanceOfType(testModel, typeof(BaseViewModelCT)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/TemplateViewModelTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/TemplateViewModelTests.cs new file mode 100644 index 000000000..34b1dbeae --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/ViewModels/TemplateViewModelTests.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.ComponentModel; +using MVVM.ViewModel; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.ViewModels.Tests +{ + /// + /// Defines test class TemplateViewModelTests. + /// + /// + [TestClass()] + public class TemplateViewModelTests:BaseTestViewModel + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test model + /// + /// + TemplateViewModel testModel; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + testModel = new(); + testModel.PropertyChanged += OnVMPropertyChanged; + if (testModel is INotifyPropertyChanging npchgn) + npchgn.PropertyChanging += OnVMPropertyChanging; + ClearLog(); + } + + /// + /// Defines the test method SetupTest. + /// + /// + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(TemplateViewModel)); + Assert.IsInstanceOfType(testModel, typeof(BaseViewModelCT)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/MainWindowTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/MainWindowTests.cs new file mode 100644 index 000000000..d5c6b3830 --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/MainWindowTests.cs @@ -0,0 +1,62 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.Views.Tests +{ + /// + /// Defines test class MainWindowTests. + /// + /// + [TestClass()] + public class MainWindowTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test view + /// + /// + MainWindow testView; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + var t = new Thread(() => testView = new()); + t.SetApartmentState(ApartmentState.STA); //Set the thread to STA + t.Start(); + t.Join(); //Wait for the thread to end + } + + /// + /// Defines the test method MainWindowTest. + /// + /// + [TestMethod()] + public void MainWindowTest() + { + Assert.IsNotNull(testView); + Assert.IsInstanceOfType(testView, typeof(MainWindow)); + } + } +} diff --git a/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/TemplateViewTests.cs b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/TemplateViewTests.cs new file mode 100644 index 000000000..49b2b6c3d --- /dev/null +++ b/CSharpBible/MVVM_Tutorial/MVVM_40_WizzardTests/Views/TemplateViewTests.cs @@ -0,0 +1,62 @@ +// *********************************************************************** +// Assembly : MVVM_40_Wizzard_netTests +// Author : Mir +// Created : 05-14-2023 +// +// Last Modified By : Mir +// Last Modified On : 05-14-2023 +// *********************************************************************** +// +// Copyright © JC-Soft 2023 +// +// +// *********************************************************************** +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading; + +/// +/// The Tests namespace. +/// +/// +namespace MVVM_40_Wizzard.Views.Tests +{ + /// + /// Defines test class TemplateViewTests. + /// + /// + [TestClass()] + public class TemplateViewTests + { +#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + /// + /// The test view + /// + /// + TemplateView testView; +#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable. + + /// + /// Initializes this instance. + /// + /// + [TestInitialize] + public void Init() + { + var t = new Thread(() => testView = new()); + t.SetApartmentState(ApartmentState.STA); //Set the thread to STA + t.Start(); + t.Join(); //Wait for the thread to end + } + + /// + /// Defines the test method MainWindowTest. + /// + /// + [TestMethod()] + public void MainWindowTest() + { + Assert.IsNotNull(testView); + Assert.IsInstanceOfType(testView, typeof(TemplateView)); + } + } +} diff --git a/CSharpBible/TestConsole/Models/Interfaces/IConsoleHandler.cs b/CSharpBible/TestConsole/Models/Interfaces/IConsoleHandler.cs new file mode 100644 index 000000000..050e55f03 --- /dev/null +++ b/CSharpBible/TestConsole/Models/Interfaces/IConsoleHandler.cs @@ -0,0 +1,26 @@ +using System; +using System.Drawing; +using TestConsole.View; + +namespace TestConsole.Models.Interfaces; +public interface IConsoleHandler +{ + int WindowWidth { get; set; } + int WindowHeight { get; set; } + + string Text { get; set; } + ConsoleColor ForegroundColor { get; set; } + ConsoleColor BackgroundColor { get; set; } + bool KeyAvailable { get; } + string Content { get; } + ConsoleCharInfo[] ScreenBuffer { get; set; } + Size ConsoleSize { get; set; } + + void Clear(); + (int Left, int Top) GetCursorPosition(); + ConsoleKeyInfo ReadKey(); + void SetCursorPosition(int left, int top); + void Write(char ch); + void Write(string? st); + void YScroll(bool force = false); +} \ No newline at end of file