Exemplo n.º 1
0
 private void buttonSaveEdit_Clicked(object sender, EventArgs e)
 {
     if (entryFirstName.Text != null || entryLastName.Text != null)
     {
         LoadingIndicator.IsRunning = true;
         if (entryFirstName.Text == null)
         {
             entryFirstName.Text = localUser.FirstName;
         }
         if (entryLastName.Text == null)
         {
             entryLastName.Text = localUser.LastName;
         }
         var userUpdater = UserSystemManager.UserUpdater();
         userUpdater.Result +=
             (status, firstName, lastName) =>
         {
             Device.BeginInvokeOnMainThread(() =>        //Grįžtama į main Thread !! SVARBU
             {
                 if (status == UserUpdateStatus.Success) //Pavyko
                 {
                     localUser.FirstName = firstName;
                     localUser.LastName  = lastName;
                     localUser.OnUpdateHandler?.Invoke(localUser);
                     DependencyService.Get <IToast>().LongToast("Pakeitimai išsaugoti");
                 }
                 else     //Ne
                 {
                     Application.Current.MainPage.DisplayAlert("Klaida", "woops, kažkas netaip", "tęsti");
                 }
                 LoadingIndicator.IsRunning = false;
             });
         };
         userUpdater.Update(entryFirstName.Text, entryLastName.Text);
     }
 }
Exemplo n.º 2
0
        public void UserUpdaterTest()
        {
            LocalUser user          = UnitTestAuth.Login(username: "******", password: "******");
            var       statusUpdater = UserUpdateStatus.UnknownError;
            var       statusGetter  = UserGetStatus.UnknownError;
            bool      done          = false;
            User      user1         = null;
            string    firstName     = "";
            string    lastName      = "";
            var       random        = new Random();

            var updater = UserSystemManager.UserUpdater();

            updater.Result += (_status, _firstName, _lastName) =>
            {
                statusUpdater = _status;
                firstName     = _firstName;
                lastName      = _lastName;
                done          = true;
            };

            var getter = UserSystemManager.UserGetter();

            getter.Result += (_status, _user) =>
            {
                statusGetter = _status;
                user1        = _user;
                done         = true;
            };

            firstName = random.Next().ToString();
            lastName  = random.Next().ToString();

            done = false;
            updater.Update(firstName, lastName);

            while (!done)
            {
            }
            Assert.AreEqual(statusUpdater, UserUpdateStatus.Success);
            Assert.AreNotEqual(firstName, null);
            Assert.AreNotEqual(lastName, null);

            done = false;
            getter.Get(user.Username);

            while (!done)
            {
            }
            Assert.AreEqual(statusGetter, UserGetStatus.Success);
            Assert.AreEqual(user.Username, user1.Username);
            Assert.AreNotEqual(user.FirstName, user1.FirstName);
            Assert.AreNotEqual(user.LastName, user1.LastName);
            Assert.AreEqual(firstName, user1.FirstName);
            Assert.AreEqual(lastName, user1.LastName);

            done = false;
            updater.Update(user.FirstName, user.LastName);

            while (!done)
            {
            }
            Assert.AreEqual(statusUpdater, UserUpdateStatus.Success);
            Assert.AreNotEqual(firstName, null);
            Assert.AreNotEqual(lastName, null);

            done = false;
            getter.Get(user.Username);

            while (!done)
            {
            }
            Assert.AreEqual(statusGetter, UserGetStatus.Success);
            Assert.AreEqual(user.Username, user1.Username);
            Assert.AreEqual(user.FirstName, user1.FirstName);
            Assert.AreEqual(user.LastName, user1.LastName);
        }