public async Task cannot_put_existing_state_when_etag_is_invalid() { // Arrange var state = new StateDocument <string>() { Content = "foo", ETag = ETAG }; var request = PutStateRequest.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.Put, 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.Put(request); // Assert result.Should().BeFalse(); }
async Task <bool> IStatesApi.Put <T>(PutStateRequest <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.State); return(true); } catch (PreConditionFailedException) { return(false); } }
public DeviceStateHandler( [NotNull] SpotifySession session, uint initialVolume, int volumeSteps) { previousPause = null; _session = session; this._deviceInfo = InitializeDeviceInfo(initialVolume, volumeSteps); this._putState = new PutStateRequest { MemberType = MemberType.ConnectState, Device = new Connectstate.Device { DeviceInfo = _deviceInfo } }; session.Dealer().AddMessageListener(this, "hm://pusher/v1/connections/", "hm://connect-state/v1/connect/volume", "hm://connect-state/v1/cluster"); session.Dealer().AddRequestListener(this, "hm://connect-state/v1/"); }
private void CompleteOptions <T>(RequestOptions options, PutStateRequest <T> request) { this.CompleteOptionsBase(options, request); this.AddETagHeader(options, request.State.ETag); }