Skip to content

Commit

Permalink
Allow CollectionAttribute to reference a definition class directly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesTerwilliger committed Feb 18, 2024
1 parent 15e9f98 commit 5490c98
Show file tree
Hide file tree
Showing 17 changed files with 762 additions and 43 deletions.
21 changes: 21 additions & 0 deletions src/common.tests/TestDoubles/Mocks.Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ public static _IReflectionAttributeInfo CollectionAttribute(string collectionNam
return result;
}

public static _IReflectionAttributeInfo CollectionAttribute(Type collectionType)
{
var result = Substitute.For<_IReflectionAttributeInfo, InterfaceProxy<_IReflectionAttributeInfo>>();
result.Attribute.Returns(new CollectionAttribute(collectionType));
result.AttributeType.Returns(Reflector.Wrap(typeof(CollectionAttribute)));
result.GetConstructorArguments().Returns(new[] { collectionType });
return result;
}

#if !NETFRAMEWORK

public static _IReflectionAttributeInfo CollectionAttribute<TCollectionType>()
{
var result = Substitute.For<_IReflectionAttributeInfo, InterfaceProxy<_IReflectionAttributeInfo>>();
result.Attribute.Returns(new CollectionAttribute<TCollectionType>());
result.AttributeType.Returns(Reflector.Wrap(typeof(CollectionAttribute<TCollectionType>)));
return result;
}

#endif

public static _IReflectionAttributeInfo CollectionBehaviorAttribute(
CollectionBehavior? collectionBehavior = null,
bool disableTestParallelization = false,
Expand Down
17 changes: 17 additions & 0 deletions src/xunit.v3.common/Utility/UniqueIDGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@ public void Dispose()
return generator.Compute();
}

/// <summary>
/// Computes a unique ID for a type/>
/// </summary>
/// <param name="type">The type to generate an ID for</param>
public static string ForType(_ITypeInfo type)
{
Guard.ArgumentNotNull(type);

using var generator = new UniqueIDGenerator();

// Assembly name may include some parts that are less stable, so for now, split on comma
var assemblyParts = type.Assembly.Name.Split(',');
generator.Add(assemblyParts[0]);
generator.Add(type.Name);
return generator.Compute();
}

static char ToHexChar(int b) =>
(char)(b < 10 ? b + '0' : b - 10 + 'a');

Expand Down

0 comments on commit 5490c98

Please sign in to comment.