Exemple #1
0
        public async Task <CustomerSignUpResponse> SignUpCustomerAsync(CustomerSignUpRequest userSignUpRequest)
        {
            CustomerSignUpResponse response = null;

            PhoneNumber          phoneNumber          = new PhoneNumber(userSignUpRequest.PhoneCode, userSignUpRequest.PhoneNumber);
            EmailAddress         emailAddress         = new EmailAddress(userSignUpRequest.EmailAddress);
            Password             password             = new Password(userSignUpRequest.Password);
            Customer             customer             = new Customer(emailAddress, phoneNumber, password);
            CustomerSignUpResult customerSignUpResult = await this.CustomerSignUpService.SignUpCustomerAsync(customer);

            if (customerSignUpResult.CustomerSignUpStatus == CustomerSignUpStatus.Registered)
            {
                await Task.Run(async() =>
                {
                    long otp = await GenerateOTPAsync(customerSignUpResult.CustomerId);
                    SMSService.SendSMS(string.Format(CustomerLiteral.PHONENUMBER_VERIFICATION_SMS, customer.PhoneNumber.PhoneNumberWithCode, otp)
                                       , customer.PhoneNumber.PhoneNumberWithCode);
                });
            }

            response = new CustomerSignUpResponse
            {
                CustomerId = customerSignUpResult.CustomerId
            };
            return(response);
        }
Exemple #2
0
        public async Task SignUpCustomerAysnc_success()
        {
            // arrange
            int      customerId = 1;
            long     otp        = 965876;
            DateTime validUpTo  = DateTime.UtcNow.AddMinutes(5);
            CustomerSignUpRequest userSignUpRequest = new CustomerSignUpRequest
            {
                EmailAddress = "*****@*****.**",
                Password     = "******",
                PhoneCode    = "+91",
                PhoneNumber  = "9544856521"
            };
            CustomerSignUpResult signUpResult = new CustomerSignUpResult(customerId);

            CustomerServiceMock.Setup(service => service.SignUpCustomerAsync(It.IsAny <Customer>())).Returns(Task.FromResult <CustomerSignUpResult>(signUpResult));
            SharedUtilitiesMock.Setup(utilities => utilities.GenerateOTPHaving(6)).Returns(otp);
            CustomerRepositoryMock.Setup(repository => repository.GenerateSignUpOTPAsync(It.IsAny <CustomerOTP>())).Returns(Task.FromResult <bool>(true));
            AccountService accountService = new AccountService(CustomerServiceMock.Object,
                                                               SMSServiceMock.Object,
                                                               CustomerRepositoryMock.Object,
                                                               SharedUtilitiesMock.Object,
                                                               LoggerMock.Object);

            // act
            CustomerSignUpResponse response = await accountService.SignUpCustomerAsync(userSignUpRequest);

            // assert
            Assert.Equal(customerId, response.CustomerId);
        }
        public async void SignUpCustomer_success()
        {
            Mock <IAccountService> accountServiceMock       = new Mock <IAccountService>();
            Mock <ILogger <CustomerController> > LoggerMock = new Mock <ILogger <CustomerController> >();
            Mock <IConfiguration> configurationMock         = new Mock <IConfiguration>();
            int customerId = 300;
            CustomerSignUpResponse response = new CustomerSignUpResponse
            {
                CustomerId = customerId
            };

            configurationMock.SetupGet(p => p["Application.BaseUri"]).Returns("https://*****:*****@thinkpalm.com",
                Password     = "******",
                PhoneCode    = "+91",
                PhoneNumber  = "9544856521"
            };

            var result = await customerController.SignUpCustomer(userSignUpRequest) as CreatedResult;


            Assert.Equal(typeof(CreatedResult), result.GetType());
            Assert.Equal($"https://localhost:44339/api/customer/{customerId}", result.Location);
            Assert.Equal(201, result.StatusCode);
            Assert.Equal(customerId, ((CustomerSignUpResponse)result.Value).CustomerId);
            Assert.True(((CustomerSignUpResponse)result.Value).TwoFARequired);
        }
Exemple #4
0
        public async Task <IActionResult> SignUpCustomer([FromBody] CustomerSignUpRequest userRequest)
        {
            Logger.LogInformation($"Registration request received with {userRequest.EmailAddress}");

            CustomerSignUpResponse response = await AccountService.SignUpCustomerAsync(userRequest);

            return(Created(GetPath($"/api/customer/{response.CustomerId}"), response));
        }