public async Task cannot_put_existing_agent_profile_when_etag_is_invalid() { // Arrange var state = new AgentProfileDocument <string>() { Content = "foo", ETag = ETAG }; var request = PutAgentProfileRequest.Create(state); request.Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }; request.ProfileId = PROFILE_ID; this._mockHttp .When(HttpMethod.Put, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .WithHeaders("If-Match", ETAG) .Respond(HttpStatusCode.PreconditionFailed); // Act bool result = await this._client.AgentProfiles.Put(request); // Assert result.Should().BeFalse(); }
public async Task can_put_new_agent_profile() { // Arrange var state = new AgentProfileDocument <string>() { Content = "foo" }; var request = PutAgentProfileRequest.Create(state); request.Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }; request.ProfileId = PROFILE_ID; this._mockHttp .When(HttpMethod.Put, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .WithHeaders("If-None-Match", "*") .Respond(HttpStatusCode.NoContent); // Act bool result = await this._client.AgentProfiles.Put(request); // Assert result.Should().BeTrue(); }
async Task <bool> IAgentProfilesApi.Put <T>(PutAgentProfileRequest <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.PutJson(options, request.AgentProfile); return(true); } catch (PreConditionFailedException) { return(false); } }
private void CompleteOptions <T>(RequestOptions options, PutAgentProfileRequest <T> request) { this.CompleteOptionsBase(options, request); this.AddETagHeader(options, request.AgentProfile.ETag); }