public void AccessorObtainsAValueFromTheRow()
        {
            DataBinding binding = new DataBinding(0, null);
            ScalarDataBinder binder = new ScalarDataBinder(binding, "name");

            IDataSourceResolver resolver = Mocks.StrictMock<IDataSourceResolver>();
            DataBindingContext context = new DataBindingContext(new NullConverter());

            DataSource source = new DataSource("name");
            source.AddDataSet(new ItemSequenceDataSet(new IDataItem[]
            {
                new ScalarDataItem<int>(42, null, false),
                new ScalarDataItem<string>("42", null, false)
            }, 1));

            using (Mocks.Record())
            {
                Expect.Call(resolver.ResolveDataSource("name")).Return(source);
            }

            using (Mocks.Playback())
            {
                IDataAccessor accessor = binder.Register(context, resolver);
                Assert.IsTrue(context.DataSets.Contains(source), "The data sets list should contain the source that was resolved during binder registration.");

                List<IDataItem> items = new List<IDataItem>(context.GetItems(true));
                Assert.Count(2, items);

                Assert.AreEqual(42, accessor.GetValue(items[0]));
                Assert.AreEqual("42", accessor.GetValue(items[1]));
            }
        }
        public void RegisterThrowsIfTheDataSourceCannotBeResolvedByName()
        {
            ScalarDataBinder binder = new ScalarDataBinder( new DataBinding(0, null), "name");

            IDataSourceResolver resolver = Mocks.StrictMock<IDataSourceResolver>();

            using (Mocks.Record())
            {
                Expect.Call(resolver.ResolveDataSource("name")).Return(null);
            }

            using (Mocks.Playback())
            {
                DataBindingContext context = new DataBindingContext(new NullConverter());
                Assert.Throws<DataBindingException>(delegate { binder.Register(context, resolver); });
            }
        }
 public void RegisterThrowsIfResolverIsNull()
 {
     ScalarDataBinder binder = new ScalarDataBinder(new DataBinding(0, null), "");
     binder.Register(new DataBindingContext(Mocks.Stub<IConverter>()), null);
 }
 public void RegisterThrowsIfContextIsNull()
 {
     ScalarDataBinder binder = new ScalarDataBinder(new DataBinding(0, null), "");
     binder.Register(null, Mocks.Stub<IDataSourceResolver>());
 }