Exemplo n.º 1
0
        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]));
            });
        }
    public static async void UsesCustomTestOrderer()
    {
        var collection = new XunitTestCollection(null, Reflector.Wrap(typeof(CollectionUnderTest)), null);
        var testCase   = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection);
        var runner     = TestableXunitTestCollectionRunner.Create(testCase);

        await runner.RunAsync();

        Assert.IsType <CustomTestCaseOrderer>(runner.TestCaseOrderer);
    }
Exemplo n.º 3
0
        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 XunitTheoryTestCase(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(fact));

            Assert.DoesNotThrow(() => SerializationHelper.Serialize(testCase));
        }
    public static async void DisposesFixtures()
    {
        var collection = new XunitTestCollection(null, Reflector.Wrap(typeof(CollectionUnderTest)), null);
        var testCase   = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection);
        var runner     = TestableXunitTestCollectionRunner.Create(testCase);

        await runner.RunAsync();

        var fixtureUnderTest = runner.CollectionFixtureMappings.Values.OfType <FixtureUnderTest>().Single();

        Assert.True(fixtureUnderTest.Disposed);
    }
Exemplo n.º 5
0
        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);
        }
    public static async void CreatesFixtures()
    {
        var collection = new XunitTestCollection(null, Reflector.Wrap(typeof(CollectionUnderTest)), null);
        var testCase   = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection);
        var runner     = TestableXunitTestCollectionRunner.Create(testCase);

        await runner.RunAsync();

        Assert.Collection(runner.CollectionFixtureMappings.OrderBy(mapping => mapping.Key.Name),
                          mapping => Assert.IsType <FixtureUnderTest>(mapping.Value),
                          mapping => Assert.IsType <Object>(mapping.Value)
                          );
    }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
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);
    }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
    public static XunitTestCase XunitTestCase <TClassUnderTest>(string methodName)
    {
        var typeUnderTest   = typeof(TClassUnderTest);
        var methodUnderTest = typeUnderTest.GetMethod(methodName);

        if (methodUnderTest == null)
        {
            throw new Exception(String.Format("Unknown method: {0}.{1}", typeUnderTest.FullName, methodName));
        }

        var testCollection = new XunitTestCollection();
        var assemblyInfo   = Reflector.Wrap(typeUnderTest.Assembly);
        var typeInfo       = Reflector.Wrap(typeUnderTest);
        var methodInfo     = Reflector.Wrap(methodUnderTest);
        var factAttribute  = methodInfo.GetCustomAttributes(typeof(FactAttribute)).SingleOrDefault();

        return(new XunitTestCase(testCollection, assemblyInfo, typeInfo, methodInfo, factAttribute));
    }
Exemplo n.º 11
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);
    }