protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
        {
            var commands = base.EnumerateTestCommands(method);
            var attrs = method.MethodInfo.GetCustomAttributes(typeof(DataAttribute), false);

            if (commands.Count() != attrs.Count())
            {
                throw new InvalidOperationException("Some data attribute doesn't generate test command");
            }

            var filteredCommands = new List<ITestCommand>();
            int index = 0;

            foreach (var command in commands)
            {
                var theoryCmd = command as TheoryCommand;
                var skippableData = attrs.ElementAt(index++) as ISkippable;
                if (skippableData != null &&
                    !string.IsNullOrEmpty(skippableData.SkipReason))
                {
                    SkipCommand cmd = new SkipCommand(method, theoryCmd.DisplayName, skippableData.SkipReason);
                    filteredCommands.Add(cmd);
                }
                else
                {
                    filteredCommands.Add(command);
                }
            }

            return filteredCommands;
        }
Exemplo n.º 2
0
        public void SkipReturnSkipResult()
        {
            MethodInfo method = typeof(SpyStub).GetMethod("Skip");
            SkipCommand command = new SkipCommand(Reflector.Wrap(method), null, "reason");

            MethodResult result = command.Execute(new SpyStub());

            SkipResult skipResult = Assert.IsType<SkipResult>(result);
            Assert.Equal("reason", skipResult.Reason);
        }