public void ShouldCallTheUserConverterToConvertTableWithTableAndMultilineArg()
        {
            var converter = MockRepository.Stub<IStepArgumentTypeConverter>();
            ObjectContainer.StepArgumentTypeConverter = converter;
            ObjectContainer.StepDefinitionSkeletonProvider(ProgrammingLanguage.CSharp);

            StepExecutionTestsBindingsForTableArgumentConvert bindingInstance;
            TestRunner testRunner = GetTestRunnerFor(out bindingInstance);

            Table table = new Table("h1");
            var user = new User();

            // return false unless its a User
            converter.Stub(c => c.CanConvert(table, typeof(User), FeatureLanguage)).Return(true);
            converter.Stub(c => c.CanConvert(null, null, null)).IgnoreArguments().Return(false);
            converter.Stub(c => c.Convert(table, typeof(User), FeatureLanguage)).Return(user);

            var multiLineArg = "multi-line arg";
            bindingInstance.Expect(b => b.MultilineArgumentAndTable(multiLineArg, user));
            MockRepository.ReplayAll();

            testRunner.Given("sample step for argument convert with multiline argument and table", multiLineArg, table);

            Assert.AreEqual(TestStatus.OK, ObjectContainer.ScenarioContext.TestStatus);
            MockRepository.VerifyAll();
        }
        public void StepArgumentTypeConverterShouldUseUserConverterForConversion()
        {
            UserCreator stepTransformationInstance = new UserCreator();
            var transformMethod = new RuntimeBindingMethod(stepTransformationInstance.GetType().GetMethod("Create"));
            var stepTransformationBinding = CreateStepTransformationBinding(@"user (\w+)", transformMethod);
            stepTransformations.Add(stepTransformationBinding);
            TimeSpan duration;
            var resultUser = new User();
            methodBindingInvokerStub.Setup(i => i.InvokeBinding(stepTransformationBinding, It.IsAny<IContextManager>(), It.IsAny<object[]>(), It.IsAny<ITestTracer>(), out duration))
                .Returns(resultUser);

            var stepArgumentTypeConverter = CreateStepArgumentTypeConverter();

            var result = stepArgumentTypeConverter.Convert("user xyz", typeof(User), new CultureInfo("en-US"));
            Assert.That(result, Is.EqualTo(resultUser));
        }
        public void ShouldUseStepArgumentTransformationToConvertTable()
        {
            var table = new Table("Name");

            UserCreator stepTransformationInstance = new UserCreator();
            var transformMethod = new RuntimeBindingMethod(stepTransformationInstance.GetType().GetMethod("CreateUsers"));
            var stepTransformationBinding = CreateStepTransformationBinding(@"", transformMethod);
            stepTransformations.Add(stepTransformationBinding);
            TimeSpan duration;
            var resultUsers = new User[3];
            methodBindingInvokerStub.Setup(i => i.InvokeBinding(stepTransformationBinding, It.IsAny<IContextManager>(), new object[] { table }, It.IsAny<ITestTracer>(), out duration))
                .Returns(resultUsers);

            var stepArgumentTypeConverter = CreateStepArgumentTypeConverter();

            var result = stepArgumentTypeConverter.Convert(table, typeof(IEnumerable<User>), new CultureInfo("en-US"));

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(resultUsers));
        }
        public void ShouldCallTheUserConverterToConvertTableWithTable()
        {
            StepExecutionTestsBindingsForTableArgumentConvert bindingInstance;
            TestRunner testRunner = GetTestRunnerWithConverterStub(out bindingInstance);

            Table table = new Table("h1");
            var user = new User();

            // return false unless its a User
            StepArgumentTypeConverterStub.Stub(c => c.CanConvert(table, typeof(User), FeatureLanguage)).Return(true);
            StepArgumentTypeConverterStub.Stub(c => c.CanConvert(null, null, null)).IgnoreArguments().Return(false);
            StepArgumentTypeConverterStub.Stub(c => c.Convert(table, typeof(User), FeatureLanguage)).Return(user);

            bindingInstance.Expect(b => b.SingleTable(user));
            MockRepository.ReplayAll();

            testRunner.Given("sample step for argument convert with table", null, table);

            Assert.AreEqual(TestStatus.OK, GetLastTestStatus());
            MockRepository.VerifyAll();
        }
        public void ShouldCallTheUserConverterToConvertTableWithTableAndMultilineArg()
        {
            StepExecutionTestsBindingsForTableArgumentConvert bindingInstance;
            TestRunner testRunner = GetTestRunnerWithConverterStub(out bindingInstance);

            Table table = new Table("h1");
            var user = new User();

            // return false unless its a User
            StepArgumentTypeConverterStub.Stub(LegacyStepArgumentTypeConverterExtensions.GetCanConvertMethodFilter(table, typeof(User))).Return(true);
            StepArgumentTypeConverterStub.Stub(c => c.CanConvert(null, null, null)).IgnoreArguments().Return(false);
            StepArgumentTypeConverterStub.Stub(LegacyStepArgumentTypeConverterExtensions.GetConvertMethodFilter(table, typeof(User))).Return(user);

            var multiLineArg = "multi-line arg";
            bindingInstance.Expect(b => b.MultilineArgumentAndTable(multiLineArg, user));
            MockRepository.ReplayAll();

            testRunner.Given("sample step for argument convert with multiline argument and table", multiLineArg, table);

            Assert.AreEqual(TestStatus.OK, GetLastTestStatus());
            MockRepository.VerifyAll();
        }
        public void StepArgumentTypeConverterShouldNotUseUserConverterForNonStringConvertion()
        {
            var transformMethod = typeof(UserCreator).GetMethod("Create");
            var stepTransformationBinding = CreateStepTransformationBinding(transformMethod);
            stepTransformations.Clear();
            stepTransformations.Add(stepTransformationBinding);
            TimeSpan duration;
            var resultUser = new User();
            var methodBindingInvokerStub = new Mock<IBindingInvoker>();
            methodBindingInvokerStub.Setup(i => i.InvokeBinding(stepTransformationBinding, It.IsAny<IContextManager>(), It.IsAny<object[]>(), It.IsAny<ITestTracer>(), out duration))
                .Returns(resultUser);

            var stepArgumentTypeConverter = CreateStepArgumentTypeConverter(methodBindingInvokerStub.Object);

            var table = new Table("Name");
            table.AddRow("xyz");
            var result = stepArgumentTypeConverter.Convert(table, new RuntimeBindingType(typeof(User)), new CultureInfo("en-US"));
            Assert.That(result, Is.Not.EqualTo(resultUser));
        }
        public void ShouldCallTheUserConverterToConvertTableWithTableAndMultilineArgAndParameter()
        {
            StepExecutionTestsBindingsForTableArgumentConvert bindingInstance;
            TestRunner testRunner = GetTestRunnerWithConverterStub(out bindingInstance);

            Table table = new Table("h1");
            string argumentValue = "argument";
            var user = new User();

            // return false unless its a User
            // must also stub CanConvert & Convert for the string argument as we've introduced a parameter
            StepArgumentTypeConverterStub.Stub(c => c.CanConvert(table, typeof(User), FeatureLanguage)).Return(true);
            StepArgumentTypeConverterStub.Stub(c => c.CanConvert(null, null, null)).IgnoreArguments().Return(false);
            StepArgumentTypeConverterStub.Stub(c => c.Convert(table, typeof(User), FeatureLanguage)).Return(user);

            var multiLineArg = "multi-line arg";
            bindingInstance.Expect(b => b.ParameterMultilineArgumentAndTable(argumentValue, multiLineArg, user));
            MockRepository.ReplayAll();

            testRunner.Given("sample step for argument convert with parameter, multiline argument and table: argument", multiLineArg, table);

            Assert.AreEqual(TestStatus.OK, GetLastTestStatus());
            MockRepository.VerifyAll();
        }
        public virtual void ParameterMultilineArgumentAndTable(string param, string multilineArg, User table)
        {

        }
        public virtual void MultilineArgumentAndTable(string multilineArg, User table)
        {

        }
        public virtual void SingleTable(User table)
        {

        }