Skip to content

Commit

Permalink
Extend tests to guard conditional attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Feb 18, 2024
1 parent 5f5ab33 commit dd38780
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
29 changes: 29 additions & 0 deletions specs/Qowaiv.Specs/Diagnostics/Contracts/Conditional_specs.cs
@@ -0,0 +1,29 @@
namespace Diagnostics.Contracts.Conditional_specs;

public class Is_decorated_with_condtional_CONTRACTS_FULL
{
[Test]
public void Collection_mutation_attribute()
=> typeof(Qowaiv.Diagnostics.Contracts.CollectionMutationAttribute)
.Should().DecoratedWithConditionalAttribute("CONTRACTS_FULL");

[Test]
public void Fluent_syntax_attribute()
=> typeof(Qowaiv.Diagnostics.Contracts.FluentSyntaxAttribute)
.Should().DecoratedWithConditionalAttribute("CONTRACTS_FULL");

[Test]
public void Impure_attribute()
=> typeof(Qowaiv.Diagnostics.Contracts.ImpureAttribute)
.Should().DecoratedWithConditionalAttribute("CONTRACTS_FULL");

[Test]
public void Inheritable_attribute()
=> typeof(Qowaiv.Diagnostics.Contracts.InheritableAttribute)
.Should().DecoratedWithConditionalAttribute("CONTRACTS_FULL");

[Test]
public void Mutable_attribute()
=> typeof(Qowaiv.Diagnostics.Contracts.MutableAttribute)
.Should().DecoratedWithConditionalAttribute("CONTRACTS_FULL");
}
@@ -1,6 +1,6 @@
namespace Diagnostics.Contracts.Impure_attribute_specs;

internal class Can_decorate_methods_with
public class Can_decorate_methods_with
{
[Test]
public void Collection_mutation_attribute()
Expand Down
16 changes: 16 additions & 0 deletions specs/Qowaiv.Specs/FluentAssertions/System.Type.Assertions.cs
@@ -0,0 +1,16 @@
using FluentAssertions.Types;

namespace FluentAssertions;

internal static class QowaivSpecsTypeAssertions
{
public static AndWhichConstraint<TypeAssertions, ConditionalAttribute> DecoratedWithConditionalAttribute(
this TypeAssertions assertions,
string condition,
string because = "", params object[] becauseArgs)
{
var andWhich = assertions.Subject.Should().BeDecoratedWith<ConditionalAttribute>();
andWhich.Which.ConditionString.Should().Be(condition, because, becauseArgs);
return andWhich;
}
}
25 changes: 25 additions & 0 deletions src/Qowaiv.Diagnostics.Contracts/README.md
@@ -1,6 +1,31 @@
# Qowaiv Diagnostics Contracts
This packages contains attributes to define (expected) behavior on code.

Most likely, you only need this dependency compile time. In that case you
should add the dependency as follows:

``` XML
<ItemGroup>
<PackageReference
Include="Qowaiv.Diagnostics.Contracts"
Version="*"
PrivateAssets=""all"
IncludeAssets="compile" />
<ItemGroup>
```
To embed the result of these decorations in the compiled assembly, the `DEFINE`
constant `CONTRACTS_FULL` has to be set.
``` XML
<PropertyGroup>
<DefineConstants>CONTRACTS_FULL</DefineConstants>
</PropertyGroup>
```
If you only use these decorations to enable static code analysis, this constant
is not needed.
## Impure attribute
Opposed to the `[Pure]` attribute, the `[Impure]` attribute indicates that a
method has side effects. This attribute can help working with static code
Expand Down

0 comments on commit dd38780

Please sign in to comment.