Skip to content
Merged

sync #527

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions CSharpBible/Libraries/MVVM_BaseLib/Helper/StreamHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,44 @@ public static void EnumerateToStream(this Stream stream, IEnumerable<(string, ob
{
case Type t when t == typeof(Point):
streamBytes = new byte[sizeof(int) * 2];
stream.Read(streamBytes, 0, sizeof(int) * 2);
yield return (e.Item1, new Point(BitConverter.ToInt32(streamBytes, 0), BitConverter.ToInt32(streamBytes, sizeof(int))));
if (stream.Read(streamBytes, 0, sizeof(int) * 2) == sizeof(int) * 2)
yield return (e.Item1, new Point(BitConverter.ToInt32(streamBytes, 0), BitConverter.ToInt32(streamBytes, sizeof(int))));
else
yield return (e.Item1, new Point()); // ?? default value
break;
case Type t when t == typeof(int):
streamBytes = new byte[sizeof(int)];
stream.Read(streamBytes, 0, sizeof(int));
yield return (e.Item1, BitConverter.ToInt32(streamBytes, 0));
if (stream.Read(streamBytes, 0, sizeof(int))== sizeof(int))
yield return (e.Item1, BitConverter.ToInt32(streamBytes, 0));
else
yield return (e.Item1, 0); // ?? default value
break;
case Type t when t == typeof(bool):
streamBytes = new byte[sizeof(bool)];
stream.Read(streamBytes, 0, sizeof(bool));
yield return (e.Item1, BitConverter.ToBoolean(streamBytes, 0));
if (stream.Read(streamBytes, 0, sizeof(bool))== sizeof(bool))
yield return (e.Item1, BitConverter.ToBoolean(streamBytes, 0));
else
yield return (e.Item1, false); // ?? default value
break;
case Type t when t == typeof(byte):
streamBytes = new byte[sizeof(byte)];
stream.Read(streamBytes, 0, sizeof(byte));
yield return (e.Item1, streamBytes[0]);
if (stream.Read(streamBytes, 0, sizeof(byte)) == sizeof(byte))
yield return (e.Item1, streamBytes[0]);
else
yield return (e.Item1, (byte)0); // ?? default value
break;
case Type t when t == typeof(IEnumerable<int>):
streamBytes = new byte[sizeof(short)];
stream.Read(streamBytes, 0, sizeof(short));
_ = stream.Read(streamBytes, 0, sizeof(short));
var count = BitConverter.ToInt16(streamBytes, 0);
streamBytes = new byte[sizeof(int) * count];
stream.Read(streamBytes, 0, sizeof(int) * count);
_ = stream.Read(streamBytes, 0, sizeof(int) * count);
yield return (e.Item1, streamBytes.Select<byte, int?>((b, i) => i % sizeof(int) == 0 ? BitConverter.ToInt32(streamBytes, i) : null).Where((i) => i != null));
break;
case Type t when t.IsGenericType && t.GetGenericTypeDefinition()== typeof(IEnumerable<>):
var t2 = t.GetGenericArguments()[0];
streamBytes = new byte[sizeof(int)];
stream.Read(streamBytes, 0, sizeof(int));
_ = stream.Read(streamBytes, 0, sizeof(int));
var count32 = BitConverter.ToInt32(streamBytes, 0);
var result = new IPersistence?[count32];
if (t2.IsClass && t2.GetConstructors().FirstOrDefault(c => c.IsPublic)!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DoubleValueConverter : IValueConverter
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. If the method returns <see langword="null" />, the valid null value is used.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -54,7 +54,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. If the method returns <see langword="null" />, the valid null value is used.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BaseLib.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVVM_BaseLib.Helper;
using BaseLib.Helper;
using static BaseLib.Helper.TestHelper;

namespace BaseLib.Helper.MVVM.Tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public class IoCTests : BaseTestViewModel
{
private Func<Type, object?>? _gsOld;
private Func<Type, object>? _grsOld;
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
private Func<IServiceScope> _gscOld;
private IServiceScopeFactory _f;
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.

private object GetReqSrv(Type arg)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class DoubleValueConverterTests
/// The converter
/// </summary>
/// <autogeneratedoc />
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
DoubleValueConverter testConv;
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.

[TestInitialize]
public void Init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<Import Project="..\Libraries_net.props" />
<PropertyGroup>
<TargetFrameworks>net481-windows;net48-windows;net472-windows;net462-windows;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
13 changes: 7 additions & 6 deletions CSharpBible/Libraries/MathLibraryTests/TwoDim/StTrackSegTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public void StTrackSegTests1()

[DataTestMethod]
[DataRow(new[] { 1d, 2d }, new[] { 3d, 4d },5d)]
public void StTrackSegTests1(double[] adAct1, double[] adAct2,double fAct3)
[DataRow(new[] { 6d, 5d }, new[] { 4d, 3d },2d)]
public void StTrackSegTests2(double[] adAct1, double[] adAct2,double fAct3)
{
var st = new StTrackSeg(new(adAct1[0], adAct1[1]),new(adAct2[0], adAct2[1]),fAct3);
Assert.IsNotNull(st);
Assert.IsInstanceOfType(st, typeof(StTrackSeg));
Assert.AreEqual(adAct1[0], st.vNormal.x);
Assert.AreEqual(adAct1[1], st.vNormal.y);
Assert.AreEqual(adAct2[0], st.vFootPoint.x);
Assert.AreEqual(adAct2[1], st.vFootPoint.y);
Assert.AreEqual(fAct3, st.lrRadius);
Assert.AreEqual(adAct1[0], st.vFootPoint.x, nameof(st.vFootPoint));
Assert.AreEqual(adAct1[1], st.vFootPoint.y, nameof(st.vFootPoint));
Assert.AreEqual(adAct2[0], st.vNormal.x,nameof(st.vNormal));
Assert.AreEqual(adAct2[1], st.vNormal.y, nameof(st.vNormal));
Assert.AreEqual(fAct3, st.lrRadius, nameof(st.lrRadius));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.0" />
<PackageReference Include="MSTest" Version="3.7.0" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.0" />
<PackageReference Include="MSTest" Version="3.7.0" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.0" />
<PackageReference Include="MSTest" Version="3.7.0" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion CSharpBible/MVVM_Tutorial/MVVM_22_CTWpfCap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using BaseLib.Interfaces;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using MVVM.View.Extension;
using MVVM_22_CTWpfCap.Model;
using MVVM_22_CTWpfCap.ViewModels;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;

namespace MVVM_22_CTWpfCap.Model.Tests
{
Expand Down
2 changes: 1 addition & 1 deletion CSharpBible/MVVM_Tutorial/MVVM_22_WpfCap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// ***********************************************************************
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using BaseLib.Interfaces;
using MVVM.View.Extension;
using MVVM_22_WpfCap.Model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="5.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="5.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;

namespace MVVM_22_WpfCap.Model.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Specialized;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVVM_22_WpfCap.Model;
using Telerik.JustMock;
using NSubstitute;

namespace MVVM_22_WpfCap.ViewModels.Tests
{
Expand Down Expand Up @@ -111,12 +111,11 @@ public void SetUpTest()
[TestMethod()]
public void WpfCapViewModelTest()
{
var mdl = Mock.Create<IWpfCapModel>();
var mdl = Substitute.For<IWpfCapModel>();
var _testWpfCapVM = new WpfCapViewModel(mdl);
Assert.IsNotNull(_testWpfCapVM);
Mock.Assert(mdl);
Mock.Assert(() => mdl.Init());
Mock.Assert(() => mdl.Shuffle());
mdl.Received(1).Init();
mdl.Received(1).Shuffle();
}

[TestMethod()]
Expand Down
15 changes: 7 additions & 8 deletions CSharpBible/MVVM_Tutorial/MVVM_25_RichTextEdit/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Application x:Class="MVVM_25_RichTextEdit.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MVVM_25_RichTextEdit"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
<Application
x:Class="MVVM_25_RichTextEdit.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MVVM_25_RichTextEdit"
StartupUri="MainWindow.xaml">
<Application.Resources />
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using BaseLib.Interfaces;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using MVVM.View.Extension;
using MVVM_28_1_CTDataGridExt.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using BaseLib.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVVM.View.Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using MVVM.ViewModel;
using MVVM_28_1_DataGridExt.Models;
using MVVM_28_1_DataGridExt.Services;
Expand All @@ -21,7 +21,7 @@ public class DataGridViewModel : BaseViewModel
public bool IsItemSelected => SelectedPerson != null;
public DataGridViewModel() {
var svc = new PersonService(
new CRandom());
new CRandom());
foreach(var person in svc.GetPersons())
Persons.Add(person);
foreach (var deprtment in svc.GetDepartments())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BaseLib.Interfaces;
using BaseLib.Helper.MVVM;
using BaseLib.Helper;
using MVVM.View.Extension;
using MVVM_28_1_DataGridExt.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:local="clr-namespace:MVVM_33_Events_To_Commands.Views"
xmlns:vc="clr-namespace:MVVM_33_Events_To_Commands.ValueConverter"
xmlns:mvvm="clr-namespace:MVVM_33_Events_To_Commands.ViewModels"
xmlns:model="clr-namespace:MVVM_33_Events_To_Commands.Models"
xmlns:behav="http://schemas.microsoft.com/xaml/behaviors"
x:Class="MVVM_33_Events_To_Commands.Views.EventBindingView"
mc:Ignorable="d"
Expand Down
14 changes: 11 additions & 3 deletions CSharpBible/MVVM_Tutorial/MVVM_41_Sudoku/Models/PagePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class PagePrinter
private const int cA4Height = 297; //[mm]
private const int cBoarder = 10; //[mm]

public static void Print(string printerName, string title, object data, Action<string, object, DrawingContext, Rect> drawPage)
public static void Print(string printerName, string title, object? data, Action<string, object, DrawingContext, Rect> drawPage)
{

PrintQueue? printQueue = GetPrintQueue(printerName);
Expand All @@ -30,8 +30,12 @@ public static void Print(string printerName, string title, object data, Action<s
Print(printQueue, ticket, title, data, drawPage);
}

public static void Print(PrintQueue? printQueue, PrintTicket ticket, string title, object data, Action<string, object, DrawingContext, Rect> drawPage)
public static void Print(PrintQueue? printQueue, PrintTicket ticket, string title, object? data, Action<string, object, DrawingContext, Rect> drawPage)
{
if (printQueue == null)
{
return;
}
printQueue.Comment = $"Comment: {title}";
printQueue.CurrentJobSettings.Description = $"Desc: {title}";
var writer = PrintQueue.CreateXpsDocumentWriter(printQueue);
Expand All @@ -52,7 +56,11 @@ public static void Print(PrintQueue? printQueue, PrintTicket ticket, string titl

private static PrintTicket GetTicket(PrintQueue? printQueue)
{
var ticket = printQueue.UserPrintTicket;
var ticket = printQueue?.UserPrintTicket;
if (ticket == null)
{
return new PrintTicket();
}
ticket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
ticket.PageOrientation = PageOrientation.Portrait;
ticket.PageResolution = new PageResolution(300, 300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public SudokuViewModel():this(IoC.GetRequiredService<ISudokuModel>())
{
}

#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
public SudokuViewModel(ISudokuModel model)
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
{
_model = model;
_model.PropertyChanged += OnMPropertyChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ namespace MVVM_41_Sudoku.Models.Tests;
[TestClass]
public class SimpleLogTests:BaseTestViewModel
{
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
private Action<string> _gsOld;
private ISysTime? _sysTime;
private SimpleLog simpleLog;
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
private ISysTime? _sysTime;


[TestInitialize]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace MVVM_41_Sudoku.Models.Tests;
[TestClass]
public class SudokuPrinterTests
{
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.
ISudokuModel _model;
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Fügen Sie ggf. den „erforderlichen“ Modifizierer hinzu, oder deklarieren Sie den Modifizierer als NULL-Werte zulassend.

[TestInitialize]
public void Init()
{
Expand Down Expand Up @@ -45,7 +48,7 @@ public void PrintTest2()
PagePrinter.Print("PDF", "TestPage", null, TestPage );
}

private void TestPage(string title, object data, DrawingContext dc, Rect r)
private void TestPage(string title, object? data, DrawingContext dc, Rect r)
{
Pen blackLinePen = new Pen(Brushes.Black, 0.5);

Expand Down
Loading