private static void ValidateOperations <T>(PatchOperation patchOperation, PatchOperationType operationType, T value) { Assert.AreEqual(operationType, patchOperation.OperationType); Assert.AreEqual(path, patchOperation.Path); if (!operationType.Equals(PatchOperationType.Remove)) { string expected; CosmosSerializer cosmosSerializer = new CosmosJsonDotNetSerializer(); using (Stream stream = cosmosSerializer.ToStream(value)) { using (StreamReader streamReader = new StreamReader(stream)) { expected = streamReader.ReadToEnd(); } } Assert.IsTrue(patchOperation.TrySerializeValueParameter(new CustomSerializer(), out Stream valueParam)); string actual; using (valueParam) { using (StreamReader streamReader = new StreamReader(valueParam)) { actual = streamReader.ReadToEnd(); } } Assert.AreEqual(expected, actual); } }
/// <summary> /// Ensures that <see cref="Type"/> is equal to <paramref name="requiredType"/>. /// </summary> /// <param name="requiredType"></param> private void CheckType(PatchOperationType requiredType) { if (Type != requiredType) { throw new InvalidOperationException(); } }
/// <summary> /// Initializes a new instance of <see cref="PatchOperation"/> class with /// the given type and addition and deletion ranges. /// </summary> /// <param name="type"></param> /// <param name="addition"></param> /// <param name="deletion"></param> /// <param name="copy"></param> private PatchOperation(PatchOperationType type, Range <int> addition, Range <int> deletion, Range <int> copy) { this.type = type; this.addition = addition; this.deletion = deletion; this.copy = copy; }
/// <summary> /// Initializes a new instance of the <see cref="PatchOperationCore"/> class. /// </summary> /// <param name="operationType">Specifies the type of Patch operation.</param> /// <param name="path">Specifies the path to target location.</param> public PatchOperationCore( PatchOperationType operationType, string path) { this.OperationType = operationType; this.Path = string.IsNullOrWhiteSpace(path) ? throw new ArgumentNullException(nameof(path)) : path; }
public static string ToEnumMemberString(this PatchOperationType patchOperationType) { switch (patchOperationType) { case PatchOperationType.Add: return(PatchConstants.OperationTypeNames.Add); case PatchOperationType.Remove: return(PatchConstants.OperationTypeNames.Remove); case PatchOperationType.Replace: return(PatchConstants.OperationTypeNames.Replace); case PatchOperationType.Set: return(PatchConstants.OperationTypeNames.Set); default: throw new ArgumentException($"Unknown Patch operation type '{patchOperationType}'."); } }
/// <summary> /// Patch operation /// </summary> public PatchOperation(PatchOperationType operation, String path, Object value) { this.OperationType = operation; this.Path = path; this.Value = value; }
public InternalPatchOperation(PropertyInfo propertyInfo, object?newValue, PatchOperationType type) { PropertyInfo = propertyInfo; NewValue = newValue; Type = type; }