Ejemplo n.º 1
0
        public void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType)
        {
            var attr = Mocks.CollectionBehaviorAttribute(behavior);
            var assembly = Mocks.TestAssembly();

            var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(spy, attr, assembly);

            Assert.IsType(expectedType, result);
        }
Ejemplo n.º 2
0
        public void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType)
        {
            var attr     = Mocks.CollectionBehaviorAttribute(behavior);
            var assembly = Mocks.TestAssembly();

            var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(spy, attr, assembly);

            Assert.IsType(expectedType, result);
        }
        public static void Attribute_CollectionBehavior(CollectionBehavior behavior, string expectedDisplayText)
        {
            var attribute = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true);
            var assembly  = Mocks.TestAssembly(new[] { attribute });
            var runner    = TestableXunitTestAssemblyRunner.Create(assembly: assembly);

            var result = runner.GetTestFrameworkEnvironment();

            Assert.EndsWith(string.Format("[{0}, non-parallel]", expectedDisplayText), result);
        }
        public static void Attribute_CollectionBehavior(CollectionBehavior behavior, string expectedDisplayText)
        {
            var attribute = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true);
            var assembly = Mocks.TestAssembly(attributes: new[] { attribute });
            var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly);

            var result = runner.GetTestFrameworkEnvironment();

            Assert.EndsWith(String.Format("[{0}, non-parallel]", expectedDisplayText), result);
        }
Ejemplo n.º 5
0
        public static async ValueTask Attribute_CollectionBehavior(CollectionBehavior behavior, string expectedDisplayText)
        {
            var attribute = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true);
            var assembly  = Mocks.TestAssembly("assembly.dll", assemblyAttributes: new[] { attribute });

            await using var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly);

            var result = runner.GetTestFrameworkEnvironment();

            Assert.EndsWith($"[{expectedDisplayText}, non-parallel]", result);
        }
        public static void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType, string expectedDisplayText)
        {
            var attr = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true);
            var assembly = Mocks.AssemblyInfo(attributes: new[] { attr });
            var sourceInfoProvider = Substitute.For<ISourceInformationProvider>();

            var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider);

            Assert.IsType(expectedType, discoverer.TestCollectionFactory);
            Assert.Equal(String.Format("{0} [{1}, non-parallel]", XunitTestFrameworkDiscoverer.DisplayName, expectedDisplayText), discoverer.TestFrameworkDisplayName);
        }
Ejemplo n.º 7
0
        public static void AssemblyAttributeOverride(
            CollectionBehavior behavior,
            Type expectedFactoryType)
        {
            var behaviorAttribute = Mocks.CollectionBehaviorAttribute(behavior);
            var assembly          = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });

            var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);

            Assert.IsType(expectedFactoryType, discoverer.TestCollectionFactory);
        }
Ejemplo n.º 8
0
        public static void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType, string expectedDisplayText)
        {
            var attr               = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true);
            var assembly           = Mocks.AssemblyInfo(attributes: new[] { attr });
            var sourceInfoProvider = Substitute.For <ISourceInformationProvider>();

            var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider);

            Assert.IsType(expectedType, discoverer.TestCollectionFactory);
            Assert.Equal(String.Format("{0} [{1}, non-parallel]", XunitTestFrameworkDiscoverer.DisplayName, expectedDisplayText), discoverer.TestFrameworkDisplayName);
        }
Ejemplo n.º 9
0
    public static IReflectionAttributeInfo CollectionBehaviorAttribute(CollectionBehavior collectionBehavior, bool disableTestParallelization = false)
    {
        var result = Substitute.For <IReflectionAttributeInfo>();

        result.Attribute.Returns(new CollectionBehaviorAttribute(collectionBehavior)
        {
            DisableTestParallelization = disableTestParallelization
        });
        result.GetConstructorArguments().Returns(new object[] { collectionBehavior });
        result.GetNamedArgument <bool>("DisableTestParallelization").Returns(disableTestParallelization);
        return(result);
    }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionBehaviorAttribute" /> class.
 /// </summary>
 /// <param name="collectionBehavior">The collection behavior for the assembly.</param>
 public CollectionBehaviorAttribute(CollectionBehavior collectionBehavior)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionBehaviorAttribute" /> class.
 /// </summary>
 /// <param name="collectionBehavior">The collection behavior for the assembly.</param>
 public CollectionBehaviorAttribute(CollectionBehavior collectionBehavior)
 {
 }
Ejemplo n.º 12
0
        public static LambdaExpression CombineCollectionPropertySelectorWithPredicate(LambdaExpression propertySelector, LambdaExpression propertyPredicate, CollectionBehavior collectionBehavior = CollectionBehavior.All)
        {
            // x => ids.Contains(x.Id)
            // x => Collection.Any(ids.Contains(x.Id))
            var memberExpression = propertySelector.Body as MemberExpression;
            var propertyInfo     = ((PropertyInfo)memberExpression.Member);
            var containingType   = propertyInfo.DeclaringType;

            if (memberExpression == null)
            {
                throw new ArgumentException("propertySelector");
            }
            var        rootPredicateType = typeof(Func <,>).GetGenericTypeDefinition().MakeGenericType(containingType, typeof(bool));
            MethodInfo filterMethodInfo;

            if (collectionBehavior == CollectionBehavior.All)
            {
                filterMethodInfo = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).Single(mi => mi.Name == "All" && mi.GetParameters().Count() == 2).MakeGenericMethod(propertyInfo.PropertyType.ToSingleType());
            }
            else
            {
                filterMethodInfo = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).Single(mi => mi.Name == "Any" && mi.GetParameters().Count() == 2).MakeGenericMethod(propertyInfo.PropertyType.ToSingleType());
            }
            var collectionCall = Expression.Call(null, filterMethodInfo, memberExpression, propertyPredicate);

            return(Expression.Lambda(rootPredicateType, collectionCall, propertySelector.Parameters));
        }