1
0

Erweiterung der UnitTests und kleinere Fixes

This commit is contained in:
2021-11-17 23:30:54 +01:00
parent 3a0732dd22
commit 80fc6ff2b3
16 changed files with 873 additions and 37 deletions

View File

@@ -2,6 +2,7 @@
namespace AMWD.Common.Tests.Utils
{
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
internal class CustomMultipleAttribute : Attribute
{

View File

@@ -0,0 +1,32 @@
using System;
namespace AMWD.Common.Tests.Utils
{
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal class JsonTestClass
{
public string StringValue { get; set; } = "Hello World!";
public bool IsBoolTrue { get; set; } = true;
public float FloatValue { get; set; } = 12.34f;
public double DoubleValue { get; set; } = 21.42;
public decimal DecimalValue { get; set; } = 42.21m;
public DateTime LocalTimestamp { get; set; } = new(2021, 11, 16, 20, 15, 34, DateTimeKind.Local);
public DateTime UtcTimestamp { get; set; } = new(2021, 11, 16, 20, 15, 34, DateTimeKind.Utc);
public JsonTestSubClass Object { get; set; } = new();
}
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal class JsonTestSubClass
{
public int IntegerValue { get; set; } = 42;
public string StringValue { get; set; } = "Foo-Bar";
}
}

View File

@@ -0,0 +1,26 @@
using System;
using ReflectionMagic;
namespace AMWD.Common.Tests.Utils
{
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class TimeZoneInfoLocalMock : IDisposable
{
private readonly TimeZoneInfo localTimeZoneInfo;
private TimeZoneInfoLocalMock(TimeZoneInfo timeZoneInfo)
{
localTimeZoneInfo = TimeZoneInfo.Local;
SetLocalTimeZone(timeZoneInfo);
}
public static IDisposable Create(TimeZoneInfo mockTimeZoneInfo)
=> new TimeZoneInfoLocalMock(mockTimeZoneInfo);
public void Dispose()
=> SetLocalTimeZone(localTimeZoneInfo);
private static void SetLocalTimeZone(TimeZoneInfo timeZoneInfo)
=> typeof(TimeZoneInfo).AsDynamicType().s_cachedData._localTimeZone = timeZoneInfo;
}
}