Skip to content
Merged
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
24 changes: 24 additions & 0 deletions ArchUnitNETTests/AssemblyTestHelper/AttributeAssemblyTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ public class AttributeAssemblyTestHelpers : AssemblyTestHelper
public System.Type ClassWithThreeAttributesWithNamedArgumentsSystemType =
typeof(ClassWithThreeAttributesWithNamedArguments);

public Attribute RegularAttribute;
public System.Type RegularAttributeSystemType = typeof(RegularAttribute);

public Attribute OtherRegularAttribute;
public System.Type OtherRegularAttributeSystemType = typeof(OtherRegularAttribute);

public Attribute AbstractAttribute;
public System.Type AbstractAttributeSystemType = typeof(AbstractAttribute);

public Attribute OtherAbstractAttribute;
public System.Type OtherAbstractAttributeSystemType = typeof(OtherAbstractAttribute);

public Attribute SealedAttribute;
public System.Type SealedAttributeSystemType = typeof(SealedAttribute);

public Attribute OtherSealedAttribute;
public System.Type OtherSealedAttributeSystemType = typeof(OtherSealedAttribute);

public AttributeAssemblyTestHelpers()
{
Attribute1 = Architecture.GetAttributeOfType(typeof(Attribute1));
Expand Down Expand Up @@ -122,5 +140,11 @@ public AttributeAssemblyTestHelpers()
ClassWithThreeAttributesWithNamedArguments = Architecture.GetClassOfType(
typeof(ClassWithThreeAttributesWithNamedArguments)
);
RegularAttribute = Architecture.GetAttributeOfType(typeof(RegularAttribute));
OtherRegularAttribute = Architecture.GetAttributeOfType(typeof(OtherRegularAttribute));
AbstractAttribute = Architecture.GetAttributeOfType(typeof(AbstractAttribute));
OtherAbstractAttribute = Architecture.GetAttributeOfType(typeof(OtherAbstractAttribute));
SealedAttribute = Architecture.GetAttributeOfType(typeof(SealedAttribute));
OtherSealedAttribute = Architecture.GetAttributeOfType(typeof(OtherSealedAttribute));
}
}
249 changes: 111 additions & 138 deletions ArchUnitNETTests/Fluent/Syntax/Elements/AttributeSyntaxElementsTests.cs
Original file line number Diff line number Diff line change
@@ -1,158 +1,131 @@
using System.Collections.Generic;
using ArchUnitNET.Domain;
using System.Threading.Tasks;
using ArchUnitNETTests.AssemblyTestHelper;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace ArchUnitNETTests.Fluent.Syntax.Elements
{
// csharpier-ignore
public class AttributeSyntaxElementsTests
{
public AttributeSyntaxElementsTests()
[Fact]
public async Task BeAbstractTest()
{
_attributes = Architecture.Attributes;
var helper = new AttributeAssemblyTestHelpers();

helper.AddSnapshotHeader("No Violations");
var should = Attributes().That().Are(helper.AbstractAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.BeAbstract().AssertNoViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreAbstract()).AssertNoViolations(helper);

helper.AddSnapshotHeader("Violations");
should = Attributes().That().Are(helper.RegularAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.BeAbstract().AssertOnlyViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreAbstract()).AssertOnlyViolations(helper);

helper.AddSnapshotHeader("Multiple inputs");
Attributes().That().Are(helper.AbstractAttribute, helper.OtherAbstractAttribute).Should().BeAbstract().AssertNoViolations(helper);
Attributes().That().Are(helper.AbstractAttribute, helper.RegularAttribute).Should().BeAbstract().AssertAnyViolations(helper);

await helper.AssertSnapshotMatches();
}

private static readonly Architecture Architecture =
StaticTestArchitectures.ArchUnitNETTestArchitecture;
private readonly IEnumerable<Attribute> _attributes;
[Fact]
public async Task NotBeAbstractTest()
{
var helper = new AttributeAssemblyTestHelpers();

helper.AddSnapshotHeader("No Violations");
var should = Attributes().That().Are(helper.RegularAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.NotBeAbstract().AssertNoViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreNotAbstract()).AssertNoViolations(helper);

helper.AddSnapshotHeader("Violations");
should = Attributes().That().Are(helper.AbstractAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.NotBeAbstract().AssertOnlyViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreNotAbstract()).AssertOnlyViolations(helper);

helper.AddSnapshotHeader("Multiple inputs");
Attributes().That().Are(helper.RegularAttribute, helper.OtherRegularAttribute).Should().NotBeAbstract().AssertNoViolations(helper);
Attributes().That().Are(helper.RegularAttribute, helper.AbstractAttribute).Should().NotBeAbstract().AssertAnyViolations(helper);

await helper.AssertSnapshotMatches();
}

[Fact]
public void AreAbstractTest()
public async Task BeSealedTest()
{
foreach (var attribute in _attributes)
{
var attributeIsAbstract = Attributes().That().Are(attribute).Should().BeAbstract();
var attributeIsNotAbstract = Attributes()
.That()
.Are(attribute)
.Should()
.NotBeAbstract();
var abstractAttributesDoNotIncludeType = Attributes()
.That()
.AreAbstract()
.Should()
.NotBe(attribute)
.OrShould()
.NotExist();
var notAbstractAttributesDoNotIncludeType = Attributes()
.That()
.AreNotAbstract()
.Should()
.NotBe(attribute)
.AndShould()
.Exist();

Assert.Equal(
attribute.IsAbstract,
attributeIsAbstract.HasNoViolations(Architecture)
);
Assert.Equal(
!attribute.IsAbstract,
attributeIsNotAbstract.HasNoViolations(Architecture)
);
Assert.Equal(
!attribute.IsAbstract,
abstractAttributesDoNotIncludeType.HasNoViolations(Architecture)
);
Assert.Equal(
attribute.IsAbstract,
notAbstractAttributesDoNotIncludeType.HasNoViolations(Architecture)
);
}

var abstractAttributesAreAbstract = Attributes()
.That()
.AreAbstract()
.Should()
.BeAbstract();
var abstractAttributesAreNotAbstract = Attributes()
.That()
.AreAbstract()
.Should()
.NotBeAbstract()
.AndShould()
.Exist();
var notAbstractAttributesAreAbstract = Attributes()
.That()
.AreNotAbstract()
.Should()
.BeAbstract()
.AndShould()
.Exist();
var notAbstractAttributesAreNotAbstract = Attributes()
.That()
.AreNotAbstract()
.Should()
.NotBeAbstract();

Assert.True(abstractAttributesAreAbstract.HasNoViolations(Architecture));
Assert.False(abstractAttributesAreNotAbstract.HasNoViolations(Architecture));
Assert.False(notAbstractAttributesAreAbstract.HasNoViolations(Architecture));
Assert.True(notAbstractAttributesAreNotAbstract.HasNoViolations(Architecture));
var helper = new AttributeAssemblyTestHelpers();

helper.AddSnapshotHeader("No Violations");
var should = Attributes().That().Are(helper.SealedAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.BeSealed().AssertNoViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreSealed()).AssertNoViolations(helper);

helper.AddSnapshotHeader("Violations");
should = Attributes().That().Are(helper.RegularAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.BeSealed().AssertOnlyViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreSealed()).AssertOnlyViolations(helper);

helper.AddSnapshotHeader("Multiple inputs");
Attributes().That().Are(helper.SealedAttribute, helper.OtherSealedAttribute).Should().BeSealed().AssertNoViolations(helper);
Attributes().That().Are(helper.SealedAttribute, helper.RegularAttribute).Should().BeSealed().AssertAnyViolations(helper);

await helper.AssertSnapshotMatches();
}

[Fact]
public void AreSealedTest()
public async Task NotBeSealedTest()
{
foreach (var attribute in _attributes)
{
var attributeIsSealed = Attributes().That().Are(attribute).Should().BeSealed();
var attributeIsNotSealed = Attributes()
.That()
.Are(attribute)
.Should()
.NotBeSealed();
var sealedAttributesDoNotIncludeType = Attributes()
.That()
.AreSealed()
.Should()
.NotBe(attribute);
var notSealedAttributesDoNotIncludeType = Attributes()
.That()
.AreNotSealed()
.Should()
.NotBe(attribute);

Assert.Equal(attribute.IsSealed, attributeIsSealed.HasNoViolations(Architecture));
Assert.Equal(
!attribute.IsSealed,
attributeIsNotSealed.HasNoViolations(Architecture)
);
Assert.Equal(
!attribute.IsSealed,
sealedAttributesDoNotIncludeType.HasNoViolations(Architecture)
);
Assert.Equal(
attribute.IsSealed,
notSealedAttributesDoNotIncludeType.HasNoViolations(Architecture)
);
}

var sealedAttributesAreSealed = Attributes().That().AreSealed().Should().BeSealed();
var sealedAttributesAreNotSealed = Attributes()
.That()
.AreSealed()
.Should()
.NotBeSealed()
.AndShould()
.Exist();
var notSealedAttributesAreSealed = Attributes()
.That()
.AreNotSealed()
.Should()
.BeSealed()
.AndShould()
.Exist();
var notSealedAttributesAreNotSealed = Attributes()
.That()
.AreNotSealed()
.Should()
.NotBeSealed();

Assert.True(sealedAttributesAreSealed.HasNoViolations(Architecture));
Assert.False(sealedAttributesAreNotSealed.HasNoViolations(Architecture));
Assert.False(notSealedAttributesAreSealed.HasNoViolations(Architecture));
Assert.True(notSealedAttributesAreNotSealed.HasNoViolations(Architecture));
var helper = new AttributeAssemblyTestHelpers();

helper.AddSnapshotHeader("No Violations");
var should = Attributes().That().Are(helper.RegularAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.NotBeSealed().AssertNoViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreNotSealed()).AssertNoViolations(helper);

helper.AddSnapshotHeader("Violations");
should = Attributes().That().Are(helper.SealedAttribute).Should();

helper.AddSnapshotSubHeader("Conditions");
should.NotBeSealed().AssertOnlyViolations(helper);

helper.AddSnapshotSubHeader("Predicates");
should.Be(Attributes().That().AreNotSealed()).AssertOnlyViolations(helper);

helper.AddSnapshotHeader("Multiple inputs");
Attributes().That().Are(helper.RegularAttribute, helper.OtherRegularAttribute).Should().NotBeSealed().AssertNoViolations(helper);
Attributes().That().Are(helper.RegularAttribute, helper.SealedAttribute).Should().NotBeSealed().AssertAnyViolations(helper);

await helper.AssertSnapshotMatches();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
===== No Violations =====

----- Conditions -----

Query: Attributes that are "AttributeNamespace.AbstractAttribute" should be abstract
Result: True
Description: AttributeNamespace.AbstractAttribute passed
Message:
All Evaluations passed

----- Predicates -----

Query: Attributes that are "AttributeNamespace.AbstractAttribute" should be Attributes that are abstract
Result: True
Description: AttributeNamespace.AbstractAttribute passed
Message:
All Evaluations passed

===== Violations =====

----- Conditions -----

Query: Attributes that are "AttributeNamespace.RegularAttribute" should be abstract
Result: False
Description: AttributeNamespace.RegularAttribute is not abstract
Message:
"Attributes that are "AttributeNamespace.RegularAttribute" should be abstract" failed:
AttributeNamespace.RegularAttribute is not abstract



----- Predicates -----

Query: Attributes that are "AttributeNamespace.RegularAttribute" should be Attributes that are abstract
Result: False
Description: AttributeNamespace.RegularAttribute is not Attributes that are abstract
Message:
"Attributes that are "AttributeNamespace.RegularAttribute" should be Attributes that are abstract" failed:
AttributeNamespace.RegularAttribute is not Attributes that are abstract



===== Multiple inputs =====

Query: Attributes that are "AttributeNamespace.AbstractAttribute" or "AttributeNamespace.OtherAbstractAttribute" should be abstract
Result: True
Description: AttributeNamespace.AbstractAttribute passed
Result: True
Description: AttributeNamespace.OtherAbstractAttribute passed
Message:
All Evaluations passed

Query: Attributes that are "AttributeNamespace.AbstractAttribute" or "AttributeNamespace.RegularAttribute" should be abstract
Result: False
Description: AttributeNamespace.RegularAttribute is not abstract
Result: True
Description: AttributeNamespace.AbstractAttribute passed
Message:
"Attributes that are "AttributeNamespace.AbstractAttribute" or "AttributeNamespace.RegularAttribute" should be abstract" failed:
AttributeNamespace.RegularAttribute is not abstract



Loading
Loading