예제 #1
0
        public RegressionTestService()
        {
            ModelGeneratorService = new ModelGeneratorService();
            //Assert = new AssertService();

            RndService = new DefaultRandomService();

            //RegressionService = new RegressionTestService();

            //ModelGeneratorService.RegisterDefinitionGenerators(typeof(WebNavigationSettingsDefinitionGenerator).Assembly);

            ProvisionRunnerAssemblies = new List <string>();
            ProvisionRunners          = new List <ProvisionRunnerBase>();

            EnablePropertyValidation = true;
            EnableEventValidation    = true;

            InitConfig();
        }
        public ModelNode TestRandomDefinition <TDefinition>(Action <TDefinition> definitionSetup)
            where TDefinition : DefinitionBase, new()
        {
            _hookMap.Clear();

            ModelNode result = null;

            var allHooks = new List <EventHooks>();

            WithProvisionRunnerContext(runnerContext =>
            {
                var runner = runnerContext.Runner;

                ValidateDefinitionHostRunnerSupport <TDefinition>(runner);

                var omModelType = GetRunnerType(runner);

                var definitionSandbox     = ModelGeneratorService.GenerateModelTreeForDefinition <TDefinition>(omModelType);
                var additionalDefinitions = ModelGeneratorService.GetAdditionalDefinition <TDefinition>();

                ModelGeneratorService.ComposeModelWithAdditionalDefinitions(definitionSandbox, additionalDefinitions, omModelType);

                if (definitionSetup != null)
                {
                    foreach (var def in ModelGeneratorService.CurrentDefinitions)
                    {
                        definitionSetup(def as TDefinition);
                    }
                }

                var hooks = GetHooks(definitionSandbox);

                foreach (var hook in hooks)
                {
                    hook.Tag = runner.Name;
                }

                GetSerializedAndRestoredModels(definitionSandbox);

                allHooks.AddRange(hooks);

                if (definitionSandbox.Value.GetType() == typeof(FarmDefinition))
                {
                    runner.DeployFarmModel(definitionSandbox);
                }

                if (definitionSandbox.Value.GetType() == typeof(WebApplicationDefinition))
                {
                    runner.DeployWebApplicationModel(definitionSandbox);
                }

                if (definitionSandbox.Value.GetType() == typeof(SiteDefinition))
                {
                    runner.DeploySiteModel(definitionSandbox);
                }

                if (definitionSandbox.Value.GetType() == typeof(WebDefinition))
                {
                    runner.DeployWebModel(definitionSandbox);
                }

                if (this.EnableDefinitionValidation)
                {
                    var hasMissedOrInvalidProps = ResolveModelValidation(definitionSandbox, hooks);
                    AssertService.IsFalse(hasMissedOrInvalidProps);
                }

                result = definitionSandbox;
            });

            return(result);
        }