Exemplo n.º 1
0
        public async Task cannot_post_existing_state_when_etag_is_invalid()
        {
            // Arrange
            var state = new StateDocument <string>()
            {
                Content = "foo",
                ETag    = ETAG
            };
            var request = PostStateRequest.Create(state);

            request.ActivityId = new Uri(ACTIVITY_ID);
            request.Agent      = new Agent()
            {
                Name = AGENT_NAME,
                MBox = new Uri(AGENT_MBOX)
            };
            request.Registration = REGISTRATION;
            request.StateId      = STATE_ID;
            this._mockHttp
            .When(HttpMethod.Post, this.GetApiUrl("activities/state"))
            .WithQueryString("activityId", ACTIVITY_ID)
            .WithQueryString("agent", AGENT_QS)
            .WithQueryString("registration", REGISTRATION.ToString())
            .WithQueryString("stateId", STATE_ID)
            .WithHeaders("If-Match", ETAG)
            .Respond(HttpStatusCode.PreconditionFailed);

            // Act
            bool result = await this._client.States.Post(request);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 2
0
        async Task <bool> IStatesApi.Post <T>(PostStateRequest <T> request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.Validate();

            var options = new RequestOptions(ENDPOINT);

            this.CompleteOptions(options, request);

            try
            {
                await this._client.PostJson(options, request.State);

                return(true);
            }
            catch (PreConditionFailedException)
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 private void CompleteOptions <T>(RequestOptions options, PostStateRequest <T> request)
 {
     this.CompleteOptionsBase(options, request);
     this.AddETagHeader(options, request.State.ETag);
 }