Skip to content

Commit db2a440

Browse files
Finish migrating to C# 10.0 and cleanup (#43)
- Convert to file-scoped namespaces - Convert to using new(...) - Remove unnecessary using statements
1 parent 937f713 commit db2a440

File tree

7 files changed

+62
-75
lines changed

7 files changed

+62
-75
lines changed
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
using System;
1+
using IntelliTect.Multitool.Security;
22
using System.Security.Claims;
33
using System.Security.Principal;
4-
using IntelliTect.Multitool.Security;
54
using Xunit;
65

7-
namespace IntelliTect.Multitool.Tests
6+
namespace IntelliTect.Multitool.Tests;
7+
8+
public class ClaimsPrincipalGetRolesTests
89
{
9-
public class ClaimsPrincipalGetRolesTests
10+
[Fact]
11+
public void WhenClaimsPrincipalNull_Should_Throw()
1012
{
11-
[Fact]
12-
public void WhenClaimsPrincipalNull_Should_Throw()
13-
{
14-
ClaimsPrincipal? sut = null;
13+
ClaimsPrincipal? sut = null;
1514

16-
Assert.Throws<ArgumentNullException>(() => sut!.GetRoles());
17-
}
15+
Assert.Throws<ArgumentNullException>(() => sut!.GetRoles());
16+
}
1817

19-
[Fact]
20-
public void WhenClaimsPrincipalHasNoRoles_Should_ReturnEmpty()
21-
{
22-
ClaimsPrincipal sut = new ClaimsPrincipal();
18+
[Fact]
19+
public void WhenClaimsPrincipalHasNoRoles_Should_ReturnEmpty()
20+
{
21+
ClaimsPrincipal sut = new();
2322

24-
Assert.Empty(sut.GetRoles());
25-
}
23+
Assert.Empty(sut.GetRoles());
24+
}
2625

27-
[Fact]
28-
public void WhenClaimsPrincipalHasRoles_Should_ReturnNotEmpty()
29-
{
30-
ClaimsPrincipal sut = new GenericPrincipal(new GenericIdentity("Uncle Festus"), new[] {"Foo", "Bar"});
26+
[Fact]
27+
public void WhenClaimsPrincipalHasRoles_Should_ReturnNotEmpty()
28+
{
29+
ClaimsPrincipal sut = new GenericPrincipal(new GenericIdentity("Uncle Festus"), new[] { "Foo", "Bar" });
3130

32-
Assert.Collection(sut.GetRoles(), s => Assert.Equal("Foo", s), t => Assert.Equal("Bar", t) );
33-
}
31+
Assert.Collection(sut.GetRoles(), s => Assert.Equal("Foo", s), t => Assert.Equal("Bar", t));
3432
}
3533
}

IntelliTect.Multitool.Tests/ClaimsPrincipalGetUserIdTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using System;
1+
using IntelliTect.Multitool.Security;
22
using System.Security.Claims;
33
using System.Security.Principal;
4-
using IntelliTect.Multitool.Security;
54
using Xunit;
65

76
namespace IntelliTect.Multitool.Tests;
@@ -19,15 +18,15 @@ public void WhenClaimsPrincipalNull_Should_Throw()
1918
[Fact]
2019
public void WhenClaimsPrincipalHasNoProperty_Should_ReturnNull()
2120
{
22-
ClaimsPrincipal sut = new ClaimsPrincipal();
21+
ClaimsPrincipal sut = new();
2322

2423
Assert.Null(sut.GetUserId());
2524
}
2625

2726
[Fact]
2827
public void WhenClaimsPrincipalHasId_Should_ReturnString()
2928
{
30-
ClaimsPrincipal sut = new GenericPrincipal(new GenericIdentity("Taki The Frog"), new []{ "Bar" } );
29+
ClaimsPrincipal sut = new GenericPrincipal(new GenericIdentity("Taki The Frog"), new[] { "Bar" });
3130

3231
Assert.Equal("Taki The Frog", sut.GetUserId());
3332
}

IntelliTect.Multitool.Tests/IntelliTect.Multitool.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Moq" Version="4.18.2" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
1212
<PackageReference Include="xunit" Version="2.4.2" />
1313
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1414
<PrivateAssets>all</PrivateAssets>

IntelliTect.Multitool.Tests/RepositoryPaths.Tests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Security.Claims;
3-
using System.Security.Principal;
4-
using Xunit;
1+
using Xunit;
52

63
namespace IntelliTect.Multitool.Tests;
74

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,52 @@
1-
using System;
2-
using System.IO;
3-
using System.Reflection;
1+
using System.Reflection;
42

5-
namespace IntelliTect.Multitool
3+
namespace IntelliTect.Multitool;
4+
5+
/// <summary>
6+
/// Information about the executing assembly.
7+
/// </summary>
8+
public static class AssemblyInfo
69
{
10+
private static DateTime? _Date;
11+
712
/// <summary>
8-
/// Information about the executing assembly.
13+
/// Gets the linker date from the assembly header.
914
/// </summary>
10-
public static class AssemblyInfo
15+
public static DateTime Date
1116
{
12-
private static DateTime? _Date;
13-
14-
/// <summary>
15-
/// Gets the linker date from the assembly header.
16-
/// </summary>
17-
public static DateTime Date
17+
get
1818
{
19-
get
19+
if (_Date == null)
2020
{
21-
if (_Date == null)
22-
{
23-
_Date = GetLinkerTime(Assembly.GetExecutingAssembly());
24-
}
25-
return _Date.Value;
21+
_Date = GetLinkerTime(Assembly.GetExecutingAssembly());
2622
}
23+
return _Date.Value;
2724
}
25+
}
2826

29-
/// <summary>
30-
/// Gets the linker date of the assembly.
31-
/// </summary>
32-
/// <param name="assembly"></param>
33-
/// <returns></returns>
34-
/// <remarks>https://blog.codinghorror.com/determining-build-date-the-hard-way/</remarks>
35-
private static DateTime GetLinkerTime(Assembly assembly)
36-
{
37-
var filePath = assembly.Location;
38-
const int cPeHeaderOffset = 60;
39-
const int cLinkerTimestampOffset = 8;
27+
/// <summary>
28+
/// Gets the linker date of the assembly.
29+
/// </summary>
30+
/// <param name="assembly"></param>
31+
/// <returns></returns>
32+
/// <remarks>https://blog.codinghorror.com/determining-build-date-the-hard-way/</remarks>
33+
private static DateTime GetLinkerTime(Assembly assembly)
34+
{
35+
var filePath = assembly.Location;
36+
const int cPeHeaderOffset = 60;
37+
const int cLinkerTimestampOffset = 8;
4038

41-
var buffer = new byte[2048];
39+
var buffer = new byte[2048];
4240

43-
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
44-
stream.Read(buffer, 0, 2048);
41+
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
42+
stream.Read(buffer, 0, 2048);
4543

46-
var offset = BitConverter.ToInt32(buffer, cPeHeaderOffset);
47-
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + cLinkerTimestampOffset);
48-
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
44+
var offset = BitConverter.ToInt32(buffer, cPeHeaderOffset);
45+
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + cLinkerTimestampOffset);
46+
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
4947

50-
var linkTimeUtc = epoch.AddSeconds(secondsSince1970);
48+
var linkTimeUtc = epoch.AddSeconds(secondsSince1970);
5149

52-
return linkTimeUtc;
53-
}
50+
return linkTimeUtc;
5451
}
5552
}

IntelliTect.Multitool/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
32

43

54
[assembly: CLSCompliant(true)]

IntelliTect.Multitool/Security/ClaimsPrincipalExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Security.Claims;
1+
using System.Security.Claims;
52

63
namespace IntelliTect.Multitool.Security;
74

0 commit comments

Comments
 (0)