Skip to content
Open
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
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TechDebtPainExceededException>(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyToReportOn, 1));
}
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4EBE26A5-588E-428D-BC41-5642C0018A80}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnotherExampleUsageAssembly</RootNamespace>
<AssemblyName>AnotherExampleUsageAssembly</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyTitle>AnotherExampleUsageAssembly</AssemblyTitle>
<Product>AnotherExampleUsageAssembly</Product>
<Copyright>Copyright © 2014</Copyright>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mango.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TechDebtAttributes\TechDebtAttributes.csproj">
<Project>{7987BE47-0F7A-4FB0-A395-D0536EF6DF12}</Project>
<Name>TechDebtAttributes</Name>
</ProjectReference>
<ProjectReference Include="..\TechDebtAttributes\TechDebtAttributes.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
11 changes: 5 additions & 6 deletions src/TechDebtAttributes/AnotherExampleUsageAssembly/Mango.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using TechDebtAttributes;

namespace AnotherExampleUsageAssembly
namespace AnotherExampleUsageAssembly;

[TechDebt(9999,2)]
public class Mango
{
[TechDebt(9999,2)]
public class Mango
{
}
}
}
119 changes: 22 additions & 97 deletions src/TechDebtAttributes/ExampleUsage.Tests/ExampleUsage.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,105 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{62573446-B37F-4E98-BC15-C70FAB4AB72D}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExampleUsage.Tests</RootNamespace>
<AssemblyName>ExampleUsage.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyTitle>ExampleUsage.Tests</AssemblyTitle>
<Product>ExampleUsage.Tests</Product>
<Copyright>Copyright © 2014</Copyright>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="UsingTechDebtAttributesInTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ExampleUsage\ExampleUsage.csproj">
<Project>{F3B4F26F-203B-4045-A435-BFD7B6644C37}</Project>
<Name>ExampleUsage</Name>
</ProjectReference>
<ProjectReference Include="..\TechDebtAttributes\TechDebtAttributes.csproj">
<Project>{7987BE47-0F7A-4FB0-A395-D0536EF6DF12}</Project>
<Name>TechDebtAttributes</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<ProjectReference Include="..\ExampleUsage\ExampleUsage.csproj" />
<ProjectReference Include="..\TechDebtAttributes\TechDebtAttributes.csproj" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.9.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.analyzers" Version="1.2.0" />
<PackageReference Include="xunit.assert" Version="2.5.0" />
<PackageReference Include="xunit.core" Version="2.5.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.5.0" />
<PackageReference Include="xunit.extensibility.execution" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -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<TechDebtPainExceededException>(() => TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith));
// TechDebtReporter.AssertMaxPainNotExceeded(assemblyContainingTechDebt, maximumPainInCodebaseThatWereWillingToLiveWith);
}
}
}
43 changes: 0 additions & 43 deletions src/TechDebtAttributes/ExampleUsage.Tests/packages.config

This file was deleted.

17 changes: 8 additions & 9 deletions src/TechDebtAttributes/ExampleUsage/Cheese.cs
Original file line number Diff line number Diff line change
@@ -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
{

}

}
}
}
Loading