Пример #1
0
        public async Task AddPerson_CallsRepositoryCorrectly()
        {
            var person = new Person();

            await SUT.AddPersonAsync(person);

            _mockRepository.Verify(repo => repo.AddPersonAsync(person), Times.Once);
        }
Пример #2
0
        public async Task <ActionResult <PersonDTO> > Post([FromBody] PersonDTO dto)
        {
            var person = _mapper.Map <Person>(dto);

            var id = await _service.AddPersonAsync(person);

            return(CreatedAtAction("Get", new { id }, person));
        }
Пример #3
0
        public async Task CanAddPerson()
        {
            Person person = new Person();

            _mockPersonRepository.Setup(r => r.AddPersonAsync(It.IsAny <Person>(), It.IsAny <CancellationToken>())).ReturnsAsync(person);

            Person added = await _personService.AddPersonAsync(person, new CancellationToken());

            Assert.Equal(person, added);
            _mockPersonRepository.Verify(r => r.AddPersonAsync(person, It.IsAny <CancellationToken>()), Times.Once);
            _mockPersonRepository.VerifyNoOtherCalls();
        }
Пример #4
0
        /// <summary>
        /// Update the person with the service
        /// </summary>
        /// <returns></returns>
        private async Task SavePerson()
        {
            // Simplistic avoidance of duplicate calls
            if (this.IsBusy)
            {
                return;
            }

            // Validation
            if (string.IsNullOrEmpty(this.Person.FirstName) || string.IsNullOrEmpty(this.Person.LastName))
            {
                this.NotValid = true;
                return;
            }

            this.IsBusy = true;

            try
            {
                // Save the person and navigate back
                if (this.Person.Id == 0)
                {
                    await PersonService.AddPersonAsync(this.Person);
                }
                else
                {
                    await PersonService.UpdatePersonAsync(this.Person);
                }

                NavigateBack?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                // Placeholder error handling
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #5
0
        private async void RegisterClick()
        {
            if (CanExecute())
            {
                if (Password.Equals(PasswordCheck))
                {
                    try
                    {
                        Person newUser = new Person();
                        newUser.Email               = Email;
                        newUser.Password            = Password;
                        newUser.FirstName           = FirstName;
                        newUser.LastName            = LastName;
                        newUser.KeyLength           = ConvertKey();
                        newUser.KeyUsed             = KeyUsed;
                        newUser.Company.NameCompany = FirstLetterToUpperCase(CompanyName);
                        newUser.TypeAlgo.Type       = SelectedAlgorithm;

                        PersonService peopleService = new PersonService();
                        await peopleService.AddPersonAsync(newUser);

                        _navigationService.NavigateTo("LoginPage");
                    }
                    catch (NoNetworkException noNetworkException)
                    {
                        ShowToast(noNetworkException.ToString());
                    }
                    catch (Exception e)
                    {
                        ShowToast(e.ToString());
                    }
                }
                else
                {
                    ShowToast("not_same_password");
                }
            }
        }