public void Verify(AstoriaResponse response) { //AstoriaTestLog.TraceInfo(payload); try { JSONPayload jsonPayload = new JSONPayload(response); } catch (Exception e) { AstoriaTestLog.FailAndContinue(new TestFailedException("Failed to parse JSON payload : " + e.ToString())); } //AstoriaTestLog.TraceInfo(jsonPayload.ToString()); return; }
private void Verify(AstoriaRequest request) { RequestVerb verb = request.EffectiveVerb; bool merge = verb == RequestVerb.Patch; PayloadObject entityBefore; if (!TryGetSingleObjectFromPayload(request.BeforeUpdatePayload, out entityBefore)) { AstoriaTestLog.FailAndThrow("Pre-update payload did not contain a single entity"); } // determine the type based on what was there (doing .Single() doesn't work for MEST, because the type shows up twice) ResourceType type = request.Workspace.ServiceContainer.ResourceTypes.First(rt => entityBefore.Type.Equals(rt.Namespace + "." + rt.Name)); PayloadObject entityAfter; if (!TryGetSingleObjectFromPayload(request.AfterUpdatePayload, out entityAfter)) { AstoriaTestLog.FailAndThrow("Post-update payload did not contain a single entity"); } CommonPayload updatePayload = request.CommonPayload; PayloadObject entityUpdate = null; if (request.URI.EndsWith("$value")) { Match match = Regex.Match(request.URI, @".*/(.+)/\$value"); if (!match.Success) { AstoriaTestLog.FailAndThrow("Could not determine property name for $value request"); } string propertyValue = null; if (request.ContentType.Equals(SerializationFormatKinds.MimeApplicationOctetStream, StringComparison.InvariantCultureIgnoreCase)) { object value = (request.UpdateTree as ResourceInstanceSimpleProperty).PropertyValue; if (updatePayload.Format == SerializationFormatKind.JSON) { propertyValue = JSONPayload.ConvertJsonValue(value); } else { AstoriaTestLog.FailAndThrow("Unsure how to fake property value"); } } else { propertyValue = request.Payload; } entityUpdate = new PayloadObject(updatePayload); PayloadSimpleProperty propertyUpdate = new PayloadSimpleProperty(entityUpdate); propertyUpdate.Name = match.Groups[1].Value; propertyUpdate.Value = propertyValue; entityUpdate.PayloadProperties.Add(propertyUpdate); merge = true; //PUT to a single property doesn't reset the resource } else if (!TryGetSingleObjectFromPayload(updatePayload, out entityUpdate)) { // must be a single property update PayloadProperty propertyUpdate = updatePayload.Resources as PayloadProperty; if (propertyUpdate == null) { AstoriaTestLog.FailAndThrow("Expected either a property or an entity in the update payload"); } entityUpdate = new PayloadObject(updatePayload); entityUpdate.PayloadProperties.Add(propertyUpdate); propertyUpdate.ParentObject = entityUpdate; merge = true; //PUT to a single property doesn't reset the resource } List <string> allPropertyNames = entityBefore.PayloadProperties .Union(entityAfter.PayloadProperties) .Union(entityUpdate.PayloadProperties) .Select(p => p.Name) .ToList(); allPropertyNames.AddRange(entityBefore.CustomEpmMappedProperties.Keys); allPropertyNames.AddRange(entityUpdate.CustomEpmMappedProperties.Keys); allPropertyNames.AddRange(entityAfter.CustomEpmMappedProperties.Keys); foreach (string propertyName in allPropertyNames.Distinct()) { PayloadProperty original = null; bool originalHadProperty = entityBefore.PayloadProperties.Any(p => (original = p).Name == propertyName); PayloadProperty update = null; bool updateHadProperty = entityUpdate.PayloadProperties.Any(p => (update = p).Name == propertyName); PayloadProperty final = null; bool finalHadProperty = entityAfter.PayloadProperties.Any(p => (final = p).Name == propertyName); if (type.Properties.Any(p => p.Name == propertyName && p.Facets.IsDeclaredProperty)) { // declared property if (!finalHadProperty) { AstoriaTestLog.FailAndThrow("Final version of entity is missing declared property '" + propertyName + "'"); } ResourceProperty property = type.Properties[propertyName] as ResourceProperty; if (property.IsNavigation) { continue; } if (!originalHadProperty) { AstoriaTestLog.FailAndThrow("Original version of entity is missing declared property '" + propertyName + "'"); } bool checkValue = property.PrimaryKey == null && !property.Facets.ServerGenerated; // if we changed it, we don't care what it was if (updateHadProperty) { ComparePropertyValues(property, update, final, checkValue); } else if (merge) { ComparePropertyValues(property, original, final, checkValue); } else if (checkValue) { CompareResetProperty(property, final); } } else { // dynamic property if (updateHadProperty) { if (!finalHadProperty) { AstoriaTestLog.FailAndThrow("Final version of entity is missing dynamic property '" + propertyName + "'"); } CompareDynamicPropertyValues(update, final); } else if (merge) { if (!finalHadProperty) { AstoriaTestLog.FailAndThrow("Final version of entity is missing dynamic property '" + propertyName + "'"); } CompareDynamicPropertyValues(original, final); } else if (finalHadProperty) { AstoriaTestLog.FailAndThrow("Dynamic property '" + propertyName + "' was not cleared after reset"); } } } }