Esempio n. 1
0
        public void DesignModeIsDetected()
        {
            var service =
                (ITypeDiscoveryService)PrivateInvoke.InvokeNonPublicStaticMethod(typeof(DeclarativeConfigurationBuilder), "GetTypeDiscoveryService");

            Assert.That(service, Is.InstanceOf(typeof(AssemblyFinderTypeDiscoveryService)));

            var repository           = new MockRepository();
            var designModeHelperMock = repository.StrictMock <IDesignModeHelper> ();
            var designerHostMock     = repository.StrictMock <IDesignerHost>();
            var designerServiceMock  = repository.StrictMock <ITypeDiscoveryService> ();

            designModeHelperMock.Expect(mock => mock.DesignerHost).Return(designerHostMock);
            designerHostMock.Expect(mock => mock.GetService(typeof(ITypeDiscoveryService))).Return(designerServiceMock);

            repository.ReplayAll();

            DesignerUtility.SetDesignMode(designModeHelperMock);
            try
            {
                service = (ITypeDiscoveryService)PrivateInvoke.InvokeNonPublicStaticMethod(typeof(DeclarativeConfigurationBuilder), "GetTypeDiscoveryService");

                Assert.That(service, Is.Not.InstanceOf(typeof(AssemblyFinderTypeDiscoveryService)));
                Assert.That(service, Is.SameAs(designerServiceMock));
            }
            finally
            {
                DesignerUtility.ClearDesignMode();
            }

            repository.VerifyAll();
        }
Esempio n. 2
0
        public override void SetUp()
        {
            base.SetUp();

            _dataSource = new BindableObjectDataSource();

            _mockRepository = new MockRepository();
            _stubSite       = _mockRepository.Stub <ISite>();
            SetupResult.For(_stubSite.DesignMode).Return(true);
            _dataSource.Site = _stubSite;

            _mockDesignerHost = _mockRepository.StrictMock <IDesignerHost>();
            SetupResult.For(_stubSite.GetService(typeof(IDesignerHost))).Return(_mockDesignerHost);

            var helperStub = _mockRepository.Stub <IDesignModeHelper> ();

            SetupResult.For(helperStub.DesignerHost).Return(_mockDesignerHost);

            _typeResolutionServiceMock = _mockRepository.StrictMock <ITypeResolutionService> ();
            SetupResult.For(_mockDesignerHost.GetService(typeof(ITypeResolutionService))).Return(_typeResolutionServiceMock);

            var typeDiscoveryServiceStub = _mockRepository.Stub <ITypeDiscoveryService> ();

            SetupResult.For(typeDiscoveryServiceStub.GetTypes(null, false)).IgnoreArguments().Return(Assembly.GetExecutingAssembly().GetTypes());
            SetupResult.For(_mockDesignerHost.GetService(typeof(ITypeDiscoveryService))).Return(typeDiscoveryServiceStub);

            // initialize IoC and mixin infrastructure to remove sideeffects in test.
            MixinTypeUtility.GetConcreteMixedType(typeof(SimpleBusinessObjectClass));

            DesignerUtility.SetDesignMode(helperStub);
        }
        public void GetTypeResolutionService_DesignModeContext()
        {
            var typeResolutionServiceStub = MockRepository.GenerateStub <ITypeResolutionService>();
            var designerHostMock          = MockRepository.GenerateStub <IDesignerHost>();

            designerHostMock.Expect(_ => _.GetService(typeof(ITypeResolutionService))).Return(typeResolutionServiceStub);

            DesignerUtility.SetDesignMode(new StubDesignModeHelper(designerHostMock));
            Assert.That(ContextAwareTypeUtility.GetTypeResolutionService(), Is.SameAs(typeResolutionServiceStub));

            designerHostMock.VerifyAllExpectations();
        }
        public override void Initialize(IComponent component)
        {
            ArgumentUtility.CheckNotNull("component", component);

            base.Initialize(component);
            SetViewFlags(ViewFlags.DesignTimeHtmlRequiresLoadComplete, true);

            Assertion.IsNotNull(component.Site, "The component does not have a Site.");
            IDesignerHost designerHost = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost));

            Assertion.IsNotNull(designerHost, "No IDesignerHost found.");

            if (!DesignerUtility.IsDesignMode || !object.ReferenceEquals(DesignerUtility.DesignModeHelper.DesignerHost, designerHost))
            {
                DesignerUtility.SetDesignMode(new WebDesginModeHelper(designerHost));
            }

            EnsureCheckForDuplicateAssemblies();
        }