internal async Task WhenClientIdChangesAfterRegisteringDevice_StateMachineShouldReceive_GotPushDeviceDetailsEvent() { // Arrange const string newClientId = "testId"; var options = new ClientOptions(ValidKey) { TransportFactory = new FakeTransportFactory(), SkipInternetCheck = true }; var mobileDevice = new FakeMobileDevice(); async Task <AblyResponse> HandleRequestFunc(AblyRequest request) { if (request.Url.Contains("/push/deviceRegistrations")) { return(new AblyResponse() { TextResponse = JObject.FromObject(new { clientId = newClientId, deviceIdentityToken = new { token = "token" } }).ToString() }); } return(new AblyResponse() { TextResponse = "{}" }); } var realtime = new AblyRealtime(options, (clientOptions, device) => GetRestClient(HandleRequestFunc, options, device), mobileDevice); // Setup the local device var localDevice = PushTestHelpers.GetRegisteredLocalDevice(realtime.RestClient); realtime.RestClient.Device = localDevice; localDevice.ClientId.Should().BeNull(); realtime.Push.InitialiseStateMachine(); var taskAwaiter = new TaskCompletionAwaiter(); var stateMachine = realtime.Push.StateMachine; stateMachine.CurrentState = new ActivationStateMachine.WaitingForPushDeviceDetails(stateMachine); // We trigger the GotPushDeviceDetails event await stateMachine.HandleEvent(new ActivationStateMachine.GotPushDeviceDetails()); // From here we expect the stateMachine to move to WaitingForDeviceRegistration and try to register the Device // The registration will hit our mocked rest client above and return a localDevice with a new clientId. // Once the clientId is received we should expect to receive GotPushDeviceDetails event and the new clientId to be persisted realtime.Push.StateMachine.ProcessingEventCallback = @event => { // Check we received the correct event @event.Should().BeOfType <ActivationStateMachine.GotPushDeviceDetails>(); taskAwaiter.Done(); }; (await taskAwaiter).Should().BeTrue(); mobileDevice.GetPreference(PersistKeys.Device.ClientId, PersistKeys.Device.SharedName).Should().Be(newClientId); }
private static LocalDevice GetTestLocalDevice(AblyRest client) => PushTestHelpers.GetTestLocalDevice(client, "123");