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 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 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 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 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);
        }