public void CreateLazilyReturnsCommand()
 {
     var sut = new TestCaseCommandFactory();
     var testMethod = Reflector.Wrap(new Methods<TestClass>().Select(x => x.ThrowMethod()));
     Assert.DoesNotThrow(() =>
     {
         sut.Create(testMethod, Mocked.Of<ISpecimenBuilderFactory>());
     });
 }
        public void CreateReturnsCorrectCommandForParameterizedMethod()
        {
            var sut = new TestCaseCommandFactory();
            var testMethod = Reflector.Wrap(
                new Methods<TestClass>().Select(x => x.TestMethod(null, 0, null)));

            var actual = sut.Create(testMethod, new FakeBuilderFactory());

            Assert.True(actual.Any());
        }
        public void CreateDoesNotCreateTestFixtureForNonParameterizedMethod()
        {
            var sut = new TestCaseCommandFactory();
            var method = new Methods<TestClass>().Select(x => x.TestMethod());
            var factory = Mocked.Of<ISpecimenBuilderFactory>();

            sut.Create(Reflector.Wrap(method), factory);

            factory.ToMock().Verify(x => x.Create(It.IsAny<ITestMethodContext>()), Times.Never());
        }
        public void CreatePassesCorrectMethodContextForParameterizedMethod()
        {
            var sut = new TestCaseCommandFactory();
            var method = new Methods<TestClass>().Select(x => x.TestMethod(null, 0, null));
            var factory = Mocked.Of<ISpecimenBuilderFactory>();
            factory.ToMock()
                .Setup(x => x.Create(It.IsAny<ITestMethodContext>()))
                .Returns(new Fixture())
                .Callback<ITestMethodContext>(c =>
                {
                    Assert.Equal(method, c.TestMethod);
                    Assert.Equal(method, c.ActualMethod);
                    Assert.IsAssignableFrom<TestClass>(c.TestObject);
                    Assert.IsAssignableFrom<TestClass>(c.ActualObject);
                });

            sut.Create(Reflector.Wrap(method), factory).ToArray();

            factory.ToMock().VerifyAll();
        }
        public void CreateReturnsCorrectCommands()
        {
            // Fixture setup
            var testMethod = Reflector.Wrap(new Methods<TestClass>().Select(x => x.TestMethod()));
            var sut = new TestCaseCommandFactory();
            var factory = Mocked.Of<ISpecimenBuilderFactory>();

            // Exercise system
            var actual = sut.Create(testMethod, factory).ToArray();

            // Verify outcome
            Assert.Equal(3, actual.Length);
            foreach (var testCommand in actual)
            {
                var parameterizedCommand = Assert.IsAssignableFrom<ParameterizedCommand>(testCommand);
                var context = Assert.IsAssignableFrom<TestCaseCommandContext>(
                    parameterizedCommand.TestCommandContext);

                Assert.Equal(testMethod, context.TestMethod);
                Assert.Equal(TestClass.Method, context.ActualMethod.MethodInfo);
                Assert.Equal(TestClass.TestObject, context.ActualObject);
                Assert.Equal(factory, context.BuilderFactory);
                Assert.Equal(TestClass.Arguments, context.ExplicitArguments);
            }
        }
        public void CreateWithStaticClassReturnsCorrectCommands()
        {
            var sut = new TestCaseCommandFactory();
            var testMethod = Reflector.Wrap(Methods.Select(() => StaticTestClass.TestMethod()));

            var actual = sut.Create(testMethod, Mocked.Of<ISpecimenBuilderFactory>()).ToArray();

            Assert.Equal(1, actual.Length);
        }
 public void CreateWithNullTestMethodThrows()
 {
     var sut = new TestCaseCommandFactory();
     Assert.Throws<ArgumentNullException>(() => sut.Create(null, null).ToArray());
 }
        public void CreateReturnsNonEmptyIfReturnTypeIsCorrect(Type returnType)
        {
            var sut = new TestCaseCommandFactory();
            var testMethod = new Methods<TestClass>().Select(x => x.TestMethod());
            var factory = Mocked.Of<ISpecimenBuilderFactory>();

            var actual = sut.Create(Reflector.Wrap(testMethod), factory);

            Assert.NotEmpty(actual);
        }
        public void CreateReturnsEmptyIfReturnTypeIsIncorrect(Type returnType)
        {
            var sut = new TestCaseCommandFactory();
            var testMethod = Mocked.Of<IMethodInfo>(
                m => m.MethodInfo == Mocked.Of<MethodInfo>(i => i.ReturnType == returnType));

            var actual = sut.Create(testMethod, null);

            Assert.Empty(actual);
        }