public void When_binding_an_object_to_a_form_with_a_property_and_a_collection_with_a_pluralized_name_of_the_property()
        {
            var binder = new Binder();
            var form   = new PostWithOptionsForm();
            var post   = NeededObjectsFactory.CreatePost();

            post.PublishStates.Add(new PublishState {
                State = "Published"
            });
            post.PublishStates.Add(new PublishState {
                State = "Reviewed"
            });
            post.PublishStates.Add(new PublishState {
                State = "Pending Review"
            });
            post.PublishStates.Add(new PublishState {
                State = "Draft"
            });
            post.PublishState = post.PublishStates[2];

            binder.Bind(post, form);

            Assert.That(form.PublishState.DataSource, Is.SameAs(post.PublishStates));
            Assert.That(form.PublishState.SelectedItem, Is.SameAs(post.PublishState));
        }
        public void When_binding_a_form_to_an_object_with_a_collection_and_item_bound_to_a_list_control()
        {
            var binder = new Binder();
            var form   = new PostWithOptionsForm();
            var post   = NeededObjectsFactory.CreatePost();

            post.PublishStates.Add(new PublishState {
                State = "Published"
            });
            post.PublishStates.Add(new PublishState {
                State = "Reviewed"
            });
            post.PublishStates.Add(new PublishState {
                State = "Pending Review"
            });
            post.PublishStates.Add(new PublishState {
                State = "Draft"
            });
            post.PublishState = post.PublishStates[2];
            binder.Bind(post, form);
            var newState = post.PublishStates[0];

            form.PublishState.SelectedItem = newState;

            binder.Bind(form, post);

            Assert.That(post.PublishState, Is.EqualTo(newState));
        }
        public void When_binding_a_form_to_a_tree_view()
        {
            var binder   = new Binder();
            var form     = new PostWithOptionsForm();
            var post     = NeededObjectsFactory.CreatePost();
            var comments = NeededObjectsFactory.GenerateComments();

            post.Comments.AddRange(comments);
            binder.Bind(post, form);
            post = new Post();

            binder.Bind(form, post);

            Assert.That(post.Comments.Count, Is.EqualTo(2));
            Assert.That(post.Comments.GetCommentByAuthor("Tom").Comments.Count, Is.EqualTo(1));
            Assert.That(post.Comments.GetCommentByAuthor("Tom").Comments[0].Comments.Count, Is.EqualTo(1));
            Assert.That(post.Comments.GetCommentByAuthor("Sam").Comments.Count, Is.EqualTo(1));
        }
        public void When_binding_a_tree_view_to_aform()
        {
            var binder   = new Binder();
            var form     = new PostWithOptionsForm();
            var post     = NeededObjectsFactory.CreatePost();
            var comments = NeededObjectsFactory.GenerateComments();

            post.Comments.AddRange(comments);

            binder.Bind(post, form);

            var allNodes = form.Comments.GetAllNodesRecursive();
            var tags     = allNodes.Select(x => x.Tag);

            CollectionAssert.AllItemsAreNotNull(tags);
            Assert.That(form.Comments.Nodes.Count, Is.EqualTo(2));
            Assert.That(allNodes.GetNodeCommentByAuthor("Tom").Nodes.Count, Is.EqualTo(1));
            Assert.That(allNodes.GetNodeCommentByAuthor("Tom").Nodes[0].Nodes.Count, Is.EqualTo(1));
            Assert.That(allNodes.GetNodeCommentByAuthor("Sam").Nodes.Count, Is.EqualTo(1));
        }
        public void When_binding_a_form_to_an_object_that_implements_inotifypropertychanged_and_the_form_data_changes()
        {
            var binder = new Binder();
            var form   = new PostWithOptionsForm();
            var post   = NeededObjectsFactory.CreateNotifyingPost();

            post.PublishStates.Add(new PublishState {
                State = "Published"
            });
            post.PublishStates.Add(new PublishState {
                State = "Reviewed"
            });
            post.PublishStates.Add(new PublishState {
                State = "Pending Review"
            });
            post.PublishStates.Add(new PublishState {
                State = "Draft"
            });
            post.PublishState = post.PublishStates[2];
            binder.Bind(post, form, new[] { new BindaAlias("Location", "PostLocation") });
            CreateControl(form);

            form.Title.Text                = "New Title";
            form.Author.Text               = "New Author";
            form.PostLocation.Text         = "New Location";
            form.Body.Text                 = "New Body";
            form.Date.Value                = new DateTime(1979, 12, 31);
            form.PublishState.SelectedItem = post.PublishStates[3];
            form.HitCount.Value            = (decimal)Math.Round(Math.PI, 12);

            Assert.That(post.Title, Is.EqualTo("New Title"));
            Assert.That(post.Author, Is.EqualTo("New Author"));
            Assert.That(post.Location, Is.EqualTo("New Location"));
            Assert.That(post.Body, Is.EqualTo("New Body"));
            Assert.That(post.Date, Is.EqualTo(new DateTime(1979, 12, 31)));
            Assert.That(post.PublishState, Is.EqualTo(post.PublishStates[3]));
            Assert.That(post.HitCount, Is.EqualTo((decimal)Math.Round(Math.PI, 12)));
        }