public async Task AdapterAssociatesSelectorWithRegionActiveViews()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ContentControl();
                    IRegionAdapter adapter = new TestableContentControlRegionAdapter();

                    MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                    Assert.IsNotNull(region);

                    Assert.IsNull(control.Content);
                    region.MockActiveViews.Items.Add(new object());

                    Assert.IsNotNull(control.Content);
                    Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

                    region.MockActiveViews.Items.Add(new object());
                    Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

                    region.MockActiveViews.Items.RemoveAt(0);
                    Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

                    region.MockActiveViews.Items.RemoveAt(0);
                    Assert.IsNull(control.Content);
                });
        }
        public void ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            var     control = new ContentControl();
            Binding binding = new Binding("ObjectContents");

            binding.Source = new SimpleModel()
            {
                ObjectContents = null
            };
            control.Bind(ContentControl.ContentProperty, binding);

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                Assert.IsTrue(true); // HACK: in ContentControlRegionAdapter.Adapt there is now way to determine
                                     // is ContentProperty already bound or not
                // Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
        public void CanRemoveViewWhenNoneActive()
        {
            var control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new object();
            region.Add(mockView1);
            region.Deactivate(mockView1);
            region.Remove(mockView1);
            Assert.AreEqual(0, region.ActiveViews.Count());
        }
        public async Task ControlWithExistingContentThrows()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ContentControl() { Content = new object() };

                    IRegionAdapter adapter = new TestableContentControlRegionAdapter();

                    Assert.ThrowsException<InvalidOperationException>(
                        () => (MockPresentationRegion)adapter.Initialize(control, "Region1"),
                        "ContentControl's Content property is not empty.");
                });
        }
        public void AddedItemShouldBeActivated()
        {
            var control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView = new object();
            region.Add(mockView);

            Assert.AreEqual(1, region.ActiveViews.Count());
            Assert.IsTrue(region.ActiveViews.Contains(mockView));
        }
        public void CanRemoveViewWhenNoneActive()
        {
            var            control = new ContentView();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new StackLayout();

            region.Add(mockView1);
            region.Deactivate(mockView1);
            region.Remove(mockView1);
            Assert.Empty(region.ActiveViews);
        }
        public void AddedItemShouldBeActivated()
        {
            var            control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockRegion region = (MockRegion)adapter.Initialize(control, "Region1");

            var mockView = new object();

            region.Add(mockView);

            Assert.AreEqual(1, region.ActiveViews.Count());
            Assert.IsTrue(region.ActiveViews.Contains(mockView));
        }
        public void CanRemoveViewWhenNoneActive()
        {
            var            control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockRegion region = (MockRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new object();

            region.Add(mockView1);
            region.Deactivate(mockView1);
            region.Remove(mockView1);
            Assert.AreEqual(0, region.ActiveViews.Count());
        }
        public void AddedItemShouldBeActivated()
        {
            var            control = new ContentView();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView = new StackLayout();

            region.Add(mockView);

            Assert.Single(region.ActiveViews);
            Assert.True(region.ActiveViews.Contains(mockView));
        }
        public void ShouldNotActivateAdditionalViewsAdded()
        {
            var            control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView = new object();

            region.Add(mockView);
            region.Add(new object());

            Assert.Single(region.ActiveViews);
            Assert.True(region.ActiveViews.Contains(mockView));
        }
        public void ControlWithExistingContentThrows()
        {
            var control = new ContentView()
            {
                Content = new StackLayout()
            };

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            IRegion region = null;
            var     ex     = Record.Exception(() => region = (MockPresentationRegion)adapter.Initialize(control, "Region1"));

            Assert.NotNull(ex);
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Contains("ContentView's Content property is not empty.", ex.Message);
        }
        public void ControlWithExistingContentThrows()
        {
            var control = new ContentControl() { Content = new object() };

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
        public void ShouldActivateAddedViewWhenNoneIsActive()
        {
            var            control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockRegion region = (MockRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new object();

            region.Add(mockView1);
            region.Deactivate(mockView1);

            var mockView2 = new object();

            region.Add(mockView2);

            Assert.AreEqual(1, region.ActiveViews.Count());
            Assert.IsTrue(region.ActiveViews.Contains(mockView2));
        }
        public void ShouldActivateAddedViewWhenNoneIsActive()
        {
            var            control = new ContentView();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new StackLayout();

            region.Add(mockView1);
            region.Deactivate(mockView1);

            var mockView2 = new Grid();

            region.Add(mockView2);

            Assert.Single(region.ActiveViews);
            Assert.True(region.ActiveViews.Contains(mockView2));
        }
        public void ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            var control = new ContentControl();
            Binding binding = new Binding("ObjectContents");
            binding.Source = new SimpleModel() { ObjectContents = null };
            control.SetBinding(ContentControl.ContentProperty, binding);

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
        public void ControlWithExistingContentThrows()
        {
            var control = new ContentControl()
            {
                Content = new object()
            };

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
        public void ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            var control = new ContentView();
            var binding = new Binding("ObjectContents")
            {
                Source = new SimpleModel()
                {
                    ObjectContents = null
                }
            };

            control.SetBinding(ContentView.ContentProperty, binding);

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();
            IRegion        region  = null;
            var            ex      = Record.Exception(() => region = (MockPresentationRegion)adapter.Initialize(control, "Region1"));

            Assert.IsType <InvalidOperationException>(ex);
            Assert.Contains("ContentView's Content property is not empty.", ex.Message);
        }
        public void ControlWithExistingContentThrows()
        {
            var control = new ContentControl()
            {
                Content = new object()
            };

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockPresentationRegion)adapter.Initialize(control, "Region1");
                //Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsType <InvalidOperationException>(ex);
                Assert.Contains("ContentControl's Content property is not empty.", ex.Message);
            }
        }
        public void AdapterAssociatesSelectorWithRegionActiveViews()
        {
            var control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockRegion region = (MockRegion)adapter.Initialize(control, "Region1");
            Assert.IsNotNull(region);

            Assert.IsNull(control.Content);
            region.MockActiveViews.Items.Add(new object());

            Assert.IsNotNull(control.Content);
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.Add(new object());
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.IsNull(control.Content);
        }
        public void AdapterAssociatesSelectorWithRegionActiveViews()
        {
            var            control = new ContentView();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            Assert.NotNull(region);

            Assert.Null(control.Content);
            region.MockActiveViews.Items.Add(new StackLayout());

            Assert.NotNull(control.Content);
            Assert.Same(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.Add(new Grid());
            Assert.Same(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.Same(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.Null(control.Content);
        }
        public void ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            var     control = new ContentControl();
            Binding binding = new Binding("ObjectContents");

            binding.Source = new SimpleModel()
            {
                ObjectContents = null
            };
            control.SetBinding(ContentControl.ContentProperty, binding);

            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            try
            {
                var region = (MockRegion)adapter.Initialize(control, "Region1");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ContentControl's Content property is not empty.");
            }
        }
        public void AdapterAssociatesSelectorWithRegionActiveViews()
        {
            var            control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockRegion region = (MockRegion)adapter.Initialize(control, "Region1");

            Assert.IsNotNull(region);

            Assert.IsNull(control.Content);
            region.MockActiveViews.Items.Add(new object());

            Assert.IsNotNull(control.Content);
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.Add(new object());
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.AreSame(control.Content, region.ActiveViews.ElementAt(0));

            region.MockActiveViews.Items.RemoveAt(0);
            Assert.IsNull(control.Content);
        }
        public async Task ShouldNotActivateAdditionalViewsAdded()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ContentControl();
                    IRegionAdapter adapter = new TestableContentControlRegionAdapter();

                    MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

                    var mockView = new object();
                    region.Add(mockView);
                    region.Add(new object());

                    Assert.AreEqual(1, region.ActiveViews.Count());
                    Assert.IsTrue(region.ActiveViews.Contains(mockView));
                });
        }
        public async Task ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ContentControl();
                    Binding binding = new Binding
                    {
                        Path = new PropertyPath("ObjectContents"),
                        Source = new SimpleModel() { ObjectContents = null }
                    };
                    control.SetBinding(ContentControl.ContentProperty, binding);

                    IRegionAdapter adapter = new TestableContentControlRegionAdapter();

                    Assert.ThrowsException<InvalidOperationException>(
                        () => (MockPresentationRegion)adapter.Initialize(control, "Region1"),
                        "ContentControl's Content property is not empty.");
                });
        }
        public void ShouldActivateAddedViewWhenNoneIsActive()
        {
            var control = new ContentControl();
            IRegionAdapter adapter = new TestableContentControlRegionAdapter();

            MockPresentationRegion region = (MockPresentationRegion)adapter.Initialize(control, "Region1");

            var mockView1 = new object();
            region.Add(mockView1);
            region.Deactivate(mockView1);

            var mockView2 = new object();
            region.Add(mockView2);

            Assert.AreEqual(1, region.ActiveViews.Count());
            Assert.IsTrue(region.ActiveViews.Contains(mockView2));
        }