Beispiel #1
0
        public void chooses_most_specific_adapter()
        {
            var specificRegionAdapterMock = new Mock<IRegionAdapter>();
            specificRegionAdapterMock
                .SetupGet(adapter => adapter.SupportedType)
                .Returns(typeof (FrameworkElement));
            specificRegionAdapterMock
                .Setup(adapter => adapter.AdaptView(_view))
                .Returns(_region);

            // no invocation expected
            var generalRegionAdapterMock = new Mock<IRegionAdapter>(MockBehavior.Strict);
            generalRegionAdapterMock
                .SetupGet(adapter => adapter.SupportedType)
                .Returns(typeof (DependencyObject));

            var regionFactory =
                new RegionFactory(new[]
                                      {
                                          generalRegionAdapterMock.Object,
                                          specificRegionAdapterMock.Object
                                      });
            var createdRegion = regionFactory.CreateRegion(_view);

            Assert.AreSame(_region, createdRegion);
        }
Beispiel #2
0
        public void chooses_an_adapter_supporting_supertype()
        {
            var generalRegionAdapterMock = new Mock<IRegionAdapter>();
            generalRegionAdapterMock
                .SetupGet(adapter => adapter.SupportedType)
                .Returns(typeof (DependencyObject));
            generalRegionAdapterMock
                .Setup(adapter => adapter.AdaptView(_view))
                .Returns(_region);

            var regionFactory = new RegionFactory(new[] {generalRegionAdapterMock.Object});
            var createdRegion = regionFactory.CreateRegion(_view);

            Assert.AreSame(_region, createdRegion);
        }
Beispiel #3
0
        public void when_matching_adapter_exists_a_region_is_created()
        {
            var regionAdapterMock = new Mock<IRegionAdapter>();
            regionAdapterMock
                .SetupGet(adapter => adapter.SupportedType)
                .Returns(typeof (FrameworkElement));
            regionAdapterMock
                .Setup(adapter => adapter.AdaptView(_view))
                .Returns(_region);

            var regionFactory = new RegionFactory(new[] {regionAdapterMock.Object});
            var createdRegion = regionFactory.CreateRegion(_view);

            Assert.AreSame(_region, createdRegion);
        }
Beispiel #4
0
        public void when_no_matching_adapter_is_found_an_exception_is_thrown()
        {
            var regionFactory = new RegionFactory(new IRegionAdapter[] {});

            Assert.Throws<InvalidOperationException>(() => regionFactory.CreateRegion(_view));
        }