Example #1
0
        public void Incremental_Update_NonSingleton_ModelNodes_PlusRandomModelNodes()
        {
            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomField();
                site.AddRandomField();
                site.AddRandomField();
            });

            var prevModel    = model;
            var currentModel = model;

            var firstProvisionService = new FakeIncrementalModelTreeTraverseService();

            firstProvisionService.PreviousModelHash = new ModelHash();
            firstProvisionService.Traverse(null, currentModel);

            RegressionUtils.WriteLine("Original model:");
            RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));

            var trace = ServiceContainer.Instance.GetService <TraceServiceBase>();

            ModelNode newField1 = null;
            ModelNode newField2 = null;

            // newnodes to add
            model.AddRandomField(f => { newField1 = f; });
            model.AddRandomField(f => { newField2 = f; });

            // check one more with second provision
            var secondProvisionService = new FakeIncrementalModelTreeTraverseService();

            secondProvisionService.PreviousModelHash = firstProvisionService.CurrentModelHash;
            secondProvisionService.Traverse(null, currentModel);

            RegressionUtils.WriteLine(string.Empty);
            RegressionUtils.WriteLine("Provisioned model:");
            RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));

            // asserts
            // should be 2 of the nodes to update on the same model
            Assert.AreEqual(2, secondProvisionService.ModelNodesToUpdate.Count);
            Assert.AreEqual(GetTotalModelNodeCount(model),
                            secondProvisionService.ModelNodesToSkip.Count + secondProvisionService.ModelNodesToUpdate.Count);

            // new field must be marked as to be updated
            Assert.IsTrue(newField1.Options.RequireSelfProcessing);
            Assert.IsTrue(newField2.Options.RequireSelfProcessing);

            RegressionUtils.WriteLine("Current model hash:");
            RegressionUtils.WriteLine(Environment.NewLine + secondProvisionService.CurrentModelHash);
        }
Example #2
0
        public void Internal_Incremental_Update_NonSingleton_ModelNodes_SameModels(ModelNode model)
        {
            var prevModel    = model;
            var currentModel = model;

            var firstProvisionService = new FakeIncrementalModelTreeTraverseService();

            firstProvisionService.PreviousModelHash = new ModelHash();
            firstProvisionService.Traverse(null, currentModel);

            var trace = ServiceContainer.Instance.GetService <TraceServiceBase>();

            // check one more with second provision
            var secondProvisionService = new FakeIncrementalModelTreeTraverseService();

            RegressionUtils.WriteLine("Original model:");
            RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));

            secondProvisionService.PreviousModelHash = firstProvisionService.CurrentModelHash;
            secondProvisionService.Traverse(null, currentModel);

            RegressionUtils.WriteLine(string.Empty);
            RegressionUtils.WriteLine("Provisioned model:");
            RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));

            // asserts
            // should be NONE of the nodes to update on the same model
            Assert.AreEqual(0, secondProvisionService.ModelNodesToUpdate.Count);
            Assert.AreEqual(GetTotalModelNodeCount(model), secondProvisionService.ModelNodesToSkip.Count);

            RegressionUtils.WriteLine("Current model hash:");
            RegressionUtils.WriteLine(Environment.NewLine + secondProvisionService.CurrentModelHash);

            foreach (var modelNodeHash in secondProvisionService.CurrentModelHash.ModelNodes)
            {
                RegressionUtils.WriteLine(string.Format("- {0}", modelNodeHash.ToString()));
            }
        }
Example #3
0
        public void Incremental_Update_AllDefinitions_As_RandomModels_Internal(
            Action <DefaultIncrementalModelTreeTraverseService> configureService,
            bool silentMode,
            int iterationCount)
        {
            var m2logService = ServiceContainer.Instance.GetService <TraceServiceBase>();

            var spMetaAssembly         = typeof(FieldDefinition).Assembly;
            var spMetaStandardAssembly = typeof(TaxonomyFieldDefinition).Assembly;

            var allDefinitionTypes = ReflectionUtils.GetTypesFromAssemblies <DefinitionBase>(new[]
            {
                spMetaAssembly,
                spMetaStandardAssembly
            }).OrderBy(t => t.Name);

            var allDefinitionTypesCount    = allDefinitionTypes.Count();
            var currentDefinitionTypeIndex = 0;

            for (int it = 0; it < iterationCount; it++)
            {
                foreach (var definitionType in allDefinitionTypes)
                {
                    currentDefinitionTypeIndex++;

                    if (!silentMode)
                    {
                        RegressionUtils.WriteLine(string.Format("[{0}/{1}] Testing definition:[{2}]",
                                                                new object[] {
                            currentDefinitionTypeIndex,
                            allDefinitionTypesCount,
                            definitionType.FullName
                        }));
                    }

                    var model = GetVeryRandomModel(definitionType, SPObjectModelType.CSOM);

                    var prevModel    = model;
                    var currentModel = model;

                    var firstProvisionService = new FakeIncrementalModelTreeTraverseService();

                    if (configureService != null)
                    {
                        configureService(firstProvisionService);
                    }

                    firstProvisionService.PreviousModelHash = new ModelHash();
                    firstProvisionService.Traverse(null, currentModel);

                    var trace = ServiceContainer.Instance.GetService <TraceServiceBase>();

                    // check one more with second provision
                    var secondProvisionService = new FakeIncrementalModelTreeTraverseService();

                    if (configureService != null)
                    {
                        configureService(secondProvisionService);
                    }

                    if (!silentMode)
                    {
                        RegressionUtils.WriteLine("Original model:");
                        RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));
                    }

                    secondProvisionService.PreviousModelHash = firstProvisionService.CurrentModelHash;
                    secondProvisionService.Traverse(null, currentModel);

                    // trace size of the model hash  + amount if the aritfacts
                    var modelNodesCount = 0;
                    model.WithNodesOfType <DefinitionBase>(n => { modelNodesCount++; });

                    var serializer = ServiceContainer.Instance.GetService <DefaultXMLSerializationService>();
                    serializer.RegisterKnownTypes(new[]
                    {
                        typeof(ModelHash),
                        typeof(ModelNodeHash)
                    });

                    var data = Encoding.UTF8.GetBytes(serializer.Serialize(firstProvisionService.CurrentModelHash));

                    var persistanceFileService = new DefaultFileSystemPersistenceStorage();
                    persistanceFileService.SaveObject(
                        string.Format("incremental_state_m2.regression-artifact-{1}-{0}", definitionType.Name, modelNodesCount),
                        data);

                    if (!silentMode)
                    {
                        RegressionUtils.WriteLine(string.Empty);
                        RegressionUtils.WriteLine("Provisioned model:");
                        RegressionUtils.WriteLine(ModelPrintService.PrintModel(currentModel));
                    }

                    // asserts
                    var expectedProvisionNodesCount = 0;

                    expectedProvisionNodesCount += secondProvisionService.GetTotalSingleIdentityNodeCount();
                    expectedProvisionNodesCount += secondProvisionService.GetTotalIgnoredNodeCount();

                    Assert.AreEqual(expectedProvisionNodesCount, secondProvisionService.ModelNodesToUpdate.Count);
                    Assert.AreEqual(GetTotalModelNodeCount(model) - expectedProvisionNodesCount, secondProvisionService.ModelNodesToSkip.Count);
                }
            }
        }