public void AdapterAssociatesOutlookBarControlWithRegion()
        {
            var control = new OutlookBarControl();
            IRegionAdapter adapter = new TestableOutlookBarControlRegionAdapter();

            IRegion region = adapter.Initialize(control);
            Assert.IsNotNull(region);

            Assert.AreSame(control.ItemsSource, region.Views);
        }
        public void ShouldMoveAlreadyExistingContentInControlToRegion()
        {
            var control = new OutlookBarControl();
            var view = new object();
            control.Items.Add(view);
            IRegionAdapter adapter = new TestableOutlookBarControlRegionAdapter();

            var region = (MockRegion)adapter.Initialize(control);

            Assert.AreEqual(1, region.MockViews.Count());
            Assert.AreSame(view, region.MockViews.ElementAt(0));
            Assert.AreSame(view, control.Items[0]);
        }
        public void ControlWithExistingItemSourceThrows()
        {
            var control = new OutlookBarControl() { ItemsSource = new List<string>() };

            IRegionAdapter adapter = new TestableOutlookBarControlRegionAdapter();

            try
            {
                var region = (MockRegion)adapter.Initialize(control);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ItemsControl's ItemsSource property is not empty.");
            }
        }
 public void IfControlIsNotOutlookBarControlThrows()
 {
     var control = new TabControl();
     IRegionAdapter adapter = new TestableOutlookBarControlRegionAdapter();
     adapter.Initialize(control);
 }
        public void ControlWithExistingBindingOnItemsSourceWithNullValueThrows()
        {
            var control = new OutlookBarControl();
            Binding binding = new Binding("Enumerable");
            binding.Source = new SimpleModel() { Enumerable = null };
            BindingOperations.SetBinding(control, ItemsControl.ItemsSourceProperty, binding);

            IRegionAdapter adapter = new TestableOutlookBarControlRegionAdapter();

            try
            {
                var region = (MockRegion)adapter.Initialize(control);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                StringAssert.Contains(ex.Message, "ItemsControl's ItemsSource property is not empty.");
            }
        }