Inheritance: IRegionAdapter
        public async Task RegionWillNotGetCreatedTwiceWhenThereAreMoreRegions()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control1 = new MockFrameworkElement();
                    var control2 = new MockFrameworkElement();

                    var accessor = new MockRegionManagerAccessor
                                       {
                                           GetRegionName = d => d == control1 ? "Region1" : "Region2"
                                       };

                    var adapter = new MockRegionAdapter() { Accessor = accessor };

                    var behavior1 = DelayedRegionCreationBehaviorFixture.GetBehavior(control1, accessor, adapter);
                    var behavior2 = DelayedRegionCreationBehaviorFixture.GetBehavior(control2, accessor, adapter);

                    behavior1.Attach();
                    behavior2.Attach();

                    accessor.UpdateRegions();

                    Assert.IsTrue(adapter.CreatedRegions.Contains("Region1"));
                    Assert.IsTrue(adapter.CreatedRegions.Contains("Region2"));
                    Assert.AreEqual(1, adapter.CreatedRegions.Count((name) => name == "Region2"));
                });
        }
 private static DelayedRegionCreationBehavior GetBehavior(DependencyObject control, MockRegionManagerAccessor accessor, MockRegionAdapter adapter)
 {
     var mappings = new RegionAdapterMappings();
     mappings.RegisterMapping(control.GetType(), adapter);
     var behavior = new DelayedRegionCreationBehavior(mappings) { RegionManagerAccessor = accessor, TargetElement = control };
     return behavior;
 }
コード例 #3
0
        public void RegionWillNotGetCreatedTwiceWhenThereAreMoreRegions()
        {
            var control1 = new MockFrameworkElement();
            var control2 = new MockFrameworkElement();

            var accessor = new MockRegionManagerAccessor
                               {
                                   GetRegionName = d => d == control1 ? "Region1" : "Region2"
                               };

            var adapter = new MockRegionAdapter();
            adapter.Accessor = accessor;

            var behavior1 = this.GetBehavior(control1, accessor, adapter);
            var behavior2 = this.GetBehavior(control2, accessor, adapter);

            behavior1.Attach();
            behavior2.Attach();

            accessor.UpdateRegions();

            Assert.IsTrue(adapter.CreatedRegions.Contains("Region1"));
            Assert.IsTrue(adapter.CreatedRegions.Contains("Region2"));
            Assert.AreEqual(1, adapter.CreatedRegions.Count((name) => name == "Region2"));

        }
コード例 #4
0
        public void RegisterAMappingThatAlreadyExistsThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
        }
コード例 #5
0
        public void RegisterAMappingThatAlreadyExistsThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
            Assert.ThrowsException<InvalidOperationException>(() => regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter));
        }
コード例 #6
0
        public void ShouldGetMappingForDerivedTypesThanTheRegisteredOnes()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant));

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(regionAdapter, returnedAdapter);
        }
コード例 #7
0
        public void ShouldGetRegisteredMapping()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            Type registeredType = typeof(ItemsControl);
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(registeredType, regionAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(registeredType);

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(regionAdapter, returnedAdapter);
        }
コード例 #8
0
        public void ShouldGetTheMostSpecializedMapping()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var genericAdapter = new MockRegionAdapter();
            var specializedAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), genericAdapter);
            regionAdapterMappings.RegisterMapping(typeof(ItemsControlDescendant), specializedAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant));

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(specializedAdapter, returnedAdapter);
        }
コード例 #9
0
        public void NullControlThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(null, regionAdapter);
        }
コード例 #10
0
        public void NullControlThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            Assert.ThrowsException<ArgumentNullException>(() => regionAdapterMappings.RegisterMapping(null, regionAdapter));
        }