From 3ac4b74b690019bbe78beff21d9f7a405b215cad Mon Sep 17 00:00:00 2001 From: Karol Berezicki Date: Mon, 14 Aug 2023 22:16:31 +0200 Subject: [PATCH] feat: Upgrade to .NET 6 --- README.md | 12 +- .../AnotherExampleUsageAssembly.csproj | 62 ++------ .../AnotherExampleUsageAssembly/Mango.cs | 11 +- .../ExampleUsage.Tests.csproj | 119 +++------------- .../UsingTechDebtAttributesInTests.cs | 46 +++--- .../ExampleUsage.Tests/packages.config | 43 ------ src/TechDebtAttributes/ExampleUsage/Cheese.cs | 17 ++- .../ExampleUsage/ExampleUsage.csproj | 67 ++------- .../ExampleUsage/ISomeDumbInterface.cs | 9 +- .../ExampleUsage/ISomeExampleInterface.cs | 15 +- .../ExampleUsage/SillyEnum.cs | 17 ++- .../ExampleUsage/SomeThing.cs | 15 +- .../SomeThingWithDumbConstructor.cs | 13 +- .../TechDebtAttributes.Tests.csproj | 132 ++++-------------- .../TechDebtReporterTests.cs | 63 ++++----- .../TechDebtAttributes.Tests/packages.config | 46 ------ src/TechDebtAttributes/TechDebtAttributes.sln | 12 +- .../TechDebtAttributes/Reporter.cs | 131 +++++++++-------- .../TechDebtAttributes/TechDebtAttribute.cs | 25 ++-- .../TechDebtAttributes.csproj | 61 ++------ .../TechDebtPainExceededException.cs | 9 +- src/TechDebtAttributes/global.json | 7 + 22 files changed, 275 insertions(+), 657 deletions(-) delete mode 100644 src/TechDebtAttributes/ExampleUsage.Tests/packages.config delete mode 100644 src/TechDebtAttributes/TechDebtAttributes.Tests/packages.config create mode 100644 src/TechDebtAttributes/global.json diff --git a/README.md b/README.md index 9ca504e..fa35393 100644 --- a/README.md +++ b/README.md @@ -55,18 +55,16 @@ Benefit to fix: 0 There's a lot of work to fix this whole class for not much gai End of Tech Debt Report. ``` -## Step 3: Fail tests if too much tech debt exists (optional) +## Step 3: Throws if too much tech debt exists (optional) ```csharp -// This test will fail because there is more than total of 10 pain in all tech debt [Fact] -public void ReportOnTechDebtAndFailTestIfTotalPainExceeded() +public void ShouldThrowExceptionWhenPainLimitExceeded() { - var assemblyContainingTechDebt = Assembly.GetAssembly(typeof(SomeThing)); + var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); - const int maximumPainInCodebaseThatWereWillingToLiveWith = 10; - - TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith); + Assert.Throws(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, 1)); +} } ``` diff --git a/src/TechDebtAttributes/AnotherExampleUsageAssembly/AnotherExampleUsageAssembly.csproj b/src/TechDebtAttributes/AnotherExampleUsageAssembly/AnotherExampleUsageAssembly.csproj index 4a3d255..c726417 100644 --- a/src/TechDebtAttributes/AnotherExampleUsageAssembly/AnotherExampleUsageAssembly.csproj +++ b/src/TechDebtAttributes/AnotherExampleUsageAssembly/AnotherExampleUsageAssembly.csproj @@ -1,59 +1,15 @@ - - - + - Debug - AnyCPU - {4EBE26A5-588E-428D-BC41-5642C0018A80} + net6.0 Library - Properties - AnotherExampleUsageAssembly - AnotherExampleUsageAssembly - v4.5.1 - 512 + false + AnotherExampleUsageAssembly + AnotherExampleUsageAssembly + Copyright © 2014 + 1.0.0.0 + 1.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - {7987BE47-0F7A-4FB0-A395-D0536EF6DF12} - TechDebtAttributes - + - - \ No newline at end of file diff --git a/src/TechDebtAttributes/AnotherExampleUsageAssembly/Mango.cs b/src/TechDebtAttributes/AnotherExampleUsageAssembly/Mango.cs index e067177..5855422 100644 --- a/src/TechDebtAttributes/AnotherExampleUsageAssembly/Mango.cs +++ b/src/TechDebtAttributes/AnotherExampleUsageAssembly/Mango.cs @@ -1,9 +1,8 @@ using TechDebtAttributes; -namespace AnotherExampleUsageAssembly +namespace AnotherExampleUsageAssembly; + +[TechDebt(9999,2)] +public class Mango { - [TechDebt(9999,2)] - public class Mango - { - } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage.Tests/ExampleUsage.Tests.csproj b/src/TechDebtAttributes/ExampleUsage.Tests/ExampleUsage.Tests.csproj index b1ada2e..aade315 100644 --- a/src/TechDebtAttributes/ExampleUsage.Tests/ExampleUsage.Tests.csproj +++ b/src/TechDebtAttributes/ExampleUsage.Tests/ExampleUsage.Tests.csproj @@ -1,105 +1,30 @@ - - - - - + - Debug - AnyCPU - {62573446-B37F-4E98-BC15-C70FAB4AB72D} + net6.0 Library - Properties - ExampleUsage.Tests - ExampleUsage.Tests - v4.5.2 - 512 - - - + false + ExampleUsage.Tests + ExampleUsage.Tests + Copyright © 2014 + 1.0.0.0 + 1.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - - - ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll - - - ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll - - - ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll - - - - - - - - - {F3B4F26F-203B-4045-A435-BFD7B6644C37} - ExampleUsage - - - {7987BE47-0F7A-4FB0-A395-D0536EF6DF12} - TechDebtAttributes - - - - - - + + - + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage.Tests/UsingTechDebtAttributesInTests.cs b/src/TechDebtAttributes/ExampleUsage.Tests/UsingTechDebtAttributesInTests.cs index ed71b92..27407e3 100644 --- a/src/TechDebtAttributes/ExampleUsage.Tests/UsingTechDebtAttributesInTests.cs +++ b/src/TechDebtAttributes/ExampleUsage.Tests/UsingTechDebtAttributesInTests.cs @@ -1,32 +1,38 @@ -using System; -using System.Reflection; +using System.Reflection; using TechDebtAttributes; using Xunit; +using Xunit.Abstractions; -namespace ExampleUsage.Tests +namespace ExampleUsage.Tests; + +public class UsingTechDebtAttributesInTests { - public class UsingTechDebtAttributesInTests + private readonly ITestOutputHelper _testOutputHelper; + + public UsingTechDebtAttributesInTests(ITestOutputHelper testOutputHelper) { - [Fact] - public void ReportOnTechDebtButNeverFailATest() - { - var assemblyContainingTechDebt = Assembly.GetAssembly(typeof (SomeThing)); + _testOutputHelper = testOutputHelper; + } - var report = TechDebtReporter.GenerateReport(assemblyContainingTechDebt); + [Fact] + public void ReportOnTechDebtButNeverFailATest() + { + var assemblyContainingTechDebt = Assembly.GetAssembly(typeof (SomeThing)); - Console.WriteLine(report); - } + var report = TechDebtReporter.GenerateReport(assemblyContainingTechDebt); + + _testOutputHelper.WriteLine(report); + } - // This test will fail because there is more than total of 10 pain in tech debt - [Fact] - public void ReportOnTechDebtAndFailTestIfTotalPainExceeded() - { - var assemblyContainingTechDebt = Assembly.GetAssembly(typeof(SomeThing)); + [Fact] + public void ReportOnTechDebtAndThrowIfTotalPainExceeded() + { + var assemblyContainingTechDebt = Assembly.GetAssembly(typeof(SomeThing)); - const int maximumPainInCodebaseThatWereWillingToLiveWith = 10; + const int maximumPainInCodebaseThatWereWillingToLiveWith = 10; - TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith); - } + Assert.Throws(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith)); + // TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith); } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage.Tests/packages.config b/src/TechDebtAttributes/ExampleUsage.Tests/packages.config deleted file mode 100644 index fb1def0..0000000 --- a/src/TechDebtAttributes/ExampleUsage.Tests/packages.config +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/Cheese.cs b/src/TechDebtAttributes/ExampleUsage/Cheese.cs index 7258001..07d857b 100644 --- a/src/TechDebtAttributes/ExampleUsage/Cheese.cs +++ b/src/TechDebtAttributes/ExampleUsage/Cheese.cs @@ -1,14 +1,13 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +[TechDebt(3,6, Description = "What kind of cheese is this?")] +internal class Cheese { - [TechDebt(3,6, Description = "What kind of cheese is this?")] - internal class Cheese + [TechDebt(3, 8, Description = "What exactly is inner cheese")] + internal class InnerCheese { - [TechDebt(3, 8, Description = "What exactly is inner cheese")] - internal class InnerCheese - { - - } + } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/ExampleUsage.csproj b/src/TechDebtAttributes/ExampleUsage/ExampleUsage.csproj index fe8283b..ab8f7ab 100644 --- a/src/TechDebtAttributes/ExampleUsage/ExampleUsage.csproj +++ b/src/TechDebtAttributes/ExampleUsage/ExampleUsage.csproj @@ -1,64 +1,15 @@ - - - + - Debug - AnyCPU - {F3B4F26F-203B-4045-A435-BFD7B6644C37} + net6.0 Library - Properties - ExampleUsage - ExampleUsage - v4.5.1 - 512 + false + ExampleUsage + ExampleUsage + Copyright © 2014 + 1.0.0.0 + 1.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - {7987BE47-0F7A-4FB0-A395-D0536EF6DF12} - TechDebtAttributes - + - - \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/ISomeDumbInterface.cs b/src/TechDebtAttributes/ExampleUsage/ISomeDumbInterface.cs index ca7142e..86f20ee 100644 --- a/src/TechDebtAttributes/ExampleUsage/ISomeDumbInterface.cs +++ b/src/TechDebtAttributes/ExampleUsage/ISomeDumbInterface.cs @@ -1,9 +1,8 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +[TechDebt(10, 44, Description = "This is dumb, we should remove it")] +public interface ISomeDumbInterface { - [TechDebt(10, 44, Description = "This is dumb, we should remove it")] - public interface ISomeDumbInterface - { - } } \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/ISomeExampleInterface.cs b/src/TechDebtAttributes/ExampleUsage/ISomeExampleInterface.cs index f354f1a..c0a779b 100644 --- a/src/TechDebtAttributes/ExampleUsage/ISomeExampleInterface.cs +++ b/src/TechDebtAttributes/ExampleUsage/ISomeExampleInterface.cs @@ -1,12 +1,11 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +public interface ISomeExampleInterface { - public interface ISomeExampleInterface - { - void X(); - [TechDebt(10, 100, Description = "This should be moved to it's own interface")] - void Y(); - void Z(); - } + void X(); + [TechDebt(10, 100, Description = "This should be moved to it's own interface")] + void Y(); + void Z(); } \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/SillyEnum.cs b/src/TechDebtAttributes/ExampleUsage/SillyEnum.cs index 6d9cedf..1aa456d 100644 --- a/src/TechDebtAttributes/ExampleUsage/SillyEnum.cs +++ b/src/TechDebtAttributes/ExampleUsage/SillyEnum.cs @@ -1,13 +1,12 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +[TechDebt(2,6, Description = "This really is silly")] +public enum SillyEnum { - [TechDebt(2,6, Description = "This really is silly")] - public enum SillyEnum - { - Alpha, - Beta, - [TechDebt(47,23)] - Tomato - } + Alpha, + Beta, + [TechDebt(47,23)] + Tomato, } \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/SomeThing.cs b/src/TechDebtAttributes/ExampleUsage/SomeThing.cs index 920041d..08834e7 100644 --- a/src/TechDebtAttributes/ExampleUsage/SomeThing.cs +++ b/src/TechDebtAttributes/ExampleUsage/SomeThing.cs @@ -1,13 +1,12 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +[TechDebt(1, 200, Description = "There's a lot of work to fix this whole class for not much gain")] +public class SomeThing { - [TechDebt(1, 200, Description = "There's a lot of work to fix this whole class for not much gain")] - public class SomeThing + [TechDebt(5,1, Description = "Quick fix to stop stupid stuff happening sometimes")] + public void SomeMethod() { - [TechDebt(5,1, Description = "Quick fix to stop stupid stuff happening sometimes")] - public void SomeMethod() - { - } } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/ExampleUsage/SomeThingWithDumbConstructor.cs b/src/TechDebtAttributes/ExampleUsage/SomeThingWithDumbConstructor.cs index 89629b4..9ec7d7d 100644 --- a/src/TechDebtAttributes/ExampleUsage/SomeThingWithDumbConstructor.cs +++ b/src/TechDebtAttributes/ExampleUsage/SomeThingWithDumbConstructor.cs @@ -1,13 +1,12 @@ using TechDebtAttributes; -namespace ExampleUsage +namespace ExampleUsage; + +public class SomeThingWithDumbConstructor { - public class SomeThingWithDumbConstructor + [TechDebt(5000, 3)] + public SomeThingWithDumbConstructor() { - [TechDebt(5000, 3)] - public SomeThingWithDumbConstructor() - { - - } + } } \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtAttributes.Tests.csproj b/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtAttributes.Tests.csproj index f9421f3..516058b 100644 --- a/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtAttributes.Tests.csproj +++ b/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtAttributes.Tests.csproj @@ -1,94 +1,18 @@ - - - - - + - Debug - AnyCPU - {75918F04-871A-44B6-A291-CA88A43DA2DF} + net6.0 Library - Properties - TechDebtAttributes.Tests - TechDebtAttributes.Tests - v4.5.2 - 512 - - - + false + TechDebtAttributes.Tests + TechDebtAttributes.Tests + Copyright © 2014 + 1.0.0.0 + 1.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\AlphaFS.2.1.3\lib\net452\AlphaFS.dll - - - ..\packages\ApprovalTests.3.0.14\lib\net45\ApprovalTests.dll - - - ..\packages\ApprovalUtilities.3.0.14\lib\net45\ApprovalUtilities.dll - - - - - - - - - ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - - - ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll - - - ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll - - - ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll - - - - - - - - {4EBE26A5-588E-428D-BC41-5642C0018A80} - AnotherExampleUsageAssembly - - - {F3B4F26F-203B-4045-A435-BFD7B6644C37} - ExampleUsage - - - {7987be47-0f7a-4fb0-a395-d0536ef6df12} - TechDebtAttributes - + + + @@ -97,26 +21,22 @@ - + - + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtReporterTests.cs b/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtReporterTests.cs index 16f6616..8b229ef 100644 --- a/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtReporterTests.cs +++ b/src/TechDebtAttributes/TechDebtAttributes.Tests/TechDebtReporterTests.cs @@ -5,46 +5,45 @@ using ExampleUsage; using Xunit; -namespace TechDebtAttributes.Tests +namespace TechDebtAttributes.Tests; + +public class TechDebtReporterTests { - public class TechDebtReporterTests + [Fact] + [UseReporter(typeof(DiffReporter))] + public void ShouldRenderReport() { - [Fact] - [UseReporter(typeof(DiffReporter))] - public void ShouldRenderReport() - { - var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); + var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); - Approvals.Verify(TechDebtReporter.GenerateReport(assemblyToReportOn)); - } + Approvals.Verify(TechDebtReporter.GenerateReport(assemblyToReportOn)); + } - [Fact] - [UseReporter(typeof(DiffReporter))] - public void ShouldRenderReportWithMultipleAssemblies() + [Fact] + [UseReporter(typeof(DiffReporter))] + public void ShouldRenderReportWithMultipleAssemblies() + { + var assemblyToReportOn = new[] { - var assemblyToReportOn = new[] - { - Assembly.GetAssembly(typeof (SomeThing)), - Assembly.GetAssembly(typeof (Mango)) - }; + Assembly.GetAssembly(typeof (SomeThing)), + Assembly.GetAssembly(typeof (Mango)), + }; - Approvals.Verify(TechDebtReporter.GenerateReport(assemblyToReportOn)); - } + Approvals.Verify(TechDebtReporter.GenerateReport(assemblyToReportOn)); + } - [Fact] - public void ShouldThrowExceptionWhenPainLimitExceeded() - { - var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); + [Fact] + public void ShouldThrowExceptionWhenPainLimitExceeded() + { + var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); - Assert.Throws(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, 1)); - } + Assert.Throws(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, 1)); + } - [Fact] - public void ShouldNotThrowExceptionWhenPainIsAcceptableToTeam() - { - var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); + [Fact] + public void ShouldNotThrowExceptionWhenPainIsAcceptableToTeam() + { + var assemblyToReportOn = Assembly.GetAssembly(typeof(SomeThing)); - TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, int.MaxValue); - } + TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, int.MaxValue); } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes.Tests/packages.config b/src/TechDebtAttributes/TechDebtAttributes.Tests/packages.config deleted file mode 100644 index be846a2..0000000 --- a/src/TechDebtAttributes/TechDebtAttributes.Tests/packages.config +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes.sln b/src/TechDebtAttributes/TechDebtAttributes.sln index 7a2af0d..293a05a 100644 --- a/src/TechDebtAttributes/TechDebtAttributes.sln +++ b/src/TechDebtAttributes/TechDebtAttributes.sln @@ -1,19 +1,19 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechDebtAttributes", "TechDebtAttributes\TechDebtAttributes.csproj", "{7987BE47-0F7A-4FB0-A395-D0536EF6DF12}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TechDebtAttributes", "TechDebtAttributes\TechDebtAttributes.csproj", "{7987BE47-0F7A-4FB0-A395-D0536EF6DF12}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleUsage", "ExampleUsage\ExampleUsage.csproj", "{F3B4F26F-203B-4045-A435-BFD7B6644C37}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleUsage", "ExampleUsage\ExampleUsage.csproj", "{F3B4F26F-203B-4045-A435-BFD7B6644C37}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleUsage.Tests", "ExampleUsage.Tests\ExampleUsage.Tests.csproj", "{62573446-B37F-4E98-BC15-C70FAB4AB72D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleUsage.Tests", "ExampleUsage.Tests\ExampleUsage.Tests.csproj", "{62573446-B37F-4E98-BC15-C70FAB4AB72D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechDebtAttributes.Tests", "TechDebtAttributes.Tests\TechDebtAttributes.Tests.csproj", "{75918F04-871A-44B6-A291-CA88A43DA2DF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TechDebtAttributes.Tests", "TechDebtAttributes.Tests\TechDebtAttributes.Tests.csproj", "{75918F04-871A-44B6-A291-CA88A43DA2DF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ExampleUse", "ExampleUse", "{BFC94489-6B3F-4ADB-8F8A-35F2A4C86887}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnotherExampleUsageAssembly", "AnotherExampleUsageAssembly\AnotherExampleUsageAssembly.csproj", "{4EBE26A5-588E-428D-BC41-5642C0018A80}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnotherExampleUsageAssembly", "AnotherExampleUsageAssembly\AnotherExampleUsageAssembly.csproj", "{4EBE26A5-588E-428D-BC41-5642C0018A80}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/TechDebtAttributes/TechDebtAttributes/Reporter.cs b/src/TechDebtAttributes/TechDebtAttributes/Reporter.cs index 951d528..f77d793 100644 --- a/src/TechDebtAttributes/TechDebtAttributes/Reporter.cs +++ b/src/TechDebtAttributes/TechDebtAttributes/Reporter.cs @@ -4,97 +4,94 @@ using System.Reflection; using System.Text; -namespace TechDebtAttributes +namespace TechDebtAttributes; + +public static class TechDebtReporter { - public static class TechDebtReporter + public static string GenerateReport(params Assembly[] assemblies) { - public static string GenerateReport(params Assembly[] assemblies) - { - var typesWithTechDebt = FindTypesWithTechDebt(assemblies); + var typesWithTechDebt = FindTypesWithTechDebt(assemblies); - var reportLines = GenerateReportLines(typesWithTechDebt); + var reportLines = GenerateReportLines(typesWithTechDebt); - return RenderReportLinesToTextReport(reportLines); - } + return RenderReportLinesToTextReport(reportLines); + } - public static void AssertMaxPainNotExceeded(Assembly assemblyToReportOn, int maxAllowableMain) - { - var typesWithDebt = FindAllTheTypesThatHaveTechDebt(assemblyToReportOn); + public static void AssertMaxPainNotExceeded(Assembly assemblyToReportOn, int maxAllowableMain) + { + var typesWithDebt = FindAllTheTypesThatHaveTechDebt(assemblyToReportOn); - var totalPain = (from t in typesWithDebt - let techDebtAttribute = (TechDebtAttribute)t.GetCustomAttributes(typeof(TechDebtAttribute), inherit: false)[0] - select techDebtAttribute).Sum(x => x.Pain); + var totalPain = (from t in typesWithDebt + let techDebtAttribute = (TechDebtAttribute)t.GetCustomAttributes(typeof(TechDebtAttribute), inherit: false)[0] + select techDebtAttribute).Sum(x => x.Pain); - if (totalPain > maxAllowableMain) - { - throw new TechDebtPainExceededException(); - } - } - - private static IEnumerable FindTypesWithTechDebt(IEnumerable assemblies) + if (totalPain > maxAllowableMain) { - return assemblies.SelectMany(FindAllTheTypesThatHaveTechDebt); + throw new TechDebtPainExceededException(); } + } - private static IEnumerable FindAllTheTypesThatHaveTechDebt(Assembly assembly) - { - return assembly.GetTypes() - .SelectMany(type => type.GetMembers()) - .Union(assembly.GetTypes()) - .Where(type => Attribute.IsDefined(type, typeof(TechDebtAttribute))); - } + private static IEnumerable FindTypesWithTechDebt(IEnumerable assemblies) + { + return assemblies.SelectMany(FindAllTheTypesThatHaveTechDebt); + } + + private static IEnumerable FindAllTheTypesThatHaveTechDebt(Assembly assembly) + { + return assembly.GetTypes() + .SelectMany(type => type.GetMembers()) + .Union(assembly.GetTypes()) + .Where(type => Attribute.IsDefined(type, typeof(TechDebtAttribute))); + } + + private static IEnumerable GenerateReportLines(IEnumerable typesWithTechDebt) + { + var reportItems = new List(); - private static IEnumerable GenerateReportLines(IEnumerable typesWithTechDebt) + foreach (var type in typesWithTechDebt) { - var reportItems = new List(); + var techDebtAttribute = + (TechDebtAttribute) type.GetCustomAttributes(typeof (TechDebtAttribute), inherit: false)[0]; - foreach (var type in typesWithTechDebt) + reportItems.Add(new ReportLine { - var techDebtAttribute = - (TechDebtAttribute) type.GetCustomAttributes(typeof (TechDebtAttribute), inherit: false)[0]; - - reportItems.Add(new ReportLine - { - Attribute = techDebtAttribute, - TypeOrMemberName = type.ToString() - }); - } - return reportItems; + Attribute = techDebtAttribute, + TypeOrMemberName = type.ToString(), + }); } + return reportItems; + } - private static string RenderReportLinesToTextReport(IEnumerable reportLines) - { - var sb = new StringBuilder(); + private static string RenderReportLinesToTextReport(IEnumerable reportLines) + { + var sb = new StringBuilder(); - sb.AppendLine("***Start of Tech Debt Report - finding all [TechDebt] attribute usages"); + sb.AppendLine("***Start of Tech Debt Report - finding all [TechDebt] attribute usages"); - sb.AppendLine(); + sb.AppendLine(); - foreach (var item in reportLines.OrderByDescending(x => x.Attribute.RelativeBenefitToFix)) - { - sb.AppendLine(item.ToString()); - } + foreach (var item in reportLines.OrderByDescending(x => x.Attribute.RelativeBenefitToFix)) + { + sb.AppendLine(item.ToString()); + } - sb.AppendLine(); + sb.AppendLine(); - sb.AppendLine("***End of Tech Debt Report."); + sb.AppendLine("***End of Tech Debt Report."); - return sb.ToString(); - } + return sb.ToString(); + } - + private class ReportLine + { + public string TypeOrMemberName { get; set; } + public TechDebtAttribute Attribute {get; set; } - private class ReportLine + public override string ToString() { - public string TypeOrMemberName { get; set; } - public TechDebtAttribute Attribute {get; set; } - - public override string ToString() - { - return string.Format("Benefit to fix: {0:0.#} {1} {2} Pain:{3} Effort to fix:{4}", - Attribute.RelativeBenefitToFix, Attribute.Description, TypeOrMemberName, Attribute.Pain, - Attribute.EffortToFix); - } + return string.Format("Benefit to fix: {0:0.#} {1} {2} Pain:{3} Effort to fix:{4}", + Attribute.RelativeBenefitToFix, Attribute.Description, TypeOrMemberName, Attribute.Pain, + Attribute.EffortToFix); } } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttribute.cs b/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttribute.cs index 8409731..d375d4c 100644 --- a/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttribute.cs +++ b/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttribute.cs @@ -1,20 +1,19 @@ using System; -namespace TechDebtAttributes +namespace TechDebtAttributes; + +[AttributeUsage(AttributeTargets.All)] +public class TechDebtAttribute : Attribute { - [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] - public class TechDebtAttribute : Attribute + public TechDebtAttribute(int pain, int effortToFix) { - public TechDebtAttribute(int pain, int effortToFix) - { - Pain = pain; - EffortToFix = effortToFix; - } + Pain = pain; + EffortToFix = effortToFix; + } - public double RelativeBenefitToFix => (double)Pain / EffortToFix; + public double RelativeBenefitToFix => (double)Pain / EffortToFix; - public int Pain { get; } - public int EffortToFix { get; } - public string Description { get; set; } - } + public int Pain { get; } + public int EffortToFix { get; } + public string Description { get; set; } } \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttributes.csproj b/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttributes.csproj index 10d4fba..c6c9f12 100644 --- a/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttributes.csproj +++ b/src/TechDebtAttributes/TechDebtAttributes/TechDebtAttributes.csproj @@ -1,60 +1,17 @@ - - - + - Debug - AnyCPU - {7987BE47-0F7A-4FB0-A395-D0536EF6DF12} + net6.0 Library - Properties - TechDebtAttributes - TechDebtAttributes - v3.5 - 512 - + false + TechDebtAttributes + TechDebtAttributes + Copyright 2014-2018 Jason Roberts + 2.0.0.0 + 2.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - + Designer - - \ No newline at end of file diff --git a/src/TechDebtAttributes/TechDebtAttributes/TechDebtPainExceededException.cs b/src/TechDebtAttributes/TechDebtAttributes/TechDebtPainExceededException.cs index 0ec5121..6aba13b 100644 --- a/src/TechDebtAttributes/TechDebtAttributes/TechDebtPainExceededException.cs +++ b/src/TechDebtAttributes/TechDebtAttributes/TechDebtPainExceededException.cs @@ -1,9 +1,8 @@ using System; -namespace TechDebtAttributes +namespace TechDebtAttributes; + +public class TechDebtPainExceededException : Exception { - public class TechDebtPainExceededException : Exception - { - } -} +} \ No newline at end of file diff --git a/src/TechDebtAttributes/global.json b/src/TechDebtAttributes/global.json new file mode 100644 index 0000000..87aef9f --- /dev/null +++ b/src/TechDebtAttributes/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.0", + "rollForward": "latestMajor", + "allowPrerelease": false + } +} \ No newline at end of file