Beispiel #1
0
        protected bool ShouldPass(string message, object context, string token, string expectedUrl)
        {
            var result = true;

            RegressionUtils.WriteLine(message);

            var valueResult = Service.ReplaceTokens(new TokenReplacementContext
            {
                Value   = token,
                Context = context
            });

            result = expectedUrl.ToUpper() == valueResult.Value.ToUpper();

            RegressionUtils.WriteLine(string.Format("[{0}] - [{1}] - token:[{2}] expected value:[{3}] replaced value:[{4}]",
                                                    new object[]
            {
                message,
                result,
                token,
                expectedUrl,
                valueResult.Value
            }));

            return(result);
        }
Beispiel #2
0
        public void FieldDefinitions_ShouldHave_Correct_ValidationMessageAndFormula_Property()
        {
            var fieldDefinitionTypes = new List <Type>();

            fieldDefinitionTypes.AddRange(ReflectionUtils.GetTypesFromAssembly <FieldDefinition>(typeof(FieldDefinition).Assembly));
            fieldDefinitionTypes.AddRange(ReflectionUtils.GetTypesFromAssembly <FieldDefinition>(typeof(TaxonomyFieldDefinition).Assembly));

            foreach (var fieldDefintion in fieldDefinitionTypes)
            {
                RegressionUtils.WriteLine(string.Format("Checking Indexed propr for Indexed def:[{0}]", fieldDefintion.GetType().Name));

                var siteModel = SPMeta2Model.NewSiteModel(m => { });
                var siteField = ModelGeneratorService.GetRandomDefinition(fieldDefintion) as FieldDefinition;

                siteModel.AddField(siteField);

                // dep lookiup
                if (siteField is DependentLookupFieldDefinition)
                {
                    var primaryLookupField = new LookupFieldDefinitionGenerator().GenerateRandomDefinition() as FieldDefinition;

                    (siteField as DependentLookupFieldDefinition).PrimaryLookupFieldId = primaryLookupField.Id;
                    siteModel.AddField(primaryLookupField);
                }

                siteField.ValidationMessage = string.Format("validatin_msg_{0}", RegressionService.RndService.String());
                siteField.ValidationFormula = string.Format("=[ID] * {0}", RegressionService.RndService.Int(100));

                TestModel(siteModel);
            }
        }
        public void RandomDefinitionTest_ShouldHave_Tests_ForAllDefinitions()
        {
            var methods = typeof(RandomDefinitionTest).GetMethods();

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

            var allDefinitions = ReflectionUtils.GetTypesFromAssemblies <DefinitionBase>(new[]
            {
                spMetaAssembly,
                spMetaStandardAssembly
            });

            foreach (var def in allDefinitions)
            {
                RegressionUtils.WriteLine(def.Name);
            }

            var isValid = true;

            foreach (var definition in allDefinitions)
            {
                var hasTestMethod = HasTestMethod("CanDeployRandom_", definition, methods);

                if (!hasTestMethod)
                {
                    RegressionUtils.WriteLine(string.Format("[ERR]:{0}", definition.Name));

                    isValid = false;
                }
            }

            Assert.IsTrue(isValid);
        }
        public void All_Services_Should_Have_Metadata()
        {
            var isValid = true;

            var validationServiceTypes =
                ReflectionUtils.GetTypesFromAssembly <PreDeploymentValidationServiceBase>(
                    typeof(FieldDefinition).Assembly);


            foreach (var validationServiceType in validationServiceTypes)
            {
                var service = Activator.CreateInstance(validationServiceType) as PreDeploymentValidationServiceBase;

                RegressionUtils.WriteLine(service.Title);
                RegressionUtils.WriteLine(service.Description);

                Assert.IsNotNull(service);

                if (string.IsNullOrEmpty(service.Title))
                {
                    isValid = false;
                    break;
                }

                if (string.IsNullOrEmpty(service.Description))
                {
                    isValid = false;
                    break;
                }
            }

            Assert.IsTrue(isValid);
        }
        private bool HasTestMethod(string methodPrefix, Type definition, MethodInfo[] methods)
        {
            var methodName = string.Format("{0}{1}", methodPrefix, definition.Name);

            RegressionUtils.WriteLine(string.Format("Asserting method:[{0}]", methodName));

            var targetMethod = methods.FirstOrDefault(m => m.Name == methodName);

            return(targetMethod != null);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void Create_BuildBaseline()
        {
            var assemblies = new List <Assembly>();

            // SPMeta2
            // SPMeta2.Standard
            assemblies.Add(typeof(FieldDefinition).Assembly);
            assemblies.Add(typeof(TaxonomyFieldDefinition).Assembly);

            // SPMeta2.CSOM
            // SPMeta2.CSOM.Standard
            assemblies.Add(typeof(SPMeta2.CSOM.ModelHandlers.FieldModelHandler).Assembly);
            assemblies.Add(typeof(SPMeta2.CSOM.Standard.ModelHandlers.Fields.TaxonomyFieldModelHandler).Assembly);

            // SPMeta2.SSOM
            // SPMeta2.SSOM.Standard
            assemblies.Add(typeof(SPMeta2.SSOM.ModelHandlers.FieldModelHandler).Assembly);
            assemblies.Add(typeof(SPMeta2.SSOM.Standard.ModelHandlers.Fields.TaxonomyFieldModelHandler).Assembly);

            var result = new List <BuildBaseline>();

            foreach (var assembly in assemblies)
            {
                result.Add(BuildBaselineFromAssembly(assembly));
            }

            var fileName = "m2.buildbaseline.xml";

            var xmlService = new DefaultXMLSerializationService();

            xmlService.RegisterKnownType(typeof(BuildBaseline));

            var content = xmlService.Serialize(result);

            RegressionUtils.WriteLine(content);

            var paths = new[]
            {
                System.IO.Path.GetFullPath(fileName),
                System.IO.Path.GetFullPath("../../../SPMeta2.Build/" + fileName)
            };

            foreach (var path in paths)
            {
                var dirPath = Path.GetDirectoryName(path);
                Directory.CreateDirectory(dirPath);

                System.IO.File.WriteAllText(path, content);
            }
        }
Beispiel #8
0
        public void SelfDiagnostic_AllFields_Should_Have_Value_Tests()
        {
            var isValid = true;

            var methods     = typeof(ListItemScenariousTest).GetMethods();
            var targetTypes = new List <Type>();

            var assemblies = new[]
            {
                typeof(FieldDefinition).Assembly,
                typeof(TaxonomyFieldDefinition).Assembly
            };

            targetTypes.AddRange(ReflectionUtils.GetTypesFromAssemblies <FieldDefinition>(assemblies));

            RegressionUtils.WriteLine(string.Format("Found [{0}] fied types.", targetTypes.Count));

            foreach (var fieldType in targetTypes.OrderBy(m => m.Name))
            {
                var fullDefName  = fieldType.Name;
                var shortDefName = fieldType.Name.Replace("Definition", string.Empty);

                var testName1 = string.Format("CanDeploy_{0}_Value", shortDefName);
                var testName2 = string.Format("CanDeploy_{0}_Values", shortDefName);

                var testExists1 = methods.Any(m => m.Name == testName1);
                var testExists2 = methods.Any(m => m.Name == testName2);


                if (!testExists1)
                {
                    isValid = false;
                }

                if (!testExists2)
                {
                    isValid = false;
                }

                RegressionUtils.WriteLine(string.Format("[{0}] def: {1} one value test method: {2}",
                                                        testExists1, fullDefName, testName1));

                RegressionUtils.WriteLine(string.Format("[{0}] def: {1} multiple values test method: {2}",
                                                        testExists2, fullDefName, testName2));

                RegressionUtils.WriteLine(string.Empty);
            }

            Assert.IsTrue(isValid);
        }
Beispiel #9
0
        private void AddAndCheckRandomAppWithVersion(WebModelNode web, Version version)
        {
            var def = new AppDefinition();

            def.ProductId = DefaultContainers.Apps.ProductId;
            def.Version   = version.ToString();

            def.Content = File.ReadAllBytes(string.Format(DefaultContainers.Apps.GenericVersionableAppFilePath, version));

            web.AddApp(def, app =>
            {
                app.OnProvisioned <object, AppDefinition>(context =>
                {
                    RegressionUtils.WriteLine(context.ObjectDefinition.ToString());
                    RegressionUtils.WriteLine(context.Object.ToString());

                    var expectedAppVersion = new Version(context.ObjectDefinition.Version);

                    var obj     = context.Object;
                    var objType = context.Object.GetType();

                    if (objType.ToString().Contains("Microsoft.SharePoint.Client.AppInstance"))
                    {
                        // with CSOM there is no API to know current app installed version
                        // checking if app is Installed after every single update
                        var appStatus = obj.GetPropertyValue("Status").ToString();

                        Assert.IsTrue(appStatus == "Installed",
                                      string.Format("App should be installed after every update"));
                    }
                    else if (objType.ToString().Contains("Microsoft.SharePoint.Administration.SPAppInstance"))
                    {
                        var appObjet = obj.GetPropertyValue("App");

                        var versionString = appObjet.GetPropertyValue("VersionString") as string;
                        var spAppVersion  = new Version(versionString);

                        // either equal (update) or SharePoint version greater than local (second update)
                        // the test is run several times, so only once we have =, and then we have <
                        Assert.IsTrue(expectedAppVersion <= spAppVersion,
                                      string.Format("Expecting app version:[{0}] SharePoint app version:[{1}]", expectedAppVersion, spAppVersion));
                    }
                    else
                    {
                        throw new SPMeta2NotImplementedException(string.Format("ID property extraction is not implemented for type: [{0}]", objType));
                    }
                });
            });
        }
Beispiel #10
0
        public void FieldDefinitions_ShouldHave_Correct_Indexed_Property()
        {
            var fieldDefinitionTypes = new List <Type>();

            fieldDefinitionTypes.AddRange(ReflectionUtils.GetTypesFromAssembly <FieldDefinition>(typeof(FieldDefinition).Assembly));
            fieldDefinitionTypes.AddRange(ReflectionUtils.GetTypesFromAssembly <FieldDefinition>(typeof(TaxonomyFieldDefinition).Assembly));

            foreach (var fieldDefintion in fieldDefinitionTypes)
            {
                RegressionUtils.WriteLine(string.Format("Checking Indexed prop for Indexed def:[{0}]", fieldDefintion.GetType().Name));

                var indexedSiteModel = SPMeta2Model.NewSiteModel(m => { });
                var indexedSiteField = ModelGeneratorService.GetRandomDefinition(fieldDefintion) as FieldDefinition;

                indexedSiteModel.AddField(indexedSiteField);
                indexedSiteField.Indexed = true;

                // dep lookiup
                if (indexedSiteField is DependentLookupFieldDefinition)
                {
                    var primaryLookupField = new LookupFieldDefinitionGenerator().GenerateRandomDefinition() as FieldDefinition;

                    (indexedSiteField as DependentLookupFieldDefinition).PrimaryLookupFieldId = primaryLookupField.Id;
                    indexedSiteModel.AddField(primaryLookupField);
                }

                TestModel(indexedSiteModel);

                RegressionUtils.WriteLine(string.Format("Checking Indexed prop for non-Indexed def:[{0}]", fieldDefintion.GetType().Name));

                var nonIdexedSiteModel  = SPMeta2Model.NewSiteModel(m => { });
                var nonIndexedSiteField = ModelGeneratorService.GetRandomDefinition(fieldDefintion) as FieldDefinition;

                nonIdexedSiteModel.AddField(nonIndexedSiteField);
                nonIndexedSiteField.Indexed = false;

                // dep lookiup
                if (indexedSiteField is DependentLookupFieldDefinition)
                {
                    var primaryLookupField = new LookupFieldDefinitionGenerator().GenerateRandomDefinition() as FieldDefinition;

                    (nonIndexedSiteField as DependentLookupFieldDefinition).PrimaryLookupFieldId = primaryLookupField.Id;
                    nonIdexedSiteModel.AddField(primaryLookupField);
                }

                TestModel(nonIdexedSiteModel);
            }
        }
        public SPMeta2RegresionScenarioTestBase()
        {
            RegressionService.ProvisionGenerationCount = 2;
            RegressionService.ShowOnlyFalseResults     = true;

            var isIncrementalProvisionEnabled = IsIncrementalProvisionMode;

            if (isIncrementalProvisionEnabled)
            {
                RegressionService.BeforeProvisionRunnerExcecution += (runner) =>
                {
                    var config = new IncrementalProvisionConfig();
                    runner.ProvisionService.SetIncrementalProvisionMode(config);

                    runner.OnBeforeDeployModel += (provisionService, model) =>
                    {
                        if (PreviousModelHash != null)
                        {
                            provisionService.SetIncrementalProvisionModelHash(PreviousModelHash);
                        }
                    };

                    runner.OnAfterDeployModel += (provisionService, model) =>
                    {
                        var tracer = new DefaultIncrementalModelPrettyPrintService();

                        RegressionUtils.WriteLine(string.Format("Deployed model with incremental updates:"));
                        RegressionUtils.WriteLine(Environment.NewLine + tracer.PrintModel(model));

                        PreviousModelHash = provisionService.GetIncrementalProvisionModelHash();
                    };
                };

                RegressionService.AfterProvisionRunnerExcecution += (runner) =>
                {
                };

                RegressionService.EnableEventValidation      = false;
                RegressionService.EnableDefinitionValidation = false;
                RegressionService.EnablePropertyValidation   = false;

                EnablePropertyUpdateValidation = true;
            }
        }
Beispiel #12
0
        public void SelfDiagnostic_AllFields_Should_Have_DefaultValue_Tests()
        {
            // check if FieldScenariosTest class has all testsfor field default values
            // should not inherit SPMeta2RegresionScenarioTestBase as it will force to use (init) provisioners under CI
            // that's why it is separated

            var isValid = true;

            var methods     = typeof(FieldScenariosTest).GetMethods();
            var targetTypes = new List <Type>();

            var assemblies = new[]
            {
                typeof(FieldDefinition).Assembly,
                typeof(TaxonomyFieldDefinition).Assembly
            };

            targetTypes.AddRange(ReflectionUtils.GetTypesFromAssemblies <FieldDefinition>(assemblies));

            RegressionUtils.WriteLine(string.Format("Found [{0}] fied types.", targetTypes.Count));

            foreach (var fieldType in targetTypes.OrderBy(m => m.Name))
            {
                var fullDefName  = fieldType.Name;
                var shortDefName = fieldType.Name.Replace("Definition", string.Empty);

                var testName = string.Format("CanDeploy_{0}_DefaultValue", shortDefName);

                var testExists = methods.Any(m => m.Name == testName);

                if (!testExists)
                {
                    isValid = false;
                }

                RegressionUtils.WriteLine(string.Format("[{0}] def: {1} test method: {2}",
                                                        testExists, fullDefName, testName));
            }

            Assert.IsTrue(isValid);
        }
Beispiel #13
0
        public void CanGetHashForAllDefinitions()
        {
            var service = new MD5HashCodeServiceBase();


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

            var allDefinitions = ReflectionUtils.GetTypesFromAssemblies <DefinitionBase>(new[]
            {
                spMetaAssembly,
                spMetaStandardAssembly
            });

            var hashes = new Dictionary <string, string>();

            RegressionUtils.WriteLine("Checking hashes for definitions...");

            foreach (var defType in allDefinitions)
            {
                var defInstance = ModelGeneratorService.GetRandomDefinition(defType);
                RegressionUtils.WriteLine(string.Format("Definition:[{0}] - [{1}]", defType, defInstance));

                IndentableTrace.WithScope(trace =>
                {
                    var hash1 = service.GetHashCode(defInstance);
                    var hash2 = service.GetHashCode(defInstance);

                    trace.WriteLine(string.Format("HASH1:[{0}]", hash1));
                    trace.WriteLine(string.Format("HASH1:[{0}]", hash2));

                    // just curious, would it ever blow up on duplicate?
                    hashes.Add(hash1, hash1);

                    Assert.IsNotNull(hash1);
                    Assert.IsNotNull(hash2);

                    Assert.IsTrue(hash1 == hash2);
                });
            }
        }
Beispiel #14
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()));
            }
        }
Beispiel #15
0
        private BuildBaseline BuildBaselineFromAssembly(Assembly assembly)
        {
            var result = new BuildBaseline();

            result.AssemblyFullName = assembly.FullName;
            result.AssemblyFileName = assembly.ManifestModule.Name;

            result.DefinitionTypeFullNames = ReflectionUtils.GetTypesFromAssembly <DefinitionBase>(assembly)
                                             .Where(t => !t.IsAbstract)
                                             .Select(t => t.AssemblyQualifiedName)
                                             .ToList();

            result.ModelHandlerTypeFullNames = ReflectionUtils.GetTypesFromAssembly <ModelHandlerBase>(assembly)
                                               .Where(t => !t.IsAbstract)
                                               .Select(t => t.AssemblyQualifiedName)
                                               .ToList();

            RegressionUtils.WriteLine(string.Format("AssemblyFullName:[{0}]", result.AssemblyFullName));
            RegressionUtils.WriteLine(string.Format("DefinitionTypeFullNames:[{0}]", result.DefinitionTypeFullNames.Count));
            RegressionUtils.WriteLine(string.Format("ModelHandlerTypeFullNames:[{0}]", result.ModelHandlerTypeFullNames.Count));

            RegressionUtils.WriteLine("Definitions:");
            foreach (var name in result.DefinitionTypeFullNames)
            {
                RegressionUtils.WriteLine(" " + name);
            }

            RegressionUtils.WriteLine("Model handlers:");
            foreach (var name in result.ModelHandlerTypeFullNames)
            {
                RegressionUtils.WriteLine(" " + name);
            }

            RegressionUtils.WriteLine(string.Empty);
            RegressionUtils.WriteLine(string.Empty);

            return(result);
        }
Beispiel #16
0
        public void ShouldFail_On_Invalid_Field_Twice()
        {
            var isValid             = false;
            var innerExceptionCount = 0;

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomField(field =>
                {
                    (field.Value as FieldDefinition).InternalName = string.Empty;
                    (field.Value as FieldDefinition).Id           = default(Guid);
                });
            });

            try
            {
                Service.DeployModel(null, model);
            }
            catch (Exception e)
            {
                isValid = e is SPMeta2ModelDeploymentException &&
                          e.InnerException is SPMeta2AggregateException &&
                          (e.InnerException as AggregateException)
                          .InnerExceptions.All(ie => ie is SPMeta2ModelValidationException);

                innerExceptionCount = (e.InnerException as AggregateException)
                                      .InnerExceptions.Count;

                foreach (var ex in (e.InnerException as AggregateException).InnerExceptions
                         .OfType <SPMeta2ModelValidationException>())
                {
                    RegressionUtils.WriteLine("Ex: " + ex.Message + " N:" + ex.Definition);
                }
            }

            Assert.IsTrue(isValid);
            Assert.AreEqual(2, innerExceptionCount);
        }
Beispiel #17
0
        protected bool HasAllTestsForTokens(string methodPrefix, IEnumerable <TokenInfo> tokens,
                                            IEnumerable <MethodInfo> methods)
        {
            var isValid = true;

            foreach (var token in tokens)
            {
                var tokenName = token.Name.Replace("~", string.Empty);

                var methodName = string.Format("{1}TokenReplacementService_Can_Replace_{0}_Token", tokenName,
                                               methodPrefix);
                var method = methods.FirstOrDefault(m => m.Name.ToUpper() == methodName.ToUpper());

                RegressionUtils.WriteLine(methodName + " : " + (method != null));

                if (method == null)
                {
                    isValid = false;
                }
            }

            return(isValid);
        }
Beispiel #18
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);
                }
            }
        }
Beispiel #19
0
        public void CreateDefinitionCoverageReport()
        {
            var result = new StringBuilder();


            foreach (var definitionType in AllDefinitionTypes.OrderBy(d => d.Name))
            {
                var allProps       = definitionType.GetProperties().OrderBy(p => p.Name);
                var validatedProps = allProps.Where(p => p.GetCustomAttributes(typeof(ExpectValidationAttribute)).Any());
                var updatableProps = allProps.Where(p => p.GetCustomAttributes(true).Any(a => (a as ExpectUpdate) != null));

                RegressionUtils.WriteLine(definitionType.Name);

                result.Append("<table class='table table-bordered table-striped'>");

                result.Append("<thead>");
                result.Append("<tr>");
                result.AppendFormat("<th style='width: 150px;'>{0}</th>", definitionType.Name);
                result.Append("<th>Property</th>");
                result.Append("<th>Validated</th>");
                result.Append("<th>Updated</th>");
                result.Append("</tr>");
                result.Append("</thead>");

                result.Append("<tr>");

                bool isFirst = true;

                foreach (var prop in allProps)
                {
                    if (!isFirst)
                    {
                        result.Append("<tr>");
                    }

                    var isValidated = validatedProps.Any(p => p.Name == prop.Name);
                    var isUpdated   = updatableProps.Any(p => p.Name == prop.Name);

                    result.AppendFormat("<td></td>");
                    result.AppendFormat("<td>{0}</td>", prop.Name);
                    result.AppendFormat("<td>{0}</td>", isValidated);
                    result.AppendFormat("<td>{0}</td>", isUpdated);

                    RegressionUtils.WriteLine(string.Format("{0}{1} - validated:{2} updated:{3}", '\t', prop.Name, isValidated, isUpdated));

                    isFirst = false;

                    if (!isFirst)
                    {
                        result.Append("</tr>");
                    }
                }

                result.Append("</table>");
                result.Append("<br/>");
                result.Append("<br/>");
            }

            var reportHtml = result.ToString();

            RegressionUtils.WriteLine(reportHtml);
        }
        static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var m2runner = Environment.GetEnvironmentVariable("SPMeta2_RunnerLibraries", EnvironmentVariableTarget.Machine);
            var baseDir  = AppDomain.CurrentDomain.BaseDirectory;

            RegressionUtils.WriteLine(string.Format("Resolving custom assembly binding for m2 runner:[{0}]", m2runner));

            RegressionUtils.WriteLine(string.Format("    RequestingAssembly:[{0}]", args.RequestingAssembly));
            RegressionUtils.WriteLine(string.Format("    What requested:[{0}]", args.Name));

            if (args.Name.Contains(".resources,"))
            {
                RegressionUtils.WriteLine("resources assembly. returning null");
                return(null);
            }

            var assemblyName    = args.Name.Split(',')[0] + ".dll";
            var assemblyVersion = args.Name.Split(',')[1].Split('=')[1];

            var assemblyDirs = new List <string>();

            if (assemblyName.Contains("Microsoft.SharePoint.Client."))
            {
                switch (assemblyVersion)
                {
                case "16.1.0.0":
                    assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\csom-v365"));
                    break;

                case "15.0.0.0":
                    assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\csom-v2013"));
                    break;
                }
            }

            if (m2runner == "SPMeta2.Containers.O365v16.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-365"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-365"));
            }

            if (m2runner == "SPMeta2.Containers.O365.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-2013"));
            }
            assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-2013"));

            if (m2runner == "SPMeta2.Containers.CSOM.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-2013"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-2013"));
            }

            foreach (var dir in assemblyDirs)
            {
                var filePath = Path.Combine(dir, assemblyName);

                if (File.Exists(filePath))
                {
                    RegressionUtils.WriteLine(string.Format("Loading assemblly:[{0}]", filePath));
                    return(Assembly.LoadFile(filePath));
                }
            }

            throw new Exception(string.Format("Cannot load custom assembly:[{0}] for assembly:[{1}]",
                                              args.Name,
                                              args.RequestingAssembly
                                              ));
        }
        static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var m2runner = RegressionTestService.CurrentProvisionRunnerAsssmbly;
            var baseDir  = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);

            RegressionUtils.WriteLine(string.Format("Resolving custom assembly binding for m2 runner:[{0}]", m2runner));

            RegressionUtils.WriteLine(string.Format("    RequestingAssembly:[{0}]", args.RequestingAssembly));
            RegressionUtils.WriteLine(string.Format("    What requested:[{0}]", args.Name));

            if (args.Name.Contains(".resources,"))
            {
                RegressionUtils.WriteLine("resources assembly. returning null");
                return(null);
            }

            var assemblyName    = args.Name.Split(',')[0] + ".dll";
            var assemblyVersion = args.Name.Split(',')[1].Split('=')[1];

            var assemblyDirs = new List <string>();

            if (assemblyName.Contains("Microsoft.SharePoint.Client."))
            {
                switch (assemblyVersion)
                {
                case "16.1.0.0":
                    assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\csom-v365"));
                    break;

                case "15.0.0.0":
                    assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\csom-v2013"));
                    break;
                }
            }

            if (m2runner == "SPMeta2.Containers.O365v16.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-365"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-365"));

                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-365"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-365"));

                // VS sometimes does not coipy these accorss
                // referencing straight to the solution
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM.Standard\bin\Debug45-365\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM\bin\Debug45-365\")));

                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM\bin\Debug45-365\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM.Standard\bin\Debug45-365\")));
            }

            if (m2runner == "SPMeta2.Containers.O365.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-2013"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-2013"));

                // VS sometimes does not coipy these accorss
                // referencing straight to the solution
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM.Standard\bin\Debug45\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM\bin\Debug45\")));

                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM\bin\Debug45\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM.Standard\bin\Debug45\")));
            }

            if (m2runner == "SPMeta2.Containers.CSOM.dll")
            {
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-2013"));
                assemblyDirs.Add(Path.Combine(baseDir, @"_Dependencies\spmeta2-csom-regression-2013"));

                // VS sometimes does not coipy these accorss
                // referencing straight to the solution
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM.Standard\bin\Debug45\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.CSOM\bin\Debug45\")));

                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM\bin\Debug45\")));
                assemblyDirs.Add(GetFullPath(Path.Combine(baseDir, @"..\..\..\SPMeta2.Regression.CSOM.Standard\bin\Debug45\")));
            }

            foreach (var dir in assemblyDirs)
            {
                var filePath = Path.Combine(dir, assemblyName);

                if (File.Exists(filePath))
                {
                    RegressionUtils.WriteLine(string.Format("Loading assemblly:[{0}]", filePath));
                    return(Assembly.LoadFile(filePath));
                }
            }

            throw new Exception(string.Format("Cannot load custom assembly:[{0}] for assembly:[{1}]. Rebuild solution via powershell .\build in 'Build' project and run regression again",
                                              args.Name,
                                              args.RequestingAssembly
                                              ));
        }