/// <summary>
 /// Initializes a new instance of the <see cref="CollectionPerAssemblyTestCollectionFactory" /> class.
 /// </summary>
 /// <param name="assemblyInfo">The assembly.</param>
 /// <param name="messageAggregator">The message aggregator used to report <see cref="EnvironmentalWarning"/> messages.</param>
 public CollectionPerAssemblyTestCollectionFactory(IAssemblyInfo assemblyInfo, IMessageAggregator messageAggregator)
 {
     defaultCollection = new XunitTestCollection {
         DisplayName = "Test collection for " + Path.GetFileName(assemblyInfo.AssemblyPath)
     };
     collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(assemblyInfo, messageAggregator);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CollectionPerAssemblyTestCollectionFactory" /> class.
        /// </summary>
        /// <param name="testAssembly">The assembly.</param>
        /// <param name="messageAggregator">The message aggregator used to report <see cref="EnvironmentalWarning"/> messages.</param>
        public CollectionPerAssemblyTestCollectionFactory(ITestAssembly testAssembly, IMessageAggregator messageAggregator)
        {
            this.testAssembly = testAssembly;

            defaultCollection = new XunitTestCollection(testAssembly, null, "Test collection for " + Path.GetFileName(testAssembly.Assembly.AssemblyPath));
            collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(testAssembly.Assembly, messageAggregator);
        }
        public void DeserializedTestCaseContainsSameDataAsOriginalTestCase()
        {
            var testCollection = new XunitTestCollection();
            var type = typeof(ClassUnderTest);
            var method = type.GetMethod("FactMethod");
            var fact = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(FactAttribute));
            var testCase = new XunitTestCase(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(fact));
            var serialized = SerializationHelper.Serialize(testCase);

            var result = SerializationHelper.Deserialize<XunitTestCase>(serialized);

            Assert.Equal(testCase.Assembly.AssemblyPath, result.Assembly.AssemblyPath);
            Assert.Equal(testCase.Assembly.Name, result.Assembly.Name);
            Assert.Equal(testCase.Class.Name, result.Class.Name);
            Assert.Equal(testCase.Method.Name, result.Method.Name);
            Assert.Equal(testCase.DisplayName, result.DisplayName);
            Assert.Null(result.Arguments);
            Assert.Equal(testCase.SkipReason, result.SkipReason);
            Assert.Collection(result.Traits.Keys,
                key =>
                {
                    Assert.Equal("name", key);
                    Assert.Equal("value", Assert.Single(result.Traits[key]));
                });
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CollectionPerAssemblyTestCollectionFactory" /> class.
        /// </summary>
        /// <param name="testAssembly">The assembly.</param>
        /// <param name="messageAggregator">The message aggregator used to report <see cref="EnvironmentalWarning"/> messages.</param>
        public CollectionPerAssemblyTestCollectionFactory(ITestAssembly testAssembly, IMessageAggregator messageAggregator)
        {
            this.testAssembly = testAssembly;

            defaultCollection     = new XunitTestCollection(testAssembly, null, "Test collection for " + Path.GetFileName(testAssembly.Assembly.AssemblyPath));
            collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(testAssembly.Assembly, messageAggregator);
        }
        public void CanSerializeFactBasedTestCase()
        {
            var testCollection = new XunitTestCollection();
            var type = typeof(ClassUnderTest);
            var method = type.GetMethod("FactMethod");
            var fact = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(FactAttribute));
            var testCase = new XunitTestCase(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(fact));

            Assert.DoesNotThrow(() => SerializationHelper.Serialize(testCase));
        }
    public void SkipReason()
    {
        var testCollection = new XunitTestCollection();
        var fact = Mocks.FactAttribute(skip: "Skip Reason");
        var method = Mocks.MethodInfo();
        var type = Mocks.TypeInfo(methods: new[] { method });
        var assmInfo = Mocks.AssemblyInfo(types: new[] { type });

        var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact);

        Assert.Equal("Skip Reason", testCase.SkipReason);
    }
Esempio n. 7
0
    static XunitTestCase Create(Type typeUnderTest, string methodName, params object[] arguments)
    {
        var testCollection = new XunitTestCollection();
        var methodUnderTest = typeUnderTest.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
        var assembly = Reflector.Wrap(typeUnderTest.Assembly);
        var type = Reflector.Wrap(typeUnderTest);
        var method = Reflector.Wrap(methodUnderTest);
        var fact = Reflector.Wrap(CustomAttributeData.GetCustomAttributes(methodUnderTest)
                                                     .Single(cad => cad.AttributeType == typeof(FactAttribute)));

        return new XunitTestCase(testCollection, assembly, type, method, fact, arguments.Length == 0 ? null : arguments);
    }
        public void DeserializedTestWithNonSerializableArgumentsThrows()
        {
            var testCollection = new XunitTestCollection();
            var type = typeof(ClassUnderTest);
            var method = type.GetMethod("FactMethod");
            var fact = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(FactAttribute));
            var testCase = new XunitTestCase(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(fact), new object[] { new ClassUnderTest() });

            var ex = Record.Exception(() => SerializationHelper.Serialize(testCase));

            Assert.IsType<SerializationException>(ex);
        }
Esempio n. 9
0
    public void NonSerializableDataYieldsSingleTheoryTestCase()
    {
        var testCollection = new XunitTestCollection();
        var discoverer = new TheoryDiscoverer();
        var type = typeof(NonSerializableDataClass);
        var method = type.GetMethod("TheoryMethod");
        var theory = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(TheoryAttribute));

        var testCases = discoverer.Discover(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(theory));

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+NonSerializableDataClass.TheoryMethod", theoryTestCase.DisplayName);
    }
Esempio n. 10
0
    public void DefaultFactAttribute()
    {
        var testCollection = new XunitTestCollection();
        var fact = Mocks.FactAttribute();
        var method = Mocks.MethodInfo();
        var type = Mocks.TypeInfo(methods: new[] { method });
        var assmInfo = Mocks.AssemblyInfo(types: new[] { type });

        var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact);

        Assert.Equal("MockType.MockMethod", testCase.DisplayName);
        Assert.Null(testCase.SkipReason);
        Assert.Empty(testCase.Traits);
    }
Esempio n. 11
0
        public void TraitsOnTestMethod()
        {
            var testCollection = new XunitTestCollection();
            var fact = Mocks.FactAttribute();
            var trait1 = Mocks.TraitAttribute("Trait1", "Value1");
            var trait2 = Mocks.TraitAttribute("Trait2", "Value2");
            var method = Mocks.MethodInfo(attributes: new[] { trait1, trait2 });
            var type = Mocks.TypeInfo(methods: new[] { method });
            var assmInfo = Mocks.AssemblyInfo(types: new[] { type });

            var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact);

            Assert.Equal("Value1", Assert.Single(testCase.Traits["Trait1"]));
            Assert.Equal("Value2", Assert.Single(testCase.Traits["Trait2"]));
        }
        public void DeserializedTestWithSerializableArgumentsPreservesArguments()
        {
            var testCollection = new XunitTestCollection();
            var type = typeof(ClassUnderTest);
            var method = type.GetMethod("FactMethod");
            var fact = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(FactAttribute));
            var testCase = new XunitTestCase(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(fact), new object[] { 42, 21.12, "Hello world" });
            var serialized = SerializationHelper.Serialize(testCase);

            var result = SerializationHelper.Deserialize<XunitTestCase>(serialized);

            Assert.Collection(result.Arguments,
                arg => Assert.Equal(42, arg),
                arg => Assert.Equal(21.12, arg),
                arg => Assert.Equal("Hello world", arg));
        }
Esempio n. 13
0
    public void DisposesArguments()
    {
        var disposable1 = Substitute.For<IDisposable>();
        var disposable2 = Substitute.For<IDisposable>();
        var testCollection = new XunitTestCollection();
        var fact = Mocks.FactAttribute();
        var method = Mocks.MethodInfo();
        var type = Mocks.TypeInfo(methods: new[] { method });
        var assmInfo = Mocks.AssemblyInfo(types: new[] { type });
        var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact, new[] { disposable1, disposable2 });

        testCase.Dispose();

        disposable1.Received(1).Dispose();
        disposable2.Received(1).Dispose();
    }
Esempio n. 14
0
    public void DataDiscovererReturningNullYieldsSingleTheoryTestCase()
    {
        var testCollection = new XunitTestCollection();
        var discoverer = new TheoryDiscoverer();
        var assembly = Mocks.AssemblyInfo();
        var type = Mocks.TypeInfo();
        var theory = Mocks.TheoryAttribute();
        var data = Substitute.For<IAttributeInfo>();
        var method = Mocks.MethodInfo();
        method.GetCustomAttributes(typeof(DataAttribute).AssemblyQualifiedName).Returns(new[] { data });
        method.GetCustomAttributes(typeof(TheoryAttribute).AssemblyQualifiedName).Returns(new[] { theory });

        var testCases = discoverer.Discover(testCollection, assembly, type, method, theory);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("MockType.MockMethod", theoryTestCase.DisplayName);
    }
Esempio n. 15
0
    public void ThrowingData()
    {
        var testCollection = new XunitTestCollection();
        var discoverer = new TheoryDiscoverer();
        var type = typeof(ThrowingDataClass);
        var method = type.GetMethod("TheoryWithMisbehavingData");
        var theory = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(TheoryAttribute));

        var testCases = discoverer.Discover(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(theory));

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+ThrowingDataClass.TheoryWithMisbehavingData", theoryTestCase.DisplayName);
    }
Esempio n. 16
0
        public void CustomDisplayName()
        {
            var testCollection = new XunitTestCollection();
            var fact = Mocks.FactAttribute(displayName: "Custom Display Name");
            var method = Mocks.MethodInfo();
            var type = Mocks.TypeInfo(methods: new[] { method });
            var assmInfo = Mocks.AssemblyInfo(types: new[] { type });

            var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact);

            Assert.Equal("Custom Display Name", testCase.DisplayName);
        }
Esempio n. 17
0
        public void CorrectNumberOfTestArguments()
        {
            var testCollection = new XunitTestCollection();
            var fact = Mocks.FactAttribute();
            var param1 = Mocks.ParameterInfo("p1");
            var param2 = Mocks.ParameterInfo("p2");
            var param3 = Mocks.ParameterInfo("p3");
            var method = Mocks.MethodInfo(parameters: new[] { param1, param2, param3 });
            var type = Mocks.TypeInfo(methods: new[] { method });
            var assmInfo = Mocks.AssemblyInfo(types: new[] { type });
            var arguments = new object[] { 42, "Hello, world!", 'A' };

            var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact, arguments);

            Assert.Equal("MockType.MockMethod(p1: 42, p2: \"Hello, world!\", p3: 'A')", testCase.DisplayName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionPerAssemblyTestCollectionFactory" /> class.
 /// </summary>
 /// <param name="assemblyInfo">The assembly.</param>
 /// <param name="messageAggregator">The message aggregator used to report <see cref="EnvironmentalWarning"/> messages.</param>
 public CollectionPerAssemblyTestCollectionFactory(IAssemblyInfo assemblyInfo, IMessageAggregator messageAggregator)
 {
     defaultCollection = new XunitTestCollection { DisplayName = "Test collection for " + Path.GetFileName(assemblyInfo.AssemblyPath) };
     collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(assemblyInfo, messageAggregator);
 }
Esempio n. 19
0
        public void TooManyTestArguments()
        {
            var testCollection = new XunitTestCollection();
            var fact = Mocks.FactAttribute();
            var param = Mocks.ParameterInfo("p1");
            var method = Mocks.MethodInfo(parameters: new[] { param });
            var type = Mocks.TypeInfo(methods: new[] { method });
            var assmInfo = Mocks.AssemblyInfo(types: new[] { type });
            var arguments = new object[] { 42, 21.12 };

            var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact, arguments);

            Assert.Equal("MockType.MockMethod(p1: 42, ???: 21.12)", testCase.DisplayName);
        }