Пример #1
0
        async Task <Guid?> IStatementsApi.Post(PostStatementRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.Validate();

            var options = new RequestOptions(ENDPOINT)
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            this.CompleteOptions(options, request);

            try
            {
                HttpResponseMessage response = await this._client.PostJson(options, request.Statement);

                List <Guid> content = await response.Content.ReadAsAsync <List <Guid> >(new[] { new StrictJsonMediaTypeFormatter() });

                return(content?.FirstOrDefault());
            }
            catch (ConflictException)
            {
                return(null);
            }
        }
Пример #2
0
        public async Task can_post_voiding_statement()
        {
            // Arrange
            Statement statement = this.GetVoidingStatement(STATEMENT_ID, STATEMENT_ID_2);
            var       request   = new PostStatementRequest(statement);

            this._mockHttp
            .When(HttpMethod.Post, this.GetApiUrl("statements"))
            .Respond(HttpStatusCode.OK, "application/json", $"[\"{STATEMENT_ID}\"]");

            // Act
            Guid?result = await this._client.Statements.Post(request);

            // Assert
            result.Should().NotBeNull().And.Be(STATEMENT_ID);
        }
Пример #3
0
        public async Task cannot_post_existing_statement()
        {
            // Arrange
            Statement statement = this.GetStatement(STATEMENT_ID);
            var       request   = new PostStatementRequest(statement);

            this._mockHttp
            .When(HttpMethod.Post, this.GetApiUrl("statements"))
            .Respond(HttpStatusCode.Conflict);

            // Act
            Guid?result = await this._client.Statements.Post(request);

            // Assert
            result.Should().BeNull();
        }
Пример #4
0
        public void cannot_post_new_statement_when_unauthorized()
        {
            // Arrange
            Statement statement = this.GetStatement(STATEMENT_ID);
            var       request   = new PostStatementRequest(statement);

            this._mockHttp
            .When(HttpMethod.Post, this.GetApiUrl("statements"))
            .Respond(HttpStatusCode.Forbidden);

            // Act
            Func <Task> action = async() =>
            {
                await this._client.Statements.Post(request);
            };

            // Assert
            action.ShouldThrow <ForbiddenException>();
        }
Пример #5
0
 private void CompleteOptions(RequestOptions options, PostStatementRequest request)
 {
 }