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
13 changes: 13 additions & 0 deletions ArchUnitNET/Domain/ISizedObjectProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace ArchUnitNET.Domain
{
/// <summary>
/// An interface for object providers that can provide a size independent of the used architecture.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface ISizedObjectProvider<out T> : IObjectProvider<T>
{
int Count { get; }
}
}
9 changes: 5 additions & 4 deletions ArchUnitNET/Fluent/Conditions/RelationCondition.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent.Conditions
Expand All @@ -8,10 +9,10 @@ public class RelationCondition<TRuleType, TRelatedType> : IHasDescription
where TRuleType : ICanBeAnalyzed
where TRelatedType : ICanBeAnalyzed
{
private readonly Func<IEnumerable<TRelatedType>, ICondition<TRuleType>> _relation;
private readonly Func<IObjectProvider<TRelatedType>, ICondition<TRuleType>> _relation;

public RelationCondition(
Func<IEnumerable<TRelatedType>, ICondition<TRuleType>> relation,
Func<IObjectProvider<TRelatedType>, ICondition<TRuleType>> relation,
string description,
string failDescription
)
Expand All @@ -25,9 +26,9 @@ string failDescription

public string Description { get; }

public ICondition<TRuleType> GetCondition(IEnumerable<TRelatedType> objectProvider)
public ICondition<TRuleType> GetCondition(IEnumerable<TRelatedType> objects)
{
return _relation(objectProvider);
return _relation(new ListObjectProvider<TRelatedType>(objects.ToList()));
}

private bool Equals(RelationCondition<TRuleType, TRelatedType> other)
Expand Down
52 changes: 52 additions & 0 deletions ArchUnitNET/Fluent/ListObjectProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent
{
public class ListObjectProvider<T> : ISizedObjectProvider<T>
where T : ICanBeAnalyzed
{
private readonly IEnumerable<T> _objects;

public ListObjectProvider(List<T> objects)
{
_objects = objects;
Description = string.Join(" or ", objects.Select(obj => $"\"{obj.FullName}\""));
}

public string Description { get; }

public int Count => _objects.Count();

public IEnumerable<T> GetObjects(Architecture architecture)
{
return _objects;
}

private bool Equals(ListObjectProvider<T> other)
{
return string.Equals(Description, other.Description);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

return obj.GetType() == GetType() && Equals((ListObjectProvider<T>)obj);
}

public override int GetHashCode()
{
return Description != null ? Description.GetHashCode() : 0;
}
}
}
Loading