Exemplo n.º 1
0
        public void ShouldUseStepArgumentTransformationToConvertTable()
        {
            ObjectContainer.ScenarioContext = new ScenarioContext(null);
            BindingRegistry bindingRegistry = new BindingRegistry();

            ObjectContainer.BindingRegistry = bindingRegistry;

            UserCreator stepTransformationInstance = new UserCreator();
            var         transformMethod            = stepTransformationInstance.GetType().GetMethod("CreateUsers");

            bindingRegistry.StepTransformations.Add(new StepTransformationBinding(@"", transformMethod));

            var stepArgumentTypeConverter = new StepArgumentTypeConverter();

            var table = new Table("Name");

            table.AddRow("Tom");
            table.AddRow("Dick");
            table.AddRow("Harry");

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

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf <IEnumerable <User> >());
            Assert.That(((IEnumerable <User>)result).Count(), Is.EqualTo(3));
        }
Exemplo n.º 2
0
        public void StepArgumentTypeConverterShouldUseUserConverterForConversion()
        {
            ObjectContainer.ScenarioContext = new ScenarioContext(null);
            BindingRegistry bindingRegistry = new BindingRegistry();

            ObjectContainer.BindingRegistry = bindingRegistry;

            UserCreator stepTransformationInstance = new UserCreator();
            var         transformMethod            = stepTransformationInstance.GetType().GetMethod("Create");

            bindingRegistry.StepTransformations.Add(new StepTransformationBinding(@"user (\w+)", transformMethod));

            var stepArgumentTypeConverter = new StepArgumentTypeConverter();

            var result = stepArgumentTypeConverter.Convert("user xyz", typeof(User), new CultureInfo("en-US"));

            Assert.That(result.GetType(), Is.EqualTo(typeof(User)));
            Assert.That(((User)result).Name, Is.EqualTo("xyz"));
        }