protected void ResolveHook(EventHooks eventHooks, string start) { IndentableTrace.WithScope(traceScope => { if (eventHooks.OnProvisioning) { if (!ShowOnlyFalseResults) { traceScope.WriteLine(string.Format("[INF]{0} [VALIDATED] - [OnProvisioning]", start)); } } else { traceScope.WriteLine(string.Format("[ERR]{0} [MISSED] - [OnProvisioning]", start)); } if (eventHooks.OnProvisioned) { if (!ShowOnlyFalseResults) { traceScope.WriteLine(string.Format("[INF]{0} [VALIDATED] - [OnProvisioned]", start)); } } else { traceScope.WriteLine(string.Format("[IERR]{0} [MISSED] - [OnProvisioned]", start)); } AssertService.AreEqual(true, eventHooks.OnProvisioning); AssertService.AreEqual(true, eventHooks.OnProvisioned); }); }
public void ExpectUpdateAttributes_ShouldHave_Services() { var updateAttrTypes = ReflectionUtils.GetTypesFromAssembly <ExpectUpdate>(typeof(ExpectUpdate).Assembly); var updateAttrServices = new List <ExpectUpdateValueServiceBase>(); updateAttrServices.AddRange(ReflectionUtils.GetTypesFromAssembly <ExpectUpdateValueServiceBase>(typeof(ExpectUpdateValueServiceBase).Assembly) .Select(t => Activator.CreateInstance(t) as ExpectUpdateValueServiceBase)); IndentableTrace.WithScope(trace => { foreach (var attr in updateAttrTypes) { var targetServices = updateAttrServices.FirstOrDefault(s => s.TargetType == attr); if (targetServices != null) { trace.WriteLine(string.Format("ExpectUpdate: [{0}] has service: [{1}]", attr, targetServices.GetType())); } else { trace.WriteLine(string.Format("ExpectUpdate: [{0}] misses service impl", attr)); Assert.Fail(); } } }); }
private void ProcessDefinitionsPropertyNulableValidation(DefinitionBase def) { var nullableProps = def.GetType() .GetProperties() .Where(p => p.GetCustomAttributes(typeof(ExpectNullable), true).Count() > 0); IndentableTrace.WithScope(trace => { trace.WriteLine(""); trace.WriteLine(string.Format("[INF]\tPROPERTY NULLABLE VALIDATION")); trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def)); if (nullableProps.Count() == 0) { trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping.")); } else { foreach (var prop in nullableProps) { trace.WriteLine(string.Format("[INF]\tSetting NULLABLE property: [" + prop.Name + "]")); prop.SetValue(def, null); } } }); }
private void PleaseMakeSureWeCanSerializeDeserializeAndStillDeploy(IEnumerable <ModelNode> models) { if (!TestOptions.EnableSerializeDeserializeAndStillDeployTests) { return; } IndentableTrace.WithScope(trace => { trace.WriteLine("Saving-restoring XML/JSON models. Deployng.."); var serializedModels = RegressionService.GetSerializedAndRestoredModels(models); RegressionService.TestModels(serializedModels); }); }
public void CanSerialize_SiteModelToJSONAndBack() { var orginalModel = SPMeta2Model.NewSiteModel(site => { }); IndentableTrace.WithScope(trace => { var modelString = SPMeta2Model.ToJSON(orginalModel); Assert.IsFalse(string.IsNullOrEmpty(modelString)); trace.WriteLine("JSON"); trace.WriteLine(modelString); var deserializedModel = SPMeta2Model.FromJSON(modelString); Assert.IsNotNull(deserializedModel); }); }
public static ValidationPair <TSource> AssertProperty <TSource, TProperty>( this ValidationPair <TSource> source, ValidationResultType resultType, Expression <Func <TSource, TProperty> > exp) where TSource : DefinitionBase { var result = source.ValidationResult; var prop = ReflectionUtils.GetExpressionValue(source.Model, exp); IndentableTrace.WithScope(s => { s.WriteLine(string.Format("Validating property: [{0}]", prop.Name)); Assert.IsTrue(result.Count(r => r.PropertyName == prop.Name && !r.IsValid && r.ResultType == resultType) > 0); }); return(source); }
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); }); } }
protected override void ValidateHtmlPage(SPFile file, string pageUrl, string pageContent, DefinitionBase definitionBase) { var definition = definitionBase as XsltListViewWebPartGridModePresenceDefinition; var assert = ServiceFactory.AssertService .NewAssert(definition, file) // dont' need to check that, not the pupose of the test //.ShouldBeEqual(m => m.PageFileName, o => o.GetName()) .ShouldNotBeNull(file); //if (definition.WebPartDefinitions.Any()) //{ assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.WebPartDefinitions); var isValid = true; IndentableTrace.WithScope(trace => { trace.WriteLine(string.Format("Checking InitGridFromView presence:[{0}]", pageUrl)); isValid = pageContent.Contains("InitGridFromView"); }); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, //Dst = dstProp, IsValid = isValid }); }); //} //else //{ // assert.SkipProperty(m => m.WebPartDefinitions, "WebPartDefinitions.Count = 0. Skipping"); //} }
private void ProcessDefinitionsPropertyUpdateValidation(DefinitionBase def) { var updatableProps = def.GetType() .GetProperties() .Where(p => p.GetCustomAttributes(typeof(ExpectUpdate), true).Count() > 0); IndentableTrace.WithScope(trace => { trace.WriteLine(""); trace.WriteLine(string.Format("[INF]\tPROPERTY UPDATE VALIDATION")); trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def)); if (updatableProps.Count() == 0) { trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping.")); } else { foreach (var prop in updatableProps) { object newValue = null; var expectUpdateAttr = prop.GetCustomAttributes(typeof(ExpectUpdate), true) .FirstOrDefault() as ExpectUpdate; newValue = GetNewPropValue(expectUpdateAttr, def, prop); trace.WriteLine(string.Format("[INF]\t\tChanging property [{0}] from [{1}] to [{2}]", prop.Name, prop.GetValue(def), newValue)); prop.SetValue(def, newValue); } } trace.WriteLine(""); }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <FieldDefinition>("model", value => value.RequireNotNull()); var spObject = GetField(modelHost, definition); var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject); ValidateField(assert, spObject, definition); var typedField = spObject as SPFieldCalculated; var typedDefinition = model.WithAssertAndCast <CalculatedFieldDefinition>("model", value => value.RequireNotNull()); var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, typedDefinition, typedField); typedFieldAssert.ShouldBeEqual(m => m.CurrencyLocaleId, o => o.CurrencyLocaleId); typedFieldAssert.ShouldBeEqual(m => m.DateFormat, o => o.GetDateFormat()); typedFieldAssert.ShouldBeEqual(m => m.OutputType, o => o.GetOutputType()); // typedFieldAssert.ShouldBeEqual(m => m.DisplayFormat, o => o.GetDisplayFormat()); if (typedDefinition.ShowAsPercentage.HasValue) { typedFieldAssert.ShouldBeEqual(m => m.ShowAsPercentage, o => o.ShowAsPercentage); } else { typedFieldAssert.SkipProperty(m => m.ShowAsPercentage, "ShowAsPercentage is NULL. Skipping."); } if (!string.IsNullOrEmpty(typedDefinition.Formula)) { typedFieldAssert.ShouldBeEqual(m => m.Formula, o => o.Formula); } else { typedFieldAssert.SkipProperty(m => m.Formula); } IndentableTrace.WithScope(s => { s.WriteLine(string.Format("Formula: Src:[{0}] Dst:[{1}]", typedDefinition.Formula, typedField.Formula)); }); // field refs if (typedDefinition.FieldReferences.Count > 0) { var hasFieldRefs = true; if (typedField.FieldReferences != null) { foreach (var dstFieldRef in typedField.FieldReferences) { if (typedDefinition.FieldReferences.FirstOrDefault(c => c.ToUpper() == dstFieldRef.ToUpper()) == null) { hasFieldRefs = false; } } if (typedField.FieldReferences.Length == 0) { hasFieldRefs = false; } } else { hasFieldRefs = false; } typedFieldAssert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.FieldReferences); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = hasFieldRefs == true }); }); } else { typedFieldAssert.SkipProperty(m => m.FieldReferences, "FieldReferences.Count == 0. Skipping."); } }
protected virtual void ValidateHtmlPage( SPFile file, string pageUrl, string pageContent, DefinitionBase definitionBase ) { var definition = definitionBase as WebpartPresenceOnPageDefinition; var assert = ServiceFactory.AssertService .NewAssert(definition, file) // dont' need to check that, not the pupose of the test //.ShouldBeEqual(m => m.PageFileName, o => o.GetName()) .ShouldNotBeNull(file); if (definition.WebPartDefinitions.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.WebPartDefinitions); var isValid = true; IndentableTrace.WithScope(trace => { trace.WriteLine(string.Format("Checking web part presence on the page:[{0}]", pageUrl)); // so, essentially there should be a span with web part title foreach (var webpart in definition.WebPartDefinitions) { var targetSpan = string.Format("<span>{0}</span>", webpart.Title); var hasWebPart = pageContent.Contains(targetSpan); if (!hasWebPart) { trace.WriteLine( string.Format("[ERR] Page [{0}] misses web part with title:[{1}] and def:[{2}]", new object[] { pageUrl, webpart.Title, webpart })); isValid = false; } else { trace.WriteLine(string.Format("[True] Page [{0}] has web part with title:[{1}] and def:[{2}]", new object[] { pageUrl, webpart.Title, webpart })); } } // if the target web part is .AddToPageContent foreach (var webpart in definition.WebPartDefinitions) { if (webpart.AddToPageContent) { // web part must be with in a wiki content zone // <div id="ctl00_PlaceHolderMain_WikiField"> // <div class="ms-wikicontent ms-rtestate-field" style="padding-right: 10px"> // <span title="3fc9a6961e5a48b9855c1ecd9afd12e5" id="WebPartTitleWPQ2" class="js-webpart-titleCell"> CQ j = pageContent; var wikiFieldCnt = j.Select("div[id$='_PlaceHolderMain_WikiField']"); var wikiFieldCntText = wikiFieldCnt.Html(); var wpTitleText = string.Format("<span>{0}</span>", webpart.Title); var hasWebPartInWikiArea = wikiFieldCntText.Contains(wpTitleText); if (!hasWebPartInWikiArea) { trace.WriteLine( string.Format("[ERR] Wiki page [{0}] misses web part within WIKI area. Wp title:[{1}] and def:[{2}]", new object[] { pageUrl, webpart.Title, webpart })); isValid = false; } else { trace.WriteLine( string.Format("[True] Wiki page [{0}] has web part within WIKI area. Wp title:[{1}] and def:[{2}]", new object[] { pageUrl, webpart.Title, webpart })); } } } }); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, //Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.WebPartDefinitions, "WebPartDefinitions.Count = 0. Skipping"); } }