예제 #1
0
        public static XafApplication NewApplication <TModule>(this Platform platform, bool transmitMessage = true, bool handleExceptions = true, bool usePersistentStorage = false)
            where TModule : ModuleBase
        {
            XafApplication application;

            if (platform == Platform.Web)
            {
                application = new TestWebApplication(typeof(TModule), transmitMessage);
            }
            else if (platform == Platform.Win)
            {
                application = new TestWinApplication(typeof(TModule), transmitMessage, handleExceptions);
            }
            else
            {
                throw new NotSupportedException(
                          "if implemented make sure all tests pass with TestExplorer and live testing");
            }

            application.Title            = TestContext.CurrentContext.Test.FullName;
            application.ConnectionString = usePersistentStorage?
                                           @$ "Integrated Security=SSPI;Pooling=false;Data Source=(localdb)\mssqllocaldb;Initial Catalog={typeof(TModule).Name}":InMemoryDataStoreProvider.ConnectionString;
            application.DatabaseUpdateMode     = DatabaseUpdateMode.UpdateDatabaseAlways;
            application.CheckCompatibilityType = CheckCompatibilityType.DatabaseSchema;
            application.ConfigureModel <TModule>(transmitMessage).SubscribeReplay();
            application.MockEditorsFactory();

            if (application is WebApplication webApplication)
            {
                var frameTemplateFactoryMock = new Mock <IFrameTemplateFactory>();
                var frameTemplateMock        = new Mock <System.Web.UI.Control>()
                {
                    CallBase = true
                }.As <IFrameTemplate>();
                frameTemplateMock.Setup(template => template.GetContainers()).Returns(new ActionContainerCollection());
                frameTemplateFactoryMock.Setup(factory => factory.CreateTemplate(It.IsAny <TemplateContext>())).Returns(
                    (TemplateContext context) => {
                    if (context == TemplateContext.NestedFrame)
                    {
                        return((IFrameTemplate)frameTemplateMock.As <ISupportActionsToolbarVisibility>().Object);
                    }

                    return(frameTemplateMock.Object);
                });
                webApplication.FrameTemplateFactory = frameTemplateFactoryMock.Object;
            }
            else
            {
                ((WinApplication)application).UseLightStyle = true;
            }

            return(application);
        }
예제 #2
0
        public static XafApplication NewApplication <TModule>(this Platform platform, bool transmitMessage = true, bool handleExceptions = true)
            where TModule : ModuleBase
        {
            XafApplication application;

            if (platform == Platform.Web)
            {
                application = new TestWebApplication(typeof(TModule), transmitMessage);
            }
            else if (platform == Platform.Win)
            {
                application = new TestWinApplication(typeof(TModule), transmitMessage, handleExceptions);
            }
            else
            {
                throw new NotSupportedException(
                          "if implemented make sure all tests pass with TestExplorer and live testing");
            }

            application.ConfigureModel <TModule>(transmitMessage).SubscribeReplay();
            application.MockEditorsFactory();

            if (application is WebApplication webApplication)
            {
                var frameTemplateFactoryMock = new Mock <IFrameTemplateFactory>();
                var frameTemplateMock        = new Mock <System.Web.UI.Control>()
                {
                    CallBase = true
                }.As <IFrameTemplate>();
                frameTemplateMock.Setup(template => template.GetContainers()).Returns(new ActionContainerCollection());
                frameTemplateFactoryMock.Setup(factory => factory.CreateTemplate(It.IsAny <TemplateContext>())).Returns(
                    (TemplateContext context) => {
                    if (context == TemplateContext.NestedFrame)
                    {
                        return((IFrameTemplate)frameTemplateMock.As <ISupportActionsToolbarVisibility>().Object);
                    }

                    return(frameTemplateMock.Object);
                });
                webApplication.FrameTemplateFactory = frameTemplateFactoryMock.Object;
            }
            else
            {
                ((WinApplication)application).UseLightStyle = true;
            }

            return(application);
        }