Execute() public method

Executes this test command with a test object.
public Execute ( object testClass ) : MethodResult
testClass object /// The type of the test object. ///
return MethodResult
        public void ExecuteCorrectlyInvokesActualMethod()
        {
            // Fixture setup
            var verified = false;

            var arguments = new object[] { "1", 1 };

            var delegator = new Action<string, int>((x, y) =>
            {
                Assert.Equal(x, arguments[0]);
                Assert.Equal(y, arguments[1]);
                verified = true;
            });

            var testObject = new object();

            var methodContext = Mocked.Of<ITestMethodContext>(
                x => x.ActualMethod == delegator.Method
                && x.ActualObject == delegator.Target);

            var context = Mocked.Of<ITestCommandContext>(x =>
                x.GetMethodContext(testObject) == methodContext
                && x.GetArguments(methodContext) == arguments);

            var sut = new ParameterizedCommand(context);

            // Exercise system
            sut.Execute(testObject);

            // Verify outcome
            Assert.True(verified, "verified");
        }
        public void ExecuteReturnsCorrectResult()
        {
            // Fixture setup
            var testMethod = new Action(() => { }).Method;
            var actualMethod = new Action(() => { }).Method;

            var testObject = Activator.CreateInstance(actualMethod.ReflectedType);

            var methodContext = Mocked.Of<ITestMethodContext>(
                x => x.ActualMethod == actualMethod && x.ActualObject == testObject);

            var context = Mocked.Of<ITestCommandContext>(
                x => x.TestMethod == Reflector.Wrap(testMethod)
                && x.GetMethodContext(testObject) == methodContext);

            var sut = new ParameterizedCommand(context);

            // Exercise system
            var actual = sut.Execute(testObject);

            // Verify outcome
            var passedResult = Assert.IsAssignableFrom<PassedResult>(actual);
            Assert.Equal(testMethod.Name, passedResult.MethodName);
            Assert.Equal(actual.DisplayName, passedResult.DisplayName);
        }
        public void ExecuteSetsCorrectDisplayName()
        {
            // Fixture setup
            var arguments = new object[] { "1", 1 };

            var testMethod = Reflector.Wrap(new Action<string, int>((x, y) => { }).Method);

            var testObject = new object();

            var context = Mocked.Of<ITestCommandContext>(x =>
                x.TestMethod == testMethod
                && x.GetArguments(It.IsAny<ITestMethodContext>()) == arguments);

            var sut = new ParameterizedCommand(context);

            var expectecd = new TheoryCommand(testMethod, arguments).DisplayName;

            // Exercise system
            sut.Execute(testObject);

            // Verify outcome
            Assert.Equal(expectecd, sut.DisplayName);
        }
        public void ExecuteSetsDisplayNameBeforeInvokingActualMethod()
        {
            var testMethod = Reflector.Wrap(
                new Action(() => { throw new InvalidOperationException(); }).Method);
            var sut = new ParameterizedCommand(new ParameterizedCommandContext(
                testMethod,
                Mocked.Of<ISpecimenBuilderFactory>(),
                Enumerable.Empty<object>()));
            var expectecd = new TheoryCommand(testMethod, new object[0]).DisplayName;

            Assert.Throws<InvalidOperationException>(
                () => sut.Execute(Activator.CreateInstance(testMethod.Class.Type)));
            Assert.Equal(expectecd, sut.DisplayName);
        }