Beispiel #1
0
        public async Task cannot_post_many_new_statements_when_one_already_exists()
        {
            // Arrange
            List <Statement> statements = this.GetStatements();
            var request = new PostStatementsRequest(statements);

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

            // Act
            List <Guid> result = await this._client.Statements.PostMany(request);

            // Assert
            result.Should().BeEmpty();
        }
Beispiel #2
0
        public async Task can_post_many_new_statements()
        {
            // Arrange
            List <Statement> statements = this.GetStatements();
            var request = new PostStatementsRequest(statements);

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

            // Act
            List <Guid> result = await this._client.Statements.PostMany(request);

            // Assert
            result.Should().HaveCount(2).And.Contain(STATEMENT_ID).And.Contain(STATEMENT_ID_2);
        }
Beispiel #3
0
        async Task <List <Guid> > IStatementsApi.PostMany(PostStatementsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.Validate();

            var options = new RequestOptions(ENDPOINT);

            this.CompleteOptions(options, request);

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

                return(await response.Content.ReadAsAsync <List <Guid> >(new[] { new StrictJsonMediaTypeFormatter() }));
            }
            catch (ConflictException)
            {
                return(new List <Guid>());
            }
        }
Beispiel #4
0
 private void CompleteOptions(RequestOptions options, PostStatementsRequest request)
 {
 }