Esempio n. 1
0
        /// <summary>
        /// Converts a type into a name string.
        /// </summary>
        /// <param name="type">The type to convert.</param>
        /// <returns>Name string of type.</returns>
        public static string ConvertToSimpleTypeName(_ITypeInfo type)
        {
            Guard.ArgumentNotNull(nameof(type), type);

            var baseTypeName = type.Name;

            var backTickIdx = baseTypeName.IndexOf('`');

            if (backTickIdx >= 0)
            {
                baseTypeName = baseTypeName.Substring(0, backTickIdx);
            }

            var lastIndex = baseTypeName.LastIndexOf('.');

            if (lastIndex >= 0)
            {
                baseTypeName = baseTypeName.Substring(lastIndex + 1);
            }

            if (!type.IsGenericType)
            {
                return(baseTypeName);
            }

            var genericTypes = type.GetGenericArguments().ToArray();
            var simpleNames  = new string[genericTypes.Length];

            for (var idx = 0; idx < genericTypes.Length; idx++)
            {
                simpleNames[idx] = ConvertToSimpleTypeName(genericTypes[idx]);
            }

            return($"{baseTypeName}<{string.Join(", ", simpleNames)}>");
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Xunit2TypeInfo"/> class.
        /// </summary>
        /// <param name="v3TypeInfo">The v3 type info to wrap.</param>
        public Xunit2TypeInfo(_ITypeInfo v3TypeInfo)
        {
            V3TypeInfo = Guard.ArgumentNotNull(nameof(v3TypeInfo), v3TypeInfo);

            Assembly   = new Xunit2AssemblyInfo(V3TypeInfo.Assembly);
            BaseType   = V3TypeInfo.BaseType == null ? null : new Xunit2TypeInfo(V3TypeInfo.BaseType);
            Interfaces = V3TypeInfo.Interfaces.Select(i => new Xunit2TypeInfo(i)).ToList();
        }
Esempio n. 3
0
    /// <summary>
    /// Gets all the custom attributes for the given type.
    /// </summary>
    /// <param name="typeInfo">The type</param>
    /// <param name="attributeType">The type of the attribute</param>
    /// <returns>The matching attributes that decorate the type</returns>
    public static IEnumerable <_IAttributeInfo> GetCustomAttributes(this _ITypeInfo typeInfo, Type attributeType)
    {
        Guard.ArgumentNotNull(nameof(typeInfo), typeInfo);
        Guard.ArgumentNotNull(nameof(attributeType), attributeType);
        Guard.NotNull("Attribute type cannot be a generic type parameter", attributeType.AssemblyQualifiedName);

        return(typeInfo.GetCustomAttributes(attributeType.AssemblyQualifiedName));
    }
Esempio n. 4
0
    /// <summary>
    /// Gets all the custom attributes for the given type.
    /// </summary>
    /// <param name="typeInfo">The type</param>
    /// <param name="attributeType">The type of the attribute</param>
    /// <returns>The matching attributes that decorate the type</returns>
    public static IReadOnlyCollection <_IAttributeInfo> GetCustomAttributes(this _ITypeInfo typeInfo, Type attributeType)
    {
        Guard.ArgumentNotNull(typeInfo);
        Guard.ArgumentNotNull(attributeType);
        Guard.NotNull("Attribute type cannot be a generic type parameter", attributeType.AssemblyQualifiedName);

        return(typeInfo.GetCustomAttributes(attributeType.AssemblyQualifiedName));
    }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClass"/> class.
 /// </summary>
 /// <param name="testCollection">The test collection the class belongs to</param>
 /// <param name="class">The test class</param>
 /// <param name="uniqueID">The unique ID for the test class (only used to override default behavior in testing scenarios)</param>
 public TestClass(
     _ITestCollection testCollection,
     _ITypeInfo @class,
     string?uniqueID = null)
 {
     this.@class         = Guard.ArgumentNotNull(@class);
     this.testCollection = Guard.ArgumentNotNull(testCollection);
     this.uniqueID       = uniqueID ?? UniqueIDGenerator.ForTestClass(TestCollection.UniqueID, Class.Name);
 }
Esempio n. 6
0
    /// <summary>
    /// Converts an <see cref="_ITypeInfo"/> into a <see cref="Type"/>, if possible (for example, this
    /// will not work when the test class is based on source code rather than binaries).
    /// </summary>
    /// <param name="typeInfo">The type to convert</param>
    /// <returns>The runtime type, if available, <c>null</c>, otherwise</returns>
    public static Type?ToRuntimeType(this _ITypeInfo typeInfo)
    {
        if (typeInfo is _IReflectionTypeInfo reflectionTypeInfo)
        {
            return(reflectionTypeInfo.Type);
        }

        return(SerializationHelper.GetType(typeInfo.Assembly.Name, typeInfo.Name));
    }
Esempio n. 7
0
        /// <inheritdoc/>
        public _ITestCollection Get(_ITypeInfo testClass)
        {
            Guard.ArgumentNotNull(nameof(testClass), testClass);

            var collectionAttribute = testClass.GetCustomAttributes(typeof(CollectionAttribute)).SingleOrDefault();

            if (collectionAttribute == null)
            {
                return(defaultCollection);
            }

            var collectionName = collectionAttribute.GetConstructorArguments().Cast <string>().Single();

            return(testCollections.GetOrAdd(collectionName, CreateTestCollection));
        }
Esempio n. 8
0
        /// <summary>
        /// Used for de-serialization.
        /// </summary>
        protected TestClass(
            SerializationInfo info,
            StreamingContext context)
        {
            testCollection = Guard.NotNull("Could not retrieve TestCollection from serialization", info.GetValue <_ITestCollection>("TestCollection"));
            uniqueID       = Guard.NotNull("Could not retrieve UniqueID from serialization", info.GetValue <string>("UniqueID"));

            var assemblyName = Guard.NotNull("Could not retrieve ClassAssemblyName from serialization", info.GetValue <string>("ClassAssemblyName"));
            var typeName     = Guard.NotNull("Could not retrieve ClassTypeName from serialization", info.GetValue <string>("ClassTypeName"));

            var type = SerializationHelper.GetType(assemblyName, typeName);

            if (type == null)
            {
                throw new InvalidOperationException($"Failed to deserialize type '{typeName}' in assembly '{assemblyName}'");
            }

            @class = Reflector.Wrap(type);
        }
 protected sealed override bool IsValidTestClass(_ITypeInfo type)
 {
     return(base.IsValidTestClass(type));
 }
 public new _ITestClass CreateTestClass(_ITypeInfo @class)
 {
     return(base.CreateTestClass(@class));
 }
Esempio n. 11
0
 public _ITestCollection Get(_ITypeInfo testClass)
 {
     throw new NotImplementedException();
 }
Esempio n. 12
0
 public _ITestCollection Get(_ITypeInfo _) =>
 throw new NotImplementedException();
 protected override ValueTask <_ITestClass> CreateTestClass(_ITypeInfo @class) =>
 /// <inheritdoc/>
 protected internal override _ITestClass CreateTestClass(_ITypeInfo @class) =>
 new TestClass(TestCollectionFactory.Get(@class), @class);
Esempio n. 15
0
 protected sealed override bool IsValidTestClass(_ITypeInfo type) =>
 base.IsValidTestClass(type);
Esempio n. 16
0
 public new ValueTask <_ITestClass> CreateTestClass(_ITypeInfo @class) =>
 base.CreateTestClass(@class);