public void Given_a_admin_user_registration_has_been_completed_When_handling_the_event_then_the_correct_request_object_is_created()
        {
            //GIVEN
            CreateAdminUserRequest requestObject = null; 
            var userService = new Mock<IUserService>();
            var userRepository = new Mock<IUserRepository>();
            userService.Setup(x => x.CreateAdminUser(It.IsAny<CreateAdminUserRequest>()))
                .Callback<CreateAdminUserRequest>(x => requestObject = x);
            var target = new RegistrationCompletedHandler(userService.Object, userRepository.Object);
            var forename = "RaRa";
            var surname = "Rasputin";

            //var message = new Peninsula.Online.Messages.Events.PeninsulaOnlineAdminUserRegistrationCompleted()();
            var message = new RegistrationCompleted
                              {
                                  ClientId = 123,
                                  IsAdmin = true,
                                  UserId = Guid.NewGuid()
                              };
            //WHEN
            target.Handle(message);

            //THEN
            Assert.IsNotNull(requestObject);
            Assert.AreEqual(forename, requestObject.Forename);
            Assert.AreEqual(surname, requestObject.Surname);
        }
        public async Task DoAuthenticationAsync()
        {
            if (App.Authenticator != null)
            {
                var authenticationResult = await App.Authenticator.Authenticate(mobileServiceAuthenticationProvider);

                if (authenticationResult.Success)
                {
                    PmdAppSetting.UserProviderAuthentication = JsonConvert.SerializeObject(dataStore.CurrentClient.CurrentUser);
                    PmdAppSetting.IsProviderAuthenticated    = true;
                }

                /*
                 *  - Sync with the server
                 *  - Register User+Provider
                 */
                if (PmdAppSetting.IsProviderAuthenticated && string.IsNullOrEmpty(PmdAppSetting.RegistrationId))
                {
                    // Step 1
                    RegistrationStarted?.Invoke(this, new EventArgs());

                    var deviceId = GetDeviceRegistrationId();
                    var userDeviceRegistrationModel = new
                    {
                        Email          = "*****@*****.**",
                        DeviceId       = deviceId,
                        ProviderUserId = authenticationResult.UserId,
                        Provider       = mobileServiceAuthenticationProvider.ToString(),
                        Idiom          = Plugin.DeviceInfo.CrossDeviceInfo.Current.Idiom.ToString(),
                        Model          = Plugin.DeviceInfo.CrossDeviceInfo.Current.Model,
                        Platform       = Plugin.DeviceInfo.CrossDeviceInfo.Current.Platform.ToString(),
                        Version        = Plugin.DeviceInfo.CrossDeviceInfo.Current.Version,
                    };

                    try
                    {
                        var registrationContent = Newtonsoft.Json.Linq.JToken.FromObject(userDeviceRegistrationModel);
                        var postResult          = await dataStore.CurrentClient.InvokeApiAsync("/api/users", registrationContent);

                        var responseModel = postResult.ToObject <Models.Auth.AuthResult>();
                        if (responseModel.Succeeded)
                        {
                            // Step 2
                            PmdAppSetting.RegistrationId = responseModel.UserId;

                            await dataStore.EntitiesRegistrationCheckAsync();

                            var resultCode = await dataStore.SyncAsync();

                            RegistrationCompleted?.Invoke(this, resultCode);
                        }
                    }
                    catch (Exception)
                    {
                        RegistrationCompleted?.Invoke(this, DataStoreSyncCode.ErrorInServer);
                    }
                }
            }
        }
Example #3
0
 void OnRegistrationCompleted(bool isSuccess)
 {
     OnPropertyChanged(nameof(IsRegisteredForPushNotifications));
     OnPropertyChanged(nameof(RegisterForPushNotificationButtonLabel));
     RegistrationCompleted?.Invoke(this, new PushNotifEventArgs {
         IsSuccessful = isSuccess
     });
 }
 void OnRegistrationCompleted(bool isSuccess) =>
 RegistrationCompleted?.Invoke(this, new PushNotifEventArgs {
     IsSuccessful = isSuccess
 });