Example #1
0
        public void TestSelfRegisterUserAsync()
        {
            //Arrange
            IWorkFlowDbContext dbContext = new WorkFlowDbContext();


            var fixture = new SelfRegistrationServiceFixture()
                          .BuildSelfRegistrationServiceFixture()
                          .BuildWorkFlowDbContextFactory(dbContext);

            SelfRegistrationDto selfRegistrationDto = null;

            //Act
            fixture.Service.SelfRegisterUserAsync(selfRegistrationDto);

            //Assert
            Mock.Get(fixture.dbFactory).Verify(f => f.CreateContext(), Times.AtLeastOnce);
        }
Example #2
0
        public async Task SelfRegisterUserAsync(SelfRegistrationDto selfRegistrationDto)
        {
            using (IWorkFlowDbContext context = _db.CreateContext())
            {
                if (selfRegistrationDto == null)
                {
                    throw new ArgumentNullException();
                }

                var token = await context.RegistrationToken
                            .FirstOrDefaultAsync(rt => rt.Token == selfRegistrationDto.RegistrationToken);

                if (token == null)
                {
                    throw new ArgumentNullException();
                }

                string salt         = _hasher.GenerateSalt();
                string passwordHash = _hasher.ComputeHash(selfRegistrationDto.Password, salt);

                var userId = token.UserId;

                var user = await context.UserInformation
                           .FirstOrDefaultAsync(ui => ui.UserId == userId);

                if (user != null)
                {
                    user.Password    = passwordHash;
                    user.Salt        = salt;
                    user.Name        = selfRegistrationDto.FirstName;
                    user.SurName     = selfRegistrationDto.LastName;
                    user.Address     = selfRegistrationDto.Address;
                    user.PhoneNumber = selfRegistrationDto.PhoneNumber;
                    user.IsConfirmed = true;
                    context.RegistrationToken.Remove(token);
                    await context.SaveChangesAsync();
                }
                else
                {
                    throw new ArgumentNullException();
                }
            }
        }
        public async Task <HttpResponseMessage> SelfRegister(SelfRegistrationDto selfRegistrationModel)
        {
            await _service.SelfRegisterUserAsync(selfRegistrationModel);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }