diff --git a/.gitignore b/.gitignore index 5ccb5a940..b267fa01a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,29 @@ .vs bin obj +*.db +*.cache +*.bin +*.dll *.bak *.user +*.log +*.suo +*.snk +**/vs +**/obj +**/obj.net +**/bin +**/Help +/CSharpBible/App2 +/CSharpBible/Mobile +/CSharpBible/Web +/CSharpBible/packages +/CSharpBible/Simulation +/CSharpBible/DB/ADO_Test +/CSharpBible/Libraries/CSFreeVision_ +/CSharpBible/Libraries/MathLibraryTests/TestResults +/CSharpBible/Graphics/PermutationTests/TestResults +/CSharpBible/MVVM_Tutorial/UWP_00_Test +/CSharpBible/WinUI/App1 +/TestStatements/Help diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj index b7fd17855..9d80b995e 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalc/AA05_CommandParCalc.csproj @@ -2,13 +2,19 @@ WinExe - net8.0;net9.0 + net8.0 true app.manifest true + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + @@ -48,4 +54,6 @@ Resources.Designer.cs + + diff --git a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AA05_CommandParCalcTests.csproj b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AA05_CommandParCalcTests.csproj index e713d1758..fcc6be58f 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AA05_CommandParCalcTests.csproj +++ b/Avalonia_Apps/AA05_CommandParCalc/AA05_CommandParCalcTests/AA05_CommandParCalcTests.csproj @@ -1,13 +1,18 @@  - net8.0;net9.0 + net8.0 Library enable - + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + diff --git a/Avalonia_Apps/AA05_CommandParCalc/Directory.Packages.props b/Avalonia_Apps/AA05_CommandParCalc/Directory.Packages.props index 75c20929e..7eb87d870 100644 --- a/Avalonia_Apps/AA05_CommandParCalc/Directory.Packages.props +++ b/Avalonia_Apps/AA05_CommandParCalc/Directory.Packages.props @@ -1,27 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4/AA06_Converters4.csproj b/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4/AA06_Converters4.csproj index 68ab18854..7deb84a87 100644 --- a/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4/AA06_Converters4.csproj +++ b/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4/AA06_Converters4.csproj @@ -2,13 +2,19 @@ WinExe - net8.0;net9.0 + net8.0 enable true true + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + diff --git a/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4Tests/AA06_Converters4Tests.csproj b/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4Tests/AA06_Converters4Tests.csproj index a0dd72870..0e77ada03 100644 --- a/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4Tests/AA06_Converters4Tests.csproj +++ b/Avalonia_Apps/AA06_ValueConverter2/AA06_Converters4Tests/AA06_Converters4Tests.csproj @@ -1,13 +1,19 @@  - net9.0 + net8.0 false + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + - + @@ -23,4 +29,5 @@ + diff --git a/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2/AA06_ValueConverter2.csproj b/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2/AA06_ValueConverter2.csproj index e57ac834e..10ed24821 100644 --- a/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2/AA06_ValueConverter2.csproj +++ b/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2/AA06_ValueConverter2.csproj @@ -2,13 +2,19 @@ WinExe - net8.0;net9.0 + net8.0 true app.manifest true + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + @@ -49,4 +55,5 @@ Resources.Designer.cs + diff --git a/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2Tests/AA06_ValueConverter2Tests.csproj b/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2Tests/AA06_ValueConverter2Tests.csproj index 7e9626597..b906d0c53 100644 --- a/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2Tests/AA06_ValueConverter2Tests.csproj +++ b/Avalonia_Apps/AA06_ValueConverter2/AA06_ValueConverter2Tests/AA06_ValueConverter2Tests.csproj @@ -1,12 +1,18 @@  - net8.0;net9.0 + net8.0 Library enable + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + diff --git a/Avalonia_Apps/AA06_ValueConverter2/Directory.Packages.props b/Avalonia_Apps/AA06_ValueConverter2/Directory.Packages.props index 031d8b4f7..7eb87d870 100644 --- a/Avalonia_Apps/AA06_ValueConverter2/Directory.Packages.props +++ b/Avalonia_Apps/AA06_ValueConverter2/Directory.Packages.props @@ -1,31 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj index edeefc7f9..5b75d64e7 100644 --- a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxes/AA09_DialogBoxes.csproj @@ -2,12 +2,18 @@ WinExe - net8.0;net9.0 + net8.0 true - + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + + enable disable diff --git a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxesTests/AA09_DialogBoxes_Tests.csproj b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxesTests/AA09_DialogBoxes_Tests.csproj index cb8dd0f92..4a9b8064d 100644 --- a/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxesTests/AA09_DialogBoxes_Tests.csproj +++ b/Avalonia_Apps/AA09_DialogBoxes/AA09_DialogBoxesTests/AA09_DialogBoxes_Tests.csproj @@ -1,14 +1,20 @@  - net8.0;net9.0 + net8.0 true false + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + - + diff --git a/Avalonia_Apps/AA09_DialogBoxes/Directory.Packages.props b/Avalonia_Apps/AA09_DialogBoxes/Directory.Packages.props index ac66cfd24..7eb87d870 100644 --- a/Avalonia_Apps/AA09_DialogBoxes/Directory.Packages.props +++ b/Avalonia_Apps/AA09_DialogBoxes/Directory.Packages.props @@ -1,29 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA14_ScreenX/AA14_ScreenX/AA14_ScreenX.csproj b/Avalonia_Apps/AA14_ScreenX/AA14_ScreenX/AA14_ScreenX.csproj index 0b5aff615..d246e0113 100644 --- a/Avalonia_Apps/AA14_ScreenX/AA14_ScreenX/AA14_ScreenX.csproj +++ b/Avalonia_Apps/AA14_ScreenX/AA14_ScreenX/AA14_ScreenX.csproj @@ -11,7 +11,7 @@ - + @@ -23,4 +23,11 @@ + + + + + + + diff --git a/Avalonia_Apps/AA14_ScreenX/Directory.Packages.props b/Avalonia_Apps/AA14_ScreenX/Directory.Packages.props index ac66cfd24..7eb87d870 100644 --- a/Avalonia_Apps/AA14_ScreenX/Directory.Packages.props +++ b/Avalonia_Apps/AA14_ScreenX/Directory.Packages.props @@ -1,29 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA15_Labyrinth/AA15_Labyrinth/AA15_Labyrinth.csproj b/Avalonia_Apps/AA15_Labyrinth/AA15_Labyrinth/AA15_Labyrinth.csproj index baa60b44a..868598e9c 100644 --- a/Avalonia_Apps/AA15_Labyrinth/AA15_Labyrinth/AA15_Labyrinth.csproj +++ b/Avalonia_Apps/AA15_Labyrinth/AA15_Labyrinth/AA15_Labyrinth.csproj @@ -23,4 +23,11 @@ + + + + + + + diff --git a/Avalonia_Apps/AA15_Labyrinth/AA15_LabyrinthTests/AA15_LabyrinthTests.csproj b/Avalonia_Apps/AA15_Labyrinth/AA15_LabyrinthTests/AA15_LabyrinthTests.csproj index 47341c74d..5d0860a91 100644 --- a/Avalonia_Apps/AA15_Labyrinth/AA15_LabyrinthTests/AA15_LabyrinthTests.csproj +++ b/Avalonia_Apps/AA15_Labyrinth/AA15_LabyrinthTests/AA15_LabyrinthTests.csproj @@ -24,4 +24,9 @@ + + + + + diff --git a/Avalonia_Apps/AA15_Labyrinth/AA15a_Treppen/AA15a_Treppen.csproj b/Avalonia_Apps/AA15_Labyrinth/AA15a_Treppen/AA15a_Treppen.csproj index 5bdc8498c..bc98e7507 100644 --- a/Avalonia_Apps/AA15_Labyrinth/AA15a_Treppen/AA15a_Treppen.csproj +++ b/Avalonia_Apps/AA15_Labyrinth/AA15a_Treppen/AA15a_Treppen.csproj @@ -36,4 +36,13 @@ + + + + + + + + + diff --git a/Avalonia_Apps/AA15_Labyrinth/Directory.Packages.props b/Avalonia_Apps/AA15_Labyrinth/Directory.Packages.props index 064f3ff82..7eb87d870 100644 --- a/Avalonia_Apps/AA15_Labyrinth/Directory.Packages.props +++ b/Avalonia_Apps/AA15_Labyrinth/Directory.Packages.props @@ -1,32 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA15_Labyrinth/Treppen.Base/Treppen.Base.csproj b/Avalonia_Apps/AA15_Labyrinth/Treppen.Base/Treppen.Base.csproj index ff3071c13..f0ba2a4a8 100644 --- a/Avalonia_Apps/AA15_Labyrinth/Treppen.Base/Treppen.Base.csproj +++ b/Avalonia_Apps/AA15_Labyrinth/Treppen.Base/Treppen.Base.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0 + net8.0 enable enable true @@ -9,7 +9,13 @@ - + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + + diff --git a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/AppTests.cs b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/AppTests.cs new file mode 100644 index 000000000..1b9dd9632 --- /dev/null +++ b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/AppTests.cs @@ -0,0 +1,85 @@ +using System; +using System.Linq; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using AA16_UserControl1; +using AA16_UserControl1.ViewModels.Interfaces; +using AA16_UserControl1.Views; +using Avalonia.Headless.MSTest; +using Avalonia.Views.Extension; + +namespace AA16_UserControl1.Tests; + +[TestClass] +public class AppTests +{ + private static void BuildServiceProvider() + { + var services = new ServiceCollection(); + var method = typeof(App).GetMethod("ConfigureServices", BindingFlags.NonPublic | BindingFlags.Static); + Assert.IsNotNull(method, "ConfigureServices nicht gefunden."); + method.Invoke(null, new object[] { services }); + IoC.Configure(services.BuildServiceProvider()); + } + + [TestMethod] + public void Should_Register_MainWindowViewModel_As_Transient() + { + BuildServiceProvider(); + var vm1 = IoC.GetRequiredService(); + var vm2 = IoC.GetRequiredService(); + Assert.IsNotNull(vm1); + Assert.IsNotNull(vm2); + Assert.AreNotSame(vm1, vm2, "Transient Lifetime erwartet."); + } + + [TestMethod] + public void Should_Register_IUserControlViewModel() + { + BuildServiceProvider(); + var ucVm = IoC.GetRequiredService(); + Assert.IsNotNull(ucVm); + Assert.AreEqual(typeof(AA16_UserControl1.ViewModels.UserControlViewModel), ucVm.GetType()); + } + + [AvaloniaTestMethod] + public void Should_Register_Views() + { + BuildServiceProvider(); + var mainWindow = IoC.GetRequiredService(); + var userControlView = IoC.GetRequiredService(); + var labeledTextbox = IoC.GetRequiredService(); + + Assert.IsNotNull(mainWindow); + Assert.IsNotNull(userControlView); + Assert.IsNotNull(labeledTextbox); + } + + [TestMethod] + public void Should_Not_Register_Commented_DoubleButtonUC() + { + BuildServiceProvider(); + // Sicherstellen, dass nicht versehentlich registriert + var service = IoC.GetService(); + Assert.IsNull(service, "DoubleButtonUC sollte nicht registriert sein."); + } + + [AvaloniaTestMethod] + public void App_Should_Initialize_Correctly() + { + var app = new App(); + app.Initialize(); + Assert.IsNotNull(app, "App-Instanz sollte nicht null sein."); + } + + [AvaloniaTestMethod] + public void App_OnFrameworkInitializationCompletedTests() + { + var app = new App(); + app.OnFrameworkInitializationCompleted(); + Assert.IsNotNull(app, "App-Instanz sollte nicht null sein."); + + } + +} \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/MainWindowViewModelTests.cs b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/MainWindowViewModelTests.cs index c23617409..ea9c4c910 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/MainWindowViewModelTests.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/MainWindowViewModelTests.cs @@ -1,26 +1,35 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.ComponentModel; +using AA16_UserControl1.ViewModels.Interfaces; using Avalonia.ViewModels; +using Avalonia.Views.Extension; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; +using System.ComponentModel; namespace AA16_UserControl1.ViewModels.Tests; [TestClass()] -public class MainWindowViewModelTests +public class MainWindowViewModelTests : BaseTestViewModel { - MainWindowViewModel testModel; - [TestInitialize] - public void Init() + public override void Init() { - testModel = new(null); - } + IoC.GetReqSrv = t => + { + if (t == typeof(IUserControlViewModel)) + { + return Substitute.For(); + } + throw new System.NotImplementedException($"No registration for type {t}."); + }; + base.Init(); + } [TestMethod()] public void SetupTest() { Assert.IsNotNull(testModel); Assert.IsInstanceOfType(testModel, typeof(MainWindowViewModel)); - Assert.IsInstanceOfType(testModel, typeof(BaseViewModelCT)); + Assert.IsInstanceOfType(testModel, typeof(ViewModelBase)); Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); } } \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/UserControlViewModelTests.cs b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/UserControlViewModelTests.cs new file mode 100644 index 000000000..e0ee71846 --- /dev/null +++ b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/ViewModels/UserControlViewModelTests.cs @@ -0,0 +1,64 @@ +using AA16_UserControl1.ViewModels.Interfaces; +using Avalonia.ViewModels; +using Avalonia.Views.Extension; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; +using System.Collections.Generic; +using System.ComponentModel; + +namespace AA16_UserControl1.ViewModels.Tests; + +[TestClass()] +public class UserControlViewModelTests : BaseTestViewModel +{ + protected override Dictionary GetDefaultData() => new() { + { "Text", "" }, + { "Daten", "" }, + { "Do1Command", true }, + { "Do2Command", true } + }; + + [TestInitialize] + public override void Init() + { + IoC.GetReqSrv = t => + { + if (t == typeof(IUserControlViewModel)) + { + return Substitute.For(); + } + throw new System.NotImplementedException($"No registration for type {t}."); + }; + base.Init(); + } + + [TestMethod()] + public void SetupTest() + { + Assert.IsNotNull(testModel); + Assert.IsInstanceOfType(testModel, typeof(UserControlViewModel)); + Assert.IsInstanceOfType(testModel, typeof(ViewModelBase)); + Assert.IsInstanceOfType(testModel, typeof(INotifyPropertyChanged)); + } + + [TestMethod()] + public void Do1CommandTest() + { + Assert.IsTrue(testModel.Do1Command.CanExecute(null)); + testModel.Do1Command.Execute(null); + Assert.AreEqual("", testModel.Text); + Assert.AreEqual(string.Empty, testModel.Daten); + Assert.IsFalse(testModel.Do1Command.CanExecute(null)); + Assert.IsTrue(testModel.Do2Command.CanExecute(null)); + } + [TestMethod()] + public void Do2CommandTest() + { + Assert.IsTrue(testModel.Do2Command.CanExecute(null)); + testModel.Do2Command.Execute(null); + Assert.AreEqual("", testModel.Daten); + Assert.AreEqual(string.Empty, testModel.Text); + Assert.IsFalse(testModel.Do2Command.CanExecute(null)); + Assert.IsTrue(testModel.Do1Command.CanExecute(null)); + } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/MainWindowTests.cs b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/MainWindowTests.cs index a98eccfba..e4517f0e3 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/MainWindowTests.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/MainWindowTests.cs @@ -1,4 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using AA16_UserControl1.ViewModels.Interfaces; +using Avalonia.Headless.MSTest; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; using System.Threading; namespace AA16_UserControl1.Views.Tests; @@ -6,15 +9,16 @@ namespace AA16_UserControl1.Views.Tests; [TestClass()] public class MainWindowTests { - [TestMethod()] + [AvaloniaTestMethod] public void MainWindowTest() { - MainWindow? mw=null; - var t = new Thread(()=> mw = new()); - t.SetApartmentState(ApartmentState.STA); //Set the thread to STA - t.Start(); - t.Join(); //Wait for the thread to end + MainWindow? mw = new() + { + Height = 600, + Width = 800, + DataContext = Substitute.For() + }; Assert.IsNotNull(mw); - Assert.IsInstanceOfType(mw, typeof(MainWindow)); + Assert.IsInstanceOfType(mw, typeof(MainWindow)); } } \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/UserColtrolViewTests.cs b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/UserColtrolViewTests.cs index 49e9f3109..ab8b384ad 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/UserColtrolViewTests.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_UserControl1Tests/Views/UserColtrolViewTests.cs @@ -1,4 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using AA16_UserControl1.ViewModels.Interfaces; +using Avalonia.Headless.MSTest; +using Avalonia.Views.Extension; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; using System.Threading; namespace AA16_UserControl1.Views.Tests; @@ -6,15 +10,29 @@ namespace AA16_UserControl1.Views.Tests; [TestClass()] public class UserControlViewTests { - [TestMethod()] + + [TestInitialize] + public void TestInitialize() + { + IoC.GetReqSrv = t => + { + if (t == typeof(IUserControlViewModel)) + { + return Substitute.For(); + } + throw new System.NotImplementedException($"No registration for type {t}."); + }; + } + + [AvaloniaTestMethod] public void UserControlViewTest() { - UserControlView? testView=null; - 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 - Assert.IsNotNull(testView); + UserControlView? testView = new() + { + Width = 800, + Height = 600, + }; + Assert.IsNotNull(testView); Assert.IsInstanceOfType(testView, typeof(UserControlView)); } } \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/AA16_UserControl1.csproj b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/AA16_UserControl1.csproj index de7338d27..3e5e3e2f8 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/AA16_UserControl1.csproj +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/AA16_UserControl1.csproj @@ -1,4 +1,4 @@ - + WinExe diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/App.axaml.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/App.axaml.cs index c0c0b60d8..111f2a02b 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/App.axaml.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/App.axaml.cs @@ -1,6 +1,8 @@ +using AA16_UserControl1.ViewModels.Interfaces; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.Views.Extension; using Microsoft.Extensions.DependencyInjection; using System; @@ -8,7 +10,6 @@ namespace AA16_UserControl1; public partial class App : Application { - public static IServiceProvider Services { get; set; } = null!; public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -20,12 +21,12 @@ public override void OnFrameworkInitializationCompleted() ConfigureServices(services); - Services = services.BuildServiceProvider(); + IoC.Configure(services.BuildServiceProvider()); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - var mainWindow = Services.GetRequiredService(); - mainWindow.DataContext = Services.GetRequiredService(); + var mainWindow = IoC.GetRequiredService(); + mainWindow.DataContext = IoC.GetRequiredService(); desktop.MainWindow = mainWindow; } @@ -36,7 +37,7 @@ private static void ConfigureServices(IServiceCollection services) { // ViewModels services.AddTransient(); - services.AddTransient(); + services.AddTransient(); // Views services.AddTransient(); diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Directory.Packages.props b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Directory.Packages.props index f17fd09e9..921a6da2f 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Directory.Packages.props +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Directory.Packages.props @@ -3,13 +3,13 @@ true - - - - - + + + + + - + diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IMainWindowViewModel.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IMainWindowViewModel.cs new file mode 100644 index 000000000..337df3283 --- /dev/null +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IMainWindowViewModel.cs @@ -0,0 +1,9 @@ +using System.ComponentModel; + +namespace AA16_UserControl1.ViewModels.Interfaces +{ + public interface IMainWindowViewModel: INotifyPropertyChanged + { + INotifyPropertyChanged CurrentViewModel { get; } + } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IUserControlViewModel.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IUserControlViewModel.cs new file mode 100644 index 000000000..1aa35983b --- /dev/null +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/Interfaces/IUserControlViewModel.cs @@ -0,0 +1,13 @@ +using CommunityToolkit.Mvvm.Input; +using System.ComponentModel; + +namespace AA16_UserControl1.ViewModels.Interfaces; + +public interface IUserControlViewModel: INotifyPropertyChanged +{ + string Text { get; set; } + string Daten { get; set; } + + IRelayCommand Do1Command { get; } + IRelayCommand Do2Command { get; } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/MainWindowViewModel.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/MainWindowViewModel.cs index 9d8dc176d..8bf3d8ff0 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/MainWindowViewModel.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/MainWindowViewModel.cs @@ -1,13 +1,21 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using AA16_UserControl1.ViewModels.Interfaces; +using Avalonia.Views.Extension; +using CommunityToolkit.Mvvm.ComponentModel; +using System.ComponentModel; namespace AA16_UserControl1.ViewModels; -public partial class MainWindowViewModel : ViewModelBase +public partial class MainWindowViewModel : ViewModelBase, IMainWindowViewModel { - public MainWindowViewModel(UserControlViewModel content) + public MainWindowViewModel() + : this(IoC.GetRequiredService()) + { + } + + public MainWindowViewModel(IUserControlViewModel content) { CurrentViewModel = content; } - public ViewModelBase CurrentViewModel { get; } + public INotifyPropertyChanged CurrentViewModel { get; } } diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/UserControlViewModel.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/UserControlViewModel.cs index a4d45937f..4bbbebca1 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/UserControlViewModel.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/ViewModels/UserControlViewModel.cs @@ -1,9 +1,10 @@ +using AA16_UserControl1.ViewModels.Interfaces; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace AA16_UserControl1.ViewModels; -public partial class UserControlViewModel : ViewModelBase +public partial class UserControlViewModel : ViewModelBase, IUserControlViewModel { [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(Do1Command))] diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml index 809932260..a90025495 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml @@ -1,8 +1,8 @@ diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml.cs b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml.cs index 9bce823e0..b02972e1c 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml.cs +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol1/Views/UserControlView.axaml.cs @@ -1,6 +1,8 @@ using Avalonia.Controls; using Microsoft.Extensions.DependencyInjection; using AA16_UserControl1.ViewModels; +using AA16_UserControl1.ViewModels.Interfaces; +using Avalonia.Views.Extension; namespace AA16_UserControl1.Views; @@ -9,6 +11,6 @@ public partial class UserControlView : UserControl public UserControlView() { InitializeComponent(); - DataContext ??= App.Services.GetRequiredService(); + DataContext ??= IoC.GetRequiredService(); } } diff --git a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol2/AA16_UserControl2.csproj b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol2/AA16_UserControl2.csproj index aeb7c33fb..ed77aa851 100644 --- a/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol2/AA16_UserControl2.csproj +++ b/Avalonia_Apps/AA16_UserControl/AA16_Usercontrol2/AA16_UserControl2.csproj @@ -25,4 +25,11 @@ + + + + + + + diff --git a/Avalonia_Apps/AA16_UserControl/Directory.Packages.props b/Avalonia_Apps/AA16_UserControl/Directory.Packages.props index 1afdd3db4..7eb87d870 100644 --- a/Avalonia_Apps/AA16_UserControl/Directory.Packages.props +++ b/Avalonia_Apps/AA16_UserControl/Directory.Packages.props @@ -1,29 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/AA18_MultiConverters.csproj b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/AA18_MultiConverters.csproj index 0d373bb9a..1c16896a3 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/AA18_MultiConverters.csproj +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/AA18_MultiConverters.csproj @@ -25,4 +25,11 @@ + + + + + + + diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/App.axaml.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/App.axaml.cs index 3be292e9d..d40cea5d0 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/App.axaml.cs +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/App.axaml.cs @@ -1,3 +1,4 @@ +using AA18_MultiConverter.ViewModels.Interfaces; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; @@ -33,7 +34,7 @@ public override void OnFrameworkInitializationCompleted() private static void ConfigureServices(IServiceCollection services) { // ViewModels - services.AddTransient(); + services.AddTransient(); // Views services.AddTransient(); diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/DateDifViewModel.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/DateDifViewModel.cs index e651876f1..9f14adb16 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/DateDifViewModel.cs +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/DateDifViewModel.cs @@ -14,10 +14,11 @@ using CommunityToolkit.Mvvm.ComponentModel; using AA18_MultiConverter.Model; using System; +using AA18_MultiConverter.ViewModels.Interfaces; namespace AA18_MultiConverter.ViewModels; -public partial class DateDifViewModel : ObservableObject +public partial class DateDifViewModel : ObservableObject, IDateDifViewModel { public static Func GetNow { get; set; } = () => DateTimeOffset.Now; diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/Interfaces/IDateDifViewModel.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/Interfaces/IDateDifViewModel.cs new file mode 100644 index 000000000..55586c84e --- /dev/null +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/ViewModels/Interfaces/IDateDifViewModel.cs @@ -0,0 +1,25 @@ +// *********************************************************************** +// Assembly : MVVM_18_MultiConverters +// Author : Mir +// Created : 07-05-2022 +// +// Last Modified By : Mir +// Last Modified On : 07-05-2022 +// *********************************************************************** +// +// Copyright (c) JC-Soft. All rights reserved. +// +// +// *********************************************************************** +using AA18_MultiConverter.Model; + +namespace AA18_MultiConverter.ViewModels.Interfaces; + +public interface IDateDifViewModel +{ + DateTimeOffset StartDate { get; set; } + DateTimeOffset EndDate { get; set; } + DateDifFormat Format { get; set; } + TimeSpan DateDif { get; } + DateDifFormat[] DateFormats { get; } +} \ No newline at end of file diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml index 8cf6c9192..29ac837cb 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml @@ -1,10 +1,10 @@ + x:DataType="vmi:IDateDifViewModel"> diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml.cs index d5a3a0757..0b5d13b9a 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml.cs +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConverters/Views/DateDifView.axaml.cs @@ -1,3 +1,4 @@ +using AA18_MultiConverter.ViewModels.Interfaces; using Avalonia.Controls; using Microsoft.Extensions.DependencyInjection; @@ -8,6 +9,6 @@ public partial class DateDifView : UserControl public DateDifView() { InitializeComponent(); - DataContext = App.Services.GetRequiredService(); + DataContext = App.Services.GetRequiredService(); } } diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/DateDifViewTests.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/DateDifViewTests.cs index 01cbdc328..f06c8ccb3 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/DateDifViewTests.cs +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/DateDifViewTests.cs @@ -1,4 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using AA18_MultiConverter.ViewModels; +using AA18_MultiConverter.ViewModels.Interfaces; +using Avalonia.Headless.MSTest; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; +using System; using System.Threading; namespace AA18_MultiConverter.Views.Tests; @@ -8,14 +14,18 @@ public class DateDifViewTests { DateDifView? testView; - [TestMethod()] + [TestInitialize] + public void TestInitialize() + { + var services = typeof(App).GetProperty(nameof(App.Services)); + services.SetValue(null,Substitute.For()); + App.Services.GetService(typeof(IDateDifViewModel)).Returns(Substitute.For()); + } + + [AvaloniaTestMethod()] public void DateDifViewTest() { - testView = null; - 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 + testView = new(); Assert.IsNotNull(testView); Assert.IsInstanceOfType(testView, typeof(DateDifView)); } diff --git a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/MainWindowTests.cs b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/MainWindowTests.cs index a5d0182c9..dbbeef149 100644 --- a/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/MainWindowTests.cs +++ b/Avalonia_Apps/AA18_MultiConverter/AA18_MultiConvertersTests/View/MainWindowTests.cs @@ -1,4 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using AA18_MultiConverter.ViewModels.Interfaces; +using Avalonia.Headless.MSTest; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NSubstitute; +using System; using System.Threading; namespace AA18_MultiConverter.Views.Tests; @@ -8,14 +12,18 @@ public class MainWindowTests { MainWindow? testView; - [TestMethod()] + [TestInitialize] + public void TestInitialize() + { + var services = typeof(App).GetProperty(nameof(App.Services)); + services.SetValue(null, Substitute.For()); + App.Services.GetService(typeof(IDateDifViewModel)).Returns(Substitute.For()); + } + + [AvaloniaTestMethod()] public void MainWindowTest() { - testView = null; - var t = new Thread(() => testView = new(null)); - t.SetApartmentState(ApartmentState.STA); //Set the thread to STA - t.Start(); - t.Join(); //Wait for the thread to end + testView = new(null); Assert.IsNotNull(testView); Assert.IsInstanceOfType(testView, typeof(MainWindow)); } diff --git a/Avalonia_Apps/AA18_MultiConverter/Directory.Packages.props b/Avalonia_Apps/AA18_MultiConverter/Directory.Packages.props index 266ecf965..7eb87d870 100644 --- a/Avalonia_Apps/AA18_MultiConverter/Directory.Packages.props +++ b/Avalonia_Apps/AA18_MultiConverter/Directory.Packages.props @@ -1,29 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA19_FilterLists/AA19_FilterLists/AA19_FilterLists.csproj b/Avalonia_Apps/AA19_FilterLists/AA19_FilterLists/AA19_FilterLists.csproj index 125e1e8fd..daf30f25c 100644 --- a/Avalonia_Apps/AA19_FilterLists/AA19_FilterLists/AA19_FilterLists.csproj +++ b/Avalonia_Apps/AA19_FilterLists/AA19_FilterLists/AA19_FilterLists.csproj @@ -60,4 +60,12 @@ + + + + + + + + diff --git a/Avalonia_Apps/AA19_FilterLists/Directory.Packages.props b/Avalonia_Apps/AA19_FilterLists/Directory.Packages.props index d5f6f29d7..7eb87d870 100644 --- a/Avalonia_Apps/AA19_FilterLists/Directory.Packages.props +++ b/Avalonia_Apps/AA19_FilterLists/Directory.Packages.props @@ -1,31 +1,3 @@ - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/AA20_Sysdialogs.csproj b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/AA20_Sysdialogs.csproj index ac63b39c4..3c8797919 100644 --- a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/AA20_Sysdialogs.csproj +++ b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/AA20_Sysdialogs.csproj @@ -3,7 +3,7 @@ WinExe - net8.0;net9.0 + net8.0 enable enable true @@ -11,7 +11,13 @@ - + + $(TargetFrameworks);net9.0 + + + $(TargetFrameworks);net10.0 + + diff --git a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/MainWindow.axaml b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/MainWindow.axaml index 000a171e8..99f7dca33 100644 --- a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/MainWindow.axaml +++ b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/MainWindow.axaml @@ -1,9 +1,9 @@ - + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:views="clr-namespace:AA20_SysDialogs.Views" + mc:Ignorable="d" x:Class="AA20_SysDialogs.MainWindow" + Width="800" Height="600" Title="AA20 System Dialogs"> + diff --git a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/Views/SysDialogs.axaml b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/Views/SysDialogs.axaml index 237a3ad2d..c4a61d943 100644 --- a/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/Views/SysDialogs.axaml +++ b/Avalonia_Apps/AA20_SysDialogs/AA20_Sysdialogs/Views/SysDialogs.axaml @@ -1,48 +1,48 @@ - - - - - - - - -