diff --git a/README.md b/README.md index 9c9424f3..812235a7 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,12 @@ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Qowaiv_Qowaiv&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Qowaiv_Qowaiv) [![Coverage Status](https://coveralls.io/repos/github/Qowaiv/Qowaiv/badge.svg?branch=master)](https://coveralls.io/github/Qowaiv/Qowaiv?branch=master) -| version | downloads | package | -|--------------------------------------------------------------------|-----------------------------------------------------------|-----------------------------------------------------------------------------| -|![v](https://img.shields.io/nuget/v/Qowaiv?color=18C) |![v](https://img.shields.io/nuget/dt/Qowaiv) |[Qowaiv](https://www.nuget.org/packages/Qowaiv/) | -|![v](https://img.shields.io/nuget/v/Qowaiv.Data.SqlClient?color=18C)|![v](https://img.shields.io/nuget/dt/Qowaiv.Data.SqlClient)|[Qowaiv.Data.SqlCient](https://www.nuget.org/packages/Qowaiv.Data.SqlClient/)| -|![v](https://img.shields.io/nuget/v/Qowaiv.TestTools?color=118) |![v](https://img.shields.io/nuget/dt/Qowaiv.TestTools) |[Qowaiv.TestTools](https://www.nuget.org/packages/Qowaiv.TestTools/) | +| version | downloads | package | +|----------------------------------------------------------------------------------|------------------------------------------------------------------|--------------------------------------------------------------------------------| +|![v](https://img.shields.io/nuget/v/Qowaiv?color=18C) |![v](https://img.shields.io/nuget/dt/Qowaiv) |[Qowaiv](https://www.nuget.org/packages/Qowaiv/) | +|![v](https://img.shields.io/nuget/v/Qowaiv.Data.SqlClient?color=18C) |![v](https://img.shields.io/nuget/dt/Qowaiv.Data.SqlClient) |[Qowaiv.Data.SqlCient](https://www.nuget.org/packages/Qowaiv.Data.SqlClient/) | +|![v](https://img.shields.io/nuget/v/Qowaiv.Qowaiv.Diagnostics.Contracts?color=118)|![v](https://img.shields.io/nuget/dt/Qowaiv.Diagnostics.Contracts)|[Qowaiv.TestTools](https://www.nuget.org/packages/Qowaiv.Diagnostics.Contracts/)| +|![v](https://img.shields.io/nuget/v/Qowaiv.TestTools?color=118) |![v](https://img.shields.io/nuget/dt/Qowaiv.TestTools) |[Qowaiv.TestTools](https://www.nuget.org/packages/Qowaiv.TestTools/) | # Qowaiv @@ -1134,3 +1135,7 @@ Since .NET 8.0, Microsoft provides a `TimeProvider`. To benefit from both the `Qowaiv.Clock` mechanism, and this time provider, the `Clock.TimeProvider`, a singleton which provides access to `Clock.UtcNow()` and `Clock.TimeZone` is added. + +# Qowaiv Diagnostics Contracts +This packages contains attributes to define (expected) behavior on code +[(..)](src/Qowaiv.Diagnostics.Contracts/README.md) diff --git a/props/common.props b/props/common.props index a60e54d9..0ec96a6f 100644 --- a/props/common.props +++ b/props/common.props @@ -56,8 +56,8 @@ - - + + diff --git a/specs/Qowaiv.Specs/Diagnostics/Contracts/Impure_attribute_specs.cs b/specs/Qowaiv.Specs/Diagnostics/Contracts/Impure_attribute_specs.cs new file mode 100644 index 00000000..70f44852 --- /dev/null +++ b/specs/Qowaiv.Specs/Diagnostics/Contracts/Impure_attribute_specs.cs @@ -0,0 +1,28 @@ +namespace Diagnostics.Contracts.Impure_attribute_specs; + +internal class Can_decorate_methods_with +{ + [Test] + public void Collection_mutation_attribute() + => typeof(SomeClass).GetMethod(nameof(SomeClass.CollectionMutation)).Should().BeDecoratedWith(); + + [Test] + public void Impure_attribute() + => typeof(SomeClass).GetMethod(nameof(SomeClass.Impure)).Should().BeDecoratedWith(); + + [Test] + public void Fluent_syntax_attribute() + => typeof(SomeClass).GetMethod(nameof(SomeClass.FluentSyntax)).Should().BeDecoratedWith(); +} + +internal class SomeClass +{ + [CollectionMutation] + public bool CollectionMutation(HashSet set) => set.Add(this); + + [Impure] + public static int Impure() => 42; + + [FluentSyntax] + public SomeClass FluentSyntax() => this; +} diff --git a/specs/Qowaiv.Specs/Diagnostics/Contracts/Inheritable_attribute_specs.cs b/specs/Qowaiv.Specs/Diagnostics/Contracts/Inheritable_attribute_specs.cs new file mode 100644 index 00000000..26166a2f --- /dev/null +++ b/specs/Qowaiv.Specs/Diagnostics/Contracts/Inheritable_attribute_specs.cs @@ -0,0 +1,13 @@ +namespace Diagnostics.Contracts.Inheritable_attribute_specs; + +internal class Can_decorate +{ + [Test] + public void Classes() + => typeof(SomeClass).Should().BeDecoratedWith(); +} + +[Inheritable("For test purposes")] +internal class SomeClass +{ +} diff --git a/specs/Qowaiv.Specs/Diagnostics/Contracts/Mutable_attribute_specs.cs b/specs/Qowaiv.Specs/Diagnostics/Contracts/Mutable_attribute_specs.cs new file mode 100644 index 00000000..e9fe3006 --- /dev/null +++ b/specs/Qowaiv.Specs/Diagnostics/Contracts/Mutable_attribute_specs.cs @@ -0,0 +1,13 @@ +namespace Diagnostics.Contracts.Mutable_attribute_specs; + +internal class Can_decorate +{ + [Test] + public void Classes() + => typeof(SomeClass).Should().BeDecoratedWith(); +} + +[Mutable("For test purposes")] +internal class SomeClass +{ +} diff --git a/specs/Qowaiv.Specs/Diagnostics/Contracts/Will_be_sealed_attribute_specs.cs b/specs/Qowaiv.Specs/Diagnostics/Contracts/Will_be_sealed_attribute_specs.cs new file mode 100644 index 00000000..0a55f855 --- /dev/null +++ b/specs/Qowaiv.Specs/Diagnostics/Contracts/Will_be_sealed_attribute_specs.cs @@ -0,0 +1,26 @@ +namespace Diagnostics.Contracts.Will_be_sealed_attribute_specs; + +internal class Can_decorate +{ + [Test] + public void Classes() + => typeof(SomeClass).Should().BeDecoratedWith(); + + [Test] + public void Properties() + => typeof(SomeClass).GetProperty(nameof(SomeClass.Property)).Should().BeDecoratedWith(); + + [Test] + public void Methods() + => typeof(SomeClass).GetMethod(nameof(SomeClass.Method)).Should().BeDecoratedWith(); +} + +[WillBeSealed("For test purposes")] +internal class SomeClass +{ + [WillBeSealed("No reason to change this property.")] + public virtual int Property { get; } = 42; + + [WillBeSealed("No reason to change this method.")] + public virtual int Method() => 42; +} diff --git a/specs/Qowaiv.Specs/Obsolete_code.cs b/specs/Qowaiv.Specs/Obsolete_code.cs index 02723b5a..f7e04535 100644 --- a/specs/Qowaiv.Specs/Obsolete_code.cs +++ b/specs/Qowaiv.Specs/Obsolete_code.cs @@ -1,4 +1,6 @@ -namespace Obsolete_code; +using Qowaiv.Diagnostics.Contracts; + +namespace Obsolete_code; [Obsolete("Will be dropped when the next major version is released.")] public class Will_be_dropped diff --git a/specs/Qowaiv.Specs/Qowaiv.Specs.csproj b/specs/Qowaiv.Specs/Qowaiv.Specs.csproj index 88bf4960..9667dfae 100644 --- a/specs/Qowaiv.Specs/Qowaiv.Specs.csproj +++ b/specs/Qowaiv.Specs/Qowaiv.Specs.csproj @@ -5,6 +5,7 @@ enable netcoreapp3.1;net6.0;net8.0 + CONTRACTS_FULL diff --git a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs b/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs deleted file mode 100644 index 42996b63..00000000 --- a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. Methods decorated with -/// this attribute return the same instance that was provided as argument. -/// -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public sealed class FluentSyntaxAttribute : ImpureAttribute { } diff --git a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/ImpureAttribute.cs b/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/ImpureAttribute.cs deleted file mode 100644 index 5f52c950..00000000 --- a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/ImpureAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class ImpureAttribute : Attribute { } diff --git a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/InheritableAttribute.cs b/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/InheritableAttribute.cs deleted file mode 100644 index cb7198b4..00000000 --- a/src/Qowaiv.Data.SqlClient/Internals/Diagnostics/Contracts/InheritableAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts; - -/// Indicates the a class is designed to be inheritable. -[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class InheritableAttribute : Attribute -{ - /// Initializes a new instance of the class. - public InheritableAttribute(string? message = null) => _ = message; -} diff --git a/src/Qowaiv.Data.SqlClient/Properties/GlobalUsings.cs b/src/Qowaiv.Data.SqlClient/Properties/GlobalUsings.cs index d405d0db..a5113f28 100644 --- a/src/Qowaiv.Data.SqlClient/Properties/GlobalUsings.cs +++ b/src/Qowaiv.Data.SqlClient/Properties/GlobalUsings.cs @@ -1,4 +1,4 @@ -global using Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts; +global using Qowaiv.Diagnostics.Contracts; global using Qowaiv.Formatting; global using Qowaiv.Hashing; global using Qowaiv.OpenApi; diff --git a/src/Qowaiv.Data.SqlClient/Qowaiv.Data.SqlClient.csproj b/src/Qowaiv.Data.SqlClient/Qowaiv.Data.SqlClient.csproj index 4658eb0c..7f18a23b 100644 --- a/src/Qowaiv.Data.SqlClient/Qowaiv.Data.SqlClient.csproj +++ b/src/Qowaiv.Data.SqlClient/Qowaiv.Data.SqlClient.csproj @@ -5,7 +5,7 @@ netstandard2.0;net6.0;net8.0 true - 6.4.0 + 7.0.0 Qowaiv.Data.SqlClient v7.0.0 @@ -39,6 +39,7 @@ v6.0.0 + diff --git a/src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs b/src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs index aa33fed5..54ea1dc2 100644 --- a/src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs +++ b/src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs @@ -3,4 +3,8 @@ /// Indicates the class is designed to be mutable. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] [Conditional("CONTRACTS_FULL")] -public sealed class MutableAttribute : Attribute { } +public sealed class MutableAttribute : Attribute +{ + /// Initializes a new instance of the class. + public MutableAttribute(string? message = null) => _ = message; +} diff --git a/src/Qowaiv.Diagnostics.Contracts/README.md b/src/Qowaiv.Diagnostics.Contracts/README.md index 1177469f..1f97a2fd 100644 --- a/src/Qowaiv.Diagnostics.Contracts/README.md +++ b/src/Qowaiv.Diagnostics.Contracts/README.md @@ -1,5 +1,5 @@ # Qowaiv Diagnostics Contracts -This packages contains attributes to define (expected) behaviour on code. +This packages contains attributes to define (expected) behavior on code. ## Impure attribute Opposed to the `[Pure]` attribute, the `[Impure]` attribute indicates that a diff --git a/src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs b/src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs index 930bcf7c..eadebc01 100644 --- a/src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs +++ b/src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs @@ -3,4 +3,4 @@ /// Indicates the class will be sealed with the next major change. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] [Conditional("CONTRACTS_FULL")] -public sealed class WillBeSealedAttributee(string? message = null) : InheritableAttribute(message) { } +public sealed class WillBeSealedAttribute(string? message = null) : InheritableAttribute(message) { } diff --git a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs b/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs deleted file mode 100644 index 800aad53..00000000 --- a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Qowaiv.Testools.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. Methods decorated with -/// this attribute return the same instance that was provided as argument. -/// -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public sealed class FluentSyntaxAttribute : ImpureAttribute { } diff --git a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/ImpureAttribute.cs b/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/ImpureAttribute.cs deleted file mode 100644 index 83f646ce..00000000 --- a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/ImpureAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Qowaiv.Testools.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class ImpureAttribute : Attribute { } diff --git a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/InheritableAttribute.cs b/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/InheritableAttribute.cs deleted file mode 100644 index 249461ff..00000000 --- a/src/Qowaiv.TestTools/Internals/Diagnostics/Contracts/InheritableAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Qowaiv.Testools.Internals.Diagnostics.Contracts; - -/// Indicates the a class is designed to be inheritable. -[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class InheritableAttribute : Attribute -{ - /// Initializes a new instance of the class. - public InheritableAttribute(string? message = null) => _ = message; -} diff --git a/src/Qowaiv.TestTools/Properties/GlobalUsings.cs b/src/Qowaiv.TestTools/Properties/GlobalUsings.cs index 0fe06824..259bd0ab 100644 --- a/src/Qowaiv.TestTools/Properties/GlobalUsings.cs +++ b/src/Qowaiv.TestTools/Properties/GlobalUsings.cs @@ -1,5 +1,5 @@ global using Qowaiv; -global using Qowaiv.Testools.Internals.Diagnostics.Contracts; +global using Qowaiv.Diagnostics.Contracts; global using System; global using System.Collections; global using System.Collections.Generic; diff --git a/src/Qowaiv.TestTools/Qowaiv.TestTools.csproj b/src/Qowaiv.TestTools/Qowaiv.TestTools.csproj index fea1b5ba..fa50f3ec 100644 --- a/src/Qowaiv.TestTools/Qowaiv.TestTools.csproj +++ b/src/Qowaiv.TestTools/Qowaiv.TestTools.csproj @@ -40,6 +40,7 @@ v6.0.0 + diff --git a/src/Qowaiv/Internals/Diagnostics/DebugDisplay.cs b/src/Qowaiv/Diagnostics/DebugDisplay.cs similarity index 94% rename from src/Qowaiv/Internals/Diagnostics/DebugDisplay.cs rename to src/Qowaiv/Diagnostics/DebugDisplay.cs index 9ba4f6a4..c191963e 100644 --- a/src/Qowaiv/Internals/Diagnostics/DebugDisplay.cs +++ b/src/Qowaiv/Diagnostics/DebugDisplay.cs @@ -1,6 +1,6 @@ using System.Reflection; -namespace Qowaiv.Internals.Diagnostics; +namespace Qowaiv.Diagnostics; internal static class DebugDisplay { diff --git a/src/Qowaiv/Internals/Diagnostics/Contracts/CollectionMutationAttribute.cs b/src/Qowaiv/Internals/Diagnostics/Contracts/CollectionMutationAttribute.cs deleted file mode 100644 index a2a0b038..00000000 --- a/src/Qowaiv/Internals/Diagnostics/Contracts/CollectionMutationAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Qowaiv.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. Methods decorated with -/// this attribute return info about (like, removal or addition was successful). -/// -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -internal sealed class CollectionMutationAttribute : ImpureAttribute { } diff --git a/src/Qowaiv/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs b/src/Qowaiv/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs deleted file mode 100644 index 8405ded6..00000000 --- a/src/Qowaiv/Internals/Diagnostics/Contracts/FluentSyntaxAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Qowaiv.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. Methods decorated with -/// this attribute return the same instance that was provided as argument. -/// -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public sealed class FluentSyntaxAttribute : ImpureAttribute { } diff --git a/src/Qowaiv/Internals/Diagnostics/Contracts/ImpureAttribute.cs b/src/Qowaiv/Internals/Diagnostics/Contracts/ImpureAttribute.cs deleted file mode 100644 index d17ac482..00000000 --- a/src/Qowaiv/Internals/Diagnostics/Contracts/ImpureAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Qowaiv.Internals.Diagnostics.Contracts; - -/// To mark a method explicitly as impure. -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class ImpureAttribute : Attribute { } diff --git a/src/Qowaiv/Internals/Diagnostics/Contracts/InheritableAttribute.cs b/src/Qowaiv/Internals/Diagnostics/Contracts/InheritableAttribute.cs deleted file mode 100644 index 915a0dc8..00000000 --- a/src/Qowaiv/Internals/Diagnostics/Contracts/InheritableAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Qowaiv.Internals.Diagnostics.Contracts; - -/// Indicates the a class is designed to be inheritable. -[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public class InheritableAttribute : Attribute -{ - /// Initializes a new instance of the class. - public InheritableAttribute(string? message = null) => _ = message; -} diff --git a/src/Qowaiv/Internals/Diagnostics/Contracts/WillBeSealedAttribute.cs b/src/Qowaiv/Internals/Diagnostics/Contracts/WillBeSealedAttribute.cs deleted file mode 100644 index df76ce95..00000000 --- a/src/Qowaiv/Internals/Diagnostics/Contracts/WillBeSealedAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Qowaiv.Internals.Diagnostics.Contracts; - -/// Indicates the class will be sealed with the next major change. -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -[Conditional("CONTRACTS_FULL")] -public sealed class WillBeSealedAttribute : InheritableAttribute { } diff --git a/src/Qowaiv/Properties/GlobalUsings.cs b/src/Qowaiv/Properties/GlobalUsings.cs index 45031d05..d5ccafb5 100644 --- a/src/Qowaiv/Properties/GlobalUsings.cs +++ b/src/Qowaiv/Properties/GlobalUsings.cs @@ -1,8 +1,8 @@ global using Qowaiv.Conversion; +global using Qowaiv.Diagnostics; +global using Qowaiv.Diagnostics.Contracts; global using Qowaiv.Formatting; global using Qowaiv.Hashing; -global using Qowaiv.Internals.Diagnostics; -global using Qowaiv.Internals.Diagnostics.Contracts; global using Qowaiv.OpenApi; global using Qowaiv.Security; global using Qowaiv.Text; diff --git a/src/Qowaiv/Qowaiv.csproj b/src/Qowaiv/Qowaiv.csproj index b89acd71..afe9c7d7 100644 --- a/src/Qowaiv/Qowaiv.csproj +++ b/src/Qowaiv/Qowaiv.csproj @@ -144,4 +144,8 @@ v5.1.2 + + + +