async Task <bool> IStatementsApi.Put(PutStatementRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } request.Validate(); var options = new RequestOptions(ENDPOINT) { NullValueHandling = NullValueHandling.Ignore }; this.CompleteOptions(options, request); try { await this._client.PutJson(options, request.Statement); return(true); } catch (ConflictException) { return(false); } }
public async Task can_put_voiding_statement() { // Arrange Statement statement = this.GetVoidingStatement(STATEMENT_ID, STATEMENT_ID_2); var request = new PutStatementRequest(statement); this._mockHttp .When(HttpMethod.Put, this.GetApiUrl("statements")) .WithQueryString("statementId", STATEMENT_ID.ToString()) .Respond(HttpStatusCode.NoContent); // Act bool result = await this._client.Statements.Put(request); // Assert result.Should().BeTrue(); }
public void cannot_put_new_statement_when_unauthorized() { // Arrange Statement statement = this.GetStatement(STATEMENT_ID); var request = new PutStatementRequest(statement); this._mockHttp .When(HttpMethod.Put, this.GetApiUrl("statements")) .WithQueryString("statementId", STATEMENT_ID.ToString()) .Respond(HttpStatusCode.Forbidden); // Act Func <Task> action = async() => { await this._client.Statements.Put(request); }; // Assert action.ShouldThrow <ForbiddenException>(); }
private void CompleteOptions(RequestOptions options, PutStatementRequest request) { options.QueryStringParameters.Add("statementId", request.Statement.Id.ToString()); }