protected virtual async Task <TReadModel> PatchCommand(TKey id, IJsonPatchDocument jsonPatch, CancellationToken cancellationToken = default(CancellationToken)) { var command = new EntityPatchCommand <TKey, TReadModel>(id, jsonPatch, User); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(result); }
private bool ValidateJsonPatchDocument(IJsonPatchDocument doc, ActionExecutingContext context) { doc.GetType() .TryGetGenericTypeOfImplementedGenericType(typeof(JsonPatchDocument <>), out var buildGenericType); var argType = buildGenericType.GenericTypeArguments[0]; if (!typeof(IFormModel).IsAssignableFrom(argType)) { return(true); } var mi = GetType().GetMethod(nameof(ValidateJsonPatchDocumentOfT), BindingFlags.NonPublic | BindingFlags.Instance); var gmi = mi?.MakeGenericMethod(argType); var resp = gmi?.Invoke(this, new object[] { doc, context }) as bool? == true; return(resp); }
private void VerifyPatchIsCalled(IJsonPatchDocument expected) { // Verify the API has been called once _clientMock.Verify(x => x.PatchNamespacedCustomObjectStatusWithHttpMessagesAsync ( It.IsAny <V1Patch>(), "group", "v1", "ns1", "resources", "resource1", null, default(System.Threading.CancellationToken) ), Times.Once); // Semantic equal assertion (JsonPatchDocument.Equals doesn't compare the content) var actual = (_clientMock.Invocations[0].Arguments[0] as V1Patch).Content as IJsonPatchDocument; Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual)); _clientMock.VerifyNoOtherCalls(); }
public IJsonPatchDocument Map(IJsonPatchDocument sourceDoc) { var result = new JsonPatchDocument <TDest>(); sourceDoc.GetOperations().ToList().ForEach( x => { if (NeedsToBeMap(x.path)) { result.Operations.Add( new Operation <TDest>( x.op, GetTargetMappingPath(x.path), x.from, x.value ) ); } } ); return(result); }
public V1Patch(IJsonPatchDocument jsonPatch) : this((object)jsonPatch) { }
public EntityPatchCommand(IPrincipal?principal, [NotNull] TKey id, [NotNull] IJsonPatchDocument patch) : base(principal, id) { Patch = patch ?? throw new ArgumentNullException(nameof(patch)); }
protected virtual async Task <TReadModel> PatchCommand(TKey id, IJsonPatchDocument jsonPatch, CancellationToken cancellationToken = default) { var command = new EntityPatchCommand <TKey, TReadModel>(User, id, jsonPatch); return(await Mediator.Send(command, cancellationToken)); }