Пример #1
0
        public void When_binding_an_object_to_aform_where_the_object_is_null()
        {
            var binder = new Binder();
            var form = new MySampleForm();

            Assert.Throws<ArgumentNullException>(() => binder.Bind((Post) null, form));
        }
Пример #2
0
        public void When_binding_an_object_to_aform()
        {
            var binder = new Binder();
            var form = new MySampleForm();
            var post = NeededObjectsFactory.CreatePost();

            binder.Bind(post, form);

            Assert.That(form.Title.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.Author.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.Date.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.Body.Text, Is.EqualTo(TestVariables.Body));
        }
Пример #3
0
        public void When_binding_an_object_to_aform_withaliases()
        {
            var binder = new Binder();
            var form = new MySampleForm();
            var aliases = new List<BindaAlias> {new BindaAlias("Location", "PostLocation")};
            var post = NeededObjectsFactory.CreatePost();

            binder.Bind(post, form, aliases);

            Assert.That(form.Title.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.Author.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.Date.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.Body.Text, Is.EqualTo(TestVariables.Body));
            Assert.That(form.PostLocation.Text,Is.EqualTo(TestVariables.Location));
        }
Пример #4
0
        public void When_binding_an_object_to_a_form_with_custom_control_registrations()
        {
            var binder = new Binder();
            var form = new MySampleForm();
            var strategy = new TestBindaStrategy();

            binder.AddRegistration(strategy, form.Title);
            binder.AddRegistration(typeof (TextBox), "Text");

            var post = NeededObjectsFactory.CreatePost();
            binder.Bind(post, form);

            Assert.IsTrue(strategy.WasSet);
        }
Пример #5
0
        public void When_binding_an_oject_to_aform_with_custom_registrations()
        {
            var binder = new Binder();
            binder.AddRegistration(typeof (FluxCapacitor), "PopularityRanking");
            var form = new MySampleForm();
            var post = NeededObjectsFactory.CreatePost();
            post.PopularityRanking = TestVariables.PopularityRanking;

            binder.Bind(post, form);

            Assert.That(form.Title.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.Author.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.Date.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.Body.Text, Is.EqualTo(TestVariables.Body));
            Assert.That(form.PopularityRanking.PopularityRanking, Is.EqualTo(TestVariables.PopularityRanking));
        }