public void ClassStartThrowsWhenClassHasMoreThanOneConstructor(Type classType)
        {
            var sut = new ParadigmTestClassCommand
            {
                TypeUnderTest = Reflector.Wrap(classType)
            };

            var exception = sut.ClassStart();
            Assert.IsType<InvalidParadigmException>(exception);
            Assert.Equal("The class " + classType.FullName + " must have exactly one constructor", exception.Message);
        }
 public void ClassStartDoesNotThrowUponMatchingConstructor(
     Type classType,
     object[] exemplarArguments,
     ParadigmTestClassCommand sut,
     IAttributeInfo attributeInfo,
     ParadigmDataAttribute attribute)
 {
     Mock.Get(sut.TypeUnderTest).SetupGet(x => x.Type)
         .Returns(classType);
 
     Mock.Get(sut.TypeUnderTest).Setup(x => x.GetCustomAttributes(typeof(ParadigmDataAttribute)))
         .Returns(new[] { attributeInfo });
 
     Mock.Get(attributeInfo).Setup(x => x.GetInstance<ParadigmDataAttribute>())
         .Returns(attribute);
 
     Mock.Get(attribute).Setup(x => x.GetData(It.IsAny<ConstructorInfo>(), It.IsAny<Type[]>()))
         .Returns(new[] { exemplarArguments });
 
     Assert.Null(sut.ClassStart());
 }
        public void ClassStartThrowsUponMismatchingConstructors(
            Type classType, 
            object[] exemplarArguments, 
            string expectedMessage,
            ParadigmTestClassCommand sut, 
            IAttributeInfo attributeInfo, 
            ParadigmDataAttribute attribute)
        {
            Mock.Get(sut.TypeUnderTest).SetupGet(x => x.Type)
                .Returns(classType);

            Mock.Get(sut.TypeUnderTest).Setup(x => x.GetCustomAttributes(typeof (ParadigmDataAttribute)))
                .Returns(new[] { attributeInfo });

            Mock.Get(attributeInfo).Setup(x => x.GetInstance<ParadigmDataAttribute>())
                .Returns(attribute);

            Mock.Get(attribute).Setup(x => x.GetData(It.IsAny<ConstructorInfo>(), It.IsAny<Type[]>()))
                .Returns(new [] { exemplarArguments });

            var exception = sut.ClassStart();
            Assert.IsType<InvalidParadigmExemplarException>(exception);
            Assert.Equal(expectedMessage, exception.Message);
        }
        public void RandomOrderIsUsedToChooseNextTest(int count, int randomValue, [Frozen] IRandomizer randomizer, ParadigmTestClassCommand sut, IFixture fixture)
        {
            Mock.Get(randomizer).Setup(x => x.Next(count)).Returns(randomValue);

            var methods = fixture.CreateMany<IMethodInfo>(count).ToList();

            var actual = sut.ChooseNextTest(methods);
            Assert.Equal(randomValue, actual);
        }
        public void OnlyTypeMethodsWithFactAttributeAreConsideredTests(
            bool firstHasFact,
            bool secondHasFact,
            bool thirdHasFact,
            ParadigmTestClassCommand sut,
            IMethodInfo[] methods)
        {
            Mock.Get(sut.TypeUnderTest).Setup(x => x.GetMethods()).Returns(methods);

            foreach (var methodInfo in methods)
            {
                Mock.Get(methodInfo).SetupGet(x => x.IsAbstract).Returns(false);
            }

            Mock.Get(methods[0]).Setup(x => x.HasAttribute(typeof(FactAttribute))).Returns(firstHasFact);
            Mock.Get(methods[1]).Setup(x => x.HasAttribute(typeof(FactAttribute))).Returns(secondHasFact);
            Mock.Get(methods[2]).Setup(x => x.HasAttribute(typeof(FactAttribute))).Returns(thirdHasFact);

            var expected = new List<IMethodInfo>();
            if (firstHasFact) expected.Add(methods[0]);
            if (secondHasFact) expected.Add(methods[1]);
            if (thirdHasFact) expected.Add(methods[2]);

            var actual = sut.EnumerateTestMethods();

            Assert.Equal(expected, actual);
        }
 public void MethodsWithFactAttributeAreConsideredTests(ParadigmTestClassCommand sut, IMethodInfo methodToTest)
 {
     Mock.Get(methodToTest).SetupGet(x => x.IsAbstract).Returns(false);
     Mock.Get(methodToTest).Setup(x => x.HasAttribute(typeof(FactAttribute))).Returns(true);
     Assert.True(sut.IsTestMethod(methodToTest));
 }
 public void MethodsWithoutFactAttributeAreSkipped(ParadigmTestClassCommand sut, IMethodInfo methodToTest)
 {
     Mock.Get(methodToTest).Setup(x => x.HasAttribute(typeof (FactAttribute))).Returns(false);
     Assert.False(sut.IsTestMethod(methodToTest));
 }
        public void SkippedMethodsAreHandled(
            string skipReason,
            ParadigmTestClassCommand sut,
            IMethodInfo methodToTest)
        {
            Mock.Get(methodToTest).Setup(x => x.GetCustomAttributes(typeof (FactAttribute)))
                .Returns(new[]
                {
                    Reflector.Wrap(new FactAttribute
                    {
                        Skip = skipReason
                    })
                });

            sut.ClassStart();
            var commands = sut.EnumerateTestCommands(methodToTest).ToList();
            Assert.That(commands, Is.OfLength(1));
            Assert.That(commands[0], Describe.Object<ITestCommand>()
                .Cast<SkipCommand>(c => c.Property(x => x.Reason, Is.EqualTo(skipReason))));
        }
 public void AbstractMethodsAreSkipped(ParadigmTestClassCommand sut, IMethodInfo methodToTest)
 {
     Mock.Get(methodToTest).SetupGet(x => x.IsAbstract).Returns(true);
     Assert.False(sut.IsTestMethod(methodToTest));
 }
        public void ExceptionThrownDuringFixtureSetDisposeIsReturnedButNotThrown(
            [Frozen] IFixtureSetFactory fixtureSetFactory,
            ParadigmTestClassCommand sut,
            IFixtureSet fixtureSet,
            Exception expected
            )
        {
            Mock.Get(fixtureSetFactory).Setup(x => x.CreateFixturesFor(sut.TypeUnderTest))
                .Returns(fixtureSet);

            sut.ClassStart();

            Mock.Get(fixtureSet).Setup(x => x.Dispose()).Throws(expected);
            var result = sut.ClassFinish();

            Assert.Same(expected, result);
        }
        public void FixtureSetIsDisposedOnClassFinish (
            [Frozen] IFixtureSetFactory fixtureSetFactory,
            ParadigmTestClassCommand sut,
            IFixtureSet fixtureSet)
        {
            Mock.Get(fixtureSetFactory).Setup(x => x.CreateFixturesFor(sut.TypeUnderTest))
                .Returns(fixtureSet);

            sut.ClassStart();

            Mock.Get(fixtureSet).Verify(x => x.Dispose(), Times.Never());
            var result = sut.ClassFinish();
            Mock.Get(fixtureSet).Verify(x => x.Dispose());

            Assert.Null(result);
        }
        public void CreatedFixtureSetIsUsedToCreateTestCommands(
            [Frozen] IExemplarFactory exemplarFactory,
            [Frozen] IFixtureSetFactory fixtureSetFactory,
            ParadigmTestClassCommand sut,
            IParadigmExemplar[] exemplars,
            IEnumerable<ITestCommand>[] createdCommands,
            IFixtureSet fixtureSet,
            IMethodInfo methodInfo)
        {
            Mock.Get(exemplarFactory).Setup(x => x.CreateExemplarsFor(sut.TypeUnderTest))
                .Returns(exemplars);

            for (var i = 0; i < exemplars.Length; i++)
            {
                Mock.Get(exemplars[i]).Setup(x => x.CreateTestCommands(It.IsAny<IMethodInfo>(), fixtureSet))
                    .Returns(createdCommands[i]);
            }

            Mock.Get(fixtureSetFactory).Setup(x => x.CreateFixturesFor(sut.TypeUnderTest))
                .Returns(fixtureSet);

            sut.ClassStart();

            var commands = sut.EnumerateTestCommands(methodInfo);

            Assert.Equal(createdCommands.SelectMany(x => x), commands);
        }
        public void ExceptionFromFixtureSetCreationIsReturnedButNotThrown(
            [Frozen] IFixtureSetFactory fixtureSetFactory,
            ParadigmTestClassCommand sut,
            Exception expected)
        {
            Mock.Get(fixtureSetFactory).Setup(x => x.CreateFixturesFor(sut.TypeUnderTest))
                .Throws(expected);

            var actual = sut.ClassStart();

            Assert.Same(expected, actual);
        }
        public void FixtureSetIsCreatedDuringClassStart(
            [Frozen] IFixtureSetFactory fixtureSetFactory,
            ParadigmTestClassCommand sut,
            IFixtureSet fixtureSet)
        {
            Mock.Get(fixtureSetFactory).Setup(x => x.CreateFixturesFor(sut.TypeUnderTest))
                .Returns(fixtureSet);

            var result = sut.ClassStart();

            Assert.Null(result);
            Assert.Same(fixtureSet, sut.FixtureSet);
        }