Ejemplo n.º 1
1
        public void When_binding_a_form_to_an_object_where_the_object_is_null()
        {
            var binder = new Binder();
            var form = NeededObjectsFactory.CreateForm();

            Assert.Throws<ArgumentNullException>(() => binder.Bind(form, (Post)null));
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        public void When_binding_an_object_to_aform_where_theform_is_null()
        {
            var binder = new Binder();
            var post = NeededObjectsFactory.CreatePost();

            Assert.Throws<ArgumentNullException>(() => binder.Bind(post, (MySampleForm)null));
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public void When_binding_an_object_to_a_form_with_a_property_and_a_collection_with_a_pluralized_name_of_the_property_using_prefixes_aliases_and_with_custom_registrations()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());
            binder.AddRegistration(typeof(FluxCapacitor), "PopularityRanking");
            var aliases = new List<BindaAlias> { new BindaAlias("Location", "PostLocation") };
            var form = new PostWithOptionsPrefixForm();
            var post = NeededObjectsFactory.CreatePost();
            post.PopularityRanking = TestVariables.PopularityRanking;
            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, aliases);

            Assert.That(form.cbPublishState.DataSource, Is.SameAs(post.PublishStates));
            Assert.That(form.cbPublishState.SelectedItem, Is.SameAs(post.PublishState));
            Assert.That(form.txtTitle.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.txtAuthor.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.dpDate.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.txtBody.Text, Is.EqualTo(TestVariables.Body));
            Assert.That(form.txtPostLocation.Text, Is.EqualTo(TestVariables.Location));
            Assert.That(form.fcPopularityRanking.PopularityRanking, Is.EqualTo(TestVariables.PopularityRanking));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        public void When_binding_a_form_to_an_object()
        {
            var binder = new Binder();
            var form = NeededObjectsFactory.CreateForm();
            var post = new Post();

            binder.Bind(form, post);

            Assert.That(post.Title, Is.EqualTo(TestVariables.Title));
            Assert.That(post.Author, Is.EqualTo(TestVariables.Author));
            Assert.That(post.Date, Is.EqualTo(TestVariables.Posted));
            Assert.That(post.Body, Is.EqualTo(TestVariables.Body));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public void When_binding_an_object_to_aform_using_prefixes_withaliases()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());
            var form = new MySamplePrefixForm();
            var aliases = new List<BindaAlias> {new BindaAlias("Location", "PostLocation")};
            var post = NeededObjectsFactory.CreatePost();

            binder.Bind(post, form, aliases);

            Assert.That(form.txtTitle.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.txtAuthor.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.dpDate.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.txtBody.Text, Is.EqualTo(TestVariables.Body));
            Assert.That(form.txtPostLocation.Text, Is.EqualTo(TestVariables.Location));
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        public void When_binding_a_form_to_an_object_with_aliases()
        {
            var binder = new Binder();
            var aliases = new List<BindaAlias> { new BindaAlias("Location", "PostLocation") };
            var form = NeededObjectsFactory.CreateForm();
            form.PostLocation.Text = TestVariables.Location;
            var post = new Post();

            binder.Bind(form, post, aliases);

            Assert.That(post.Title, Is.EqualTo(TestVariables.Title));
            Assert.That(post.Author, Is.EqualTo(TestVariables.Author));
            Assert.That(post.Date, Is.EqualTo(TestVariables.Posted));
            Assert.That(post.Body, Is.EqualTo(TestVariables.Body));
            Assert.That(post.Location, Is.EqualTo(TestVariables.Location));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        public void When_binding_a_prefix_form_to_an_object()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());
            var form = NeededObjectsFactory.CreatePrefixForm();
            var post = new Post();

            binder.Bind(form, post);

            Assert.That(post.Title, Is.EqualTo(TestVariables.Title));
            Assert.That(post.Author, Is.EqualTo(TestVariables.Author));
            Assert.That(post.Date, Is.EqualTo(TestVariables.Posted));
            Assert.That(post.Body, Is.EqualTo(TestVariables.Body));
        }
Ejemplo n.º 14
0
        public void When_binding_a_prefix_form_to_an_object_with_custom_registrations()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());
            binder.AddRegistration(typeof(FluxCapacitor), "PopularityRanking");
            var form = NeededObjectsFactory.CreatePrefixForm();
            form.fcPopularityRanking.PopularityRanking = TestVariables.PopularityRanking;
            var post = new Post();

            binder.Bind(form, post);

            Assert.That(post.Title, Is.EqualTo(TestVariables.Title));
            Assert.That(post.Author, Is.EqualTo(TestVariables.Author));
            Assert.That(post.Date, Is.EqualTo(TestVariables.Posted));
            Assert.That(post.Body, Is.EqualTo(TestVariables.Body));
            Assert.That(post.PopularityRanking, Is.EqualTo(TestVariables.PopularityRanking));
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        public void When_binding_a_form_to_an_object_with_custom_control_registrations()
        {
            var binder = new Binder();
            var form = NeededObjectsFactory.CreateForm();
            var strategy = new TestBindaStrategy();

            binder.AddRegistration(strategy, form.Title);
            strategy.GetValue = "Good Title";

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

            var post = new Post();
            binder.Bind(form, post);

            Assert.That(post.Title, Is.EqualTo(strategy.GetValue));
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public void When_binding_an_object_to_a_form_with_a_property_and_a_key_value_pair_collection()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());

            var post = NeededObjectsFactory.CreatePost();
            post.Categories.Add(new KeyValuePair<int, string>(123, "Toast"));
            post.Categories.Add(new KeyValuePair<int, string>(8915, "Waffles"));
            post.Categories.Add(new KeyValuePair<int, string>(56123, "Pizza"));
            post.Category = 56123;

            var form = new PostWithOptionsPrefixForm();
            binder.AddRegistration(new KeyValueListStrategy(), form.cboCategory);
            binder.Bind(post, form);

            Assert.That(form.cboCategory.DataSource, Is.SameAs(post.Categories));
            Assert.That(form.cboCategory.SelectedValue, Is.EqualTo(post.Category));
        }
Ejemplo n.º 19
0
        public void When_binding_an_oject_to_aform_using_prefixesaliases_and_custom_registrations()
        {
            var binder = new Binder();
            binder.AddControlPrefix(new HungarianNotationControlPrefix());
            binder.AddRegistration(typeof (FluxCapacitor), "PopularityRanking");
            var aliases = new List<BindaAlias> {new BindaAlias("Location", "PostLocation")};
            var form = new MySamplePrefixForm();
            var post = NeededObjectsFactory.CreatePost();
            post.PopularityRanking = TestVariables.PopularityRanking;

            binder.Bind(post, form, aliases);

            Assert.That(form.txtTitle.Text, Is.EqualTo(TestVariables.Title));
            Assert.That(form.txtAuthor.Text, Is.EqualTo(TestVariables.Author));
            Assert.That(form.dpDate.Value, Is.EqualTo(TestVariables.Posted));
            Assert.That(form.txtBody.Text, Is.EqualTo(TestVariables.Body));
            Assert.That(form.txtPostLocation.Text, Is.EqualTo(TestVariables.Location));
            Assert.That(form.fcPopularityRanking.PopularityRanking, Is.EqualTo(TestVariables.PopularityRanking));
        }
Ejemplo n.º 20
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));
        }
Ejemplo n.º 21
0
        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));
        }