public async Task InvalidatCommand_Fails() { // arrange/act var behaviorResult = new CommandBehaviorResult(); var ex = await Assert.ThrowsAsync <ValidationException>(() => new ValidateCommandBehavior().ExecutePreHandleAsync(new StubCommand(null), behaviorResult)).AnyContext(); // assert ex.Message.ShouldContain("has validation errors"); }
public async Task ValidCommand_Succeeds() { // arrange/act var behaviorResult = new CommandBehaviorResult(); await new ValidateCommandBehavior().ExecutePreHandleAsync(new StubCommand("Name1"), behaviorResult).AnyContext(); // assert behaviorResult.ShouldNotBeNull(); behaviorResult.Cancelled.ShouldBeFalse(); }
public async Task ExecutePostHandleAsync <TResponse>(CommandResponse <TResponse> response, CommandBehaviorResult result) { if (!result.Cancelled && this.next != null) { await this.next.ExecutePostHandleAsync(response, result).AnyContext(); } }
/// <summary> /// Executes this behavior for the specified command. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The command.</param> public async Task ExecutePreHandleAsync <TResponse>(Command <TResponse> request, CommandBehaviorResult result) { EnsureArg.IsNotNull(request); var path = this.pathTemplate .Replace("{id}", request.Id) .Replace("{type}", request.GetType().PrettyName(false)); await this.storage.SaveFileObjectAsync(path, request, this.serializer).AnyContext(); if (!result.Cancelled && this.next != null) { await this.next.ExecutePreHandleAsync(request, result).AnyContext(); } // terminate here }