1
0

Updated to C# 12

This commit is contained in:
2024-01-14 13:10:33 +01:00
parent 9cd1344266
commit 27cd54fb30
51 changed files with 637 additions and 379 deletions

View File

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using AMWD.Common.AspNetCore.Security.BasicAuthentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -156,12 +157,16 @@ namespace UnitTests.AspNetCore.Security.BasicAuthentication
var requestHeaderMock = new Mock<IHeaderDictionary>();
foreach (var header in _requestHeaders)
{
var strVal = new StringValues(header.Value);
requestHeaderMock
.Setup(h => h.ContainsKey(header.Key))
.Returns(true);
requestHeaderMock
.Setup(h => h[header.Key])
.Returns(header.Value);
.Returns(strVal);
requestHeaderMock
.Setup(h => h.TryGetValue(header.Key, out strVal))
.Returns(true);
}
var requestMock = new Mock<HttpRequest>();
@@ -174,6 +179,11 @@ namespace UnitTests.AspNetCore.Security.BasicAuthentication
responseHeaderMock
.SetupSet(h => h[It.IsAny<string>()] = It.IsAny<StringValues>())
.Callback<string, StringValues>((key, value) => _responseHeadersCallback[key] = value);
#pragma warning disable CS0618
responseHeaderMock
.SetupSet(h => h.WWWAuthenticate)
.Callback((value) => _responseHeadersCallback[HeaderNames.WWWAuthenticate] = value);
#pragma warning restore CS0618
var responseMock = new Mock<HttpResponse>();
responseMock

View File

@@ -108,22 +108,6 @@ namespace UnitTests.Common.Extensions
Assert.IsFalse(list.Any());
}
[TestMethod]
public void ShouldReturnDisplayNameOrStringRepresentation()
{
// arrange
var enumWithDisplayName = TestEnum.Two;
var enumWithoutDisplayName = TestEnum.Zero;
// act
string displayName = enumWithDisplayName.GetDisplayName();
string noDisplayName = enumWithoutDisplayName.GetDisplayName();
// assert
Assert.AreEqual("Zwei", displayName);
Assert.AreEqual(enumWithoutDisplayName.ToString(), noDisplayName);
}
internal enum TestEnum
{
[CustomMultiple("nix")]
@@ -132,7 +116,6 @@ namespace UnitTests.Common.Extensions
Zero,
[Description("Eins")]
One,
[Display(Name = "Zwei")]
Two,
}
}

View File

@@ -12,16 +12,16 @@ namespace UnitTests.Common.Packing.Ar
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class ArReaderTests
{
private readonly DateTime fixedDateTime = new(2023, 03, 01, 10, 20, 30, 0, DateTimeKind.Utc);
private readonly DateTime _fixedDateTime = new(2023, 03, 01, 10, 20, 30, 0, DateTimeKind.Utc);
private Dictionary<string, ArFileInfo> files;
private Dictionary<string, ArFileInfo> _files;
private Stream inStream;
[TestInitialize]
public void Initialize()
{
files = new Dictionary<string, ArFileInfo>
_files = new Dictionary<string, ArFileInfo>
{
{
"abcd.tmp",
@@ -31,7 +31,7 @@ namespace UnitTests.Common.Packing.Ar
FileSize = 14,
GroupId = 456,
Mode = 33188,
ModifyTime = fixedDateTime,
ModifyTime = _fixedDateTime,
UserId = 123
}
},
@@ -43,7 +43,7 @@ namespace UnitTests.Common.Packing.Ar
FileSize = 14,
GroupId = 456,
Mode = 33188,
ModifyTime = fixedDateTime,
ModifyTime = _fixedDateTime,
UserId = 123
}
},
@@ -55,7 +55,7 @@ namespace UnitTests.Common.Packing.Ar
FileSize = 13,
GroupId = 456,
Mode = 33188,
ModifyTime = fixedDateTime,
ModifyTime = _fixedDateTime,
UserId = 123
}
}
@@ -64,7 +64,7 @@ namespace UnitTests.Common.Packing.Ar
inStream = new MemoryStream();
inStream.Write(Encoding.ASCII.GetBytes("!<arch>\n"));
foreach (var file in files)
foreach (var file in _files)
{
int unixSeconds = (int)file.Value.ModifyTime.Subtract(DateTime.UnixEpoch).TotalSeconds;
@@ -125,9 +125,9 @@ namespace UnitTests.Common.Packing.Ar
// Assert
Assert.IsNotNull(reader);
Assert.AreEqual(files.Count, fileList.Count);
Assert.AreEqual(_files.Count, fileList.Count);
foreach (string name in files.Keys)
foreach (string name in _files.Keys)
Assert.IsTrue(fileList.Contains(name));
}
@@ -139,14 +139,14 @@ namespace UnitTests.Common.Packing.Ar
var reader = new ArReader(inStream);
// Act
foreach (string name in files.Keys)
foreach (string name in _files.Keys)
infos.Add(reader.GetFileInfo(name));
// Assert
Assert.IsNotNull(reader);
Assert.AreEqual(files.Count, infos.Count);
Assert.AreEqual(_files.Count, infos.Count);
foreach (var expected in files.Values)
foreach (var expected in _files.Values)
{
var actual = infos.Single(fi => fi.FileName == expected.FileName);
@@ -167,7 +167,7 @@ namespace UnitTests.Common.Packing.Ar
var reader = new ArReader(inStream);
// Act
foreach (string name in files.Keys)
foreach (string name in _files.Keys)
{
using var ms = new MemoryStream();
reader.ReadFile(name, ms);
@@ -178,9 +178,9 @@ namespace UnitTests.Common.Packing.Ar
// Assert
Assert.IsNotNull(reader);
Assert.AreEqual(files.Count, contents.Count);
Assert.AreEqual(_files.Count, contents.Count);
foreach (var expected in files.Values)
foreach (var expected in _files.Values)
{
string content = contents[expected.FileName];

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests.Common.Packing.Tar
{
internal class TarReaderTests
{
}
}

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<IsPackable>false</IsPackable>
<CollectCoverage>true</CollectCoverage>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
@@ -13,8 +14,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="DNS" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="ReflectionMagic" Version="5.0.0" />