예제 #1
0
            public async void Should_return_NotFound_when_phone_is_Invalid()
            {
                // Arrange
                var      invalidUserId   = 0;
                var      expirationDays  = "2";
                string   key             = "User_StatusCode_404_NotFound";
                var      localizedString = new LocalizedString(key, "Not Found");
                Contacts contact         = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(invalidUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"])
                .Returns(expirationDays);

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <NotFoundObjectResult>(result);
            }
예제 #2
0
 public ContactDetailViewModel()
 {
     ContactsService = new ContactServiceMock();
     SaveCommand     = new Command(
         async() => {
         if (IsNew)
         {
             using (UserDialogs.Instance.Loading("Loading"))
             {
                 await ContactsService.AddNewContact(new Contact()
                 {
                     Name = this.Name, Company = this.Company
                 });
                 await Shell.Current.GoToAsync("..");
             }
         }
         else
         {
             using (UserDialogs.Instance.Loading("Loading"))
             {
                 await ContactsService.EditContact(new Contact()
                 {
                     Id = this.Id, Name = this.Name, Company = this.Company
                 });
                 await Shell.Current.GoToAsync("..");
             }
         }
     }
         );
 }
예제 #3
0
        public ContactsViewModel()
        {
            ContactsService = new ContactServiceMock();

            AddCommand = new Command(
                async() =>
            {
                //await UserDialogs.Instance.AlertAsync("Add command");
                await Shell.Current.GoToAsync($"{nameof(ContactDetailPage)}?{nameof(ContactDetailViewModel.IsNew)}={true}");
            }
                );

            SelectedCommand = new Command <Contact>(async(contact) => {
                //await UserDialogs.Instance.AlertAsync("Selected command");
                await Shell.Current.GoToAsync($"{nameof(ContactDetailPage)}?{nameof(ContactDetailViewModel.IsNew)}={false}&{nameof(ContactDetailViewModel.ContactId)}={contact.Id}");
            });
        }
예제 #4
0
            public async void Should_return_createdObjectResult_when_phone_is_valid()
            {
                // Arrange
                var      validUserId    = 1;
                var      expirationDays = "2";
                Contacts contact        = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(validUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"]).Returns(expirationDays);

                ForgotPassword forgotPassword = new ForgotPassword()
                {
                    UserID        = validUserId,
                    OTPExpiryTime = DateTime.UtcNow.AddDays(Convert.ToInt16(expirationDays)),
                    ResetOTP      = ControllerUnderTest.GetOTP(),
                    ResetTime     = DateTime.UtcNow,
                    CreatedDate   = DateTime.UtcNow
                };

                var expectedResult = forgotPassword;

                UserServiceMock.Setup(y => y.CreateAsync(forgotPassword))
                .ReturnsAsync(expectedResult);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                // Assert
                Assert.IsType <CreatedResult>(result);
            }