public void DeactivateUserEndpointTests(UserEntityFactory entityFactory) { // Arrange var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); var deactivateQuery = JsonConvert.SerializeObject(new { Username = userEntity.EmailAddress }); var clientxsrf = ClientXsrf.GetValidClientAndxsrfTokenPair(_configure); var client = clientxsrf.client; client.BaseUrl = new Uri(_configure.BaseUrl + $"/api/account/deactivate"); var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; request.AddHeader("X-XSRF-TOKEN", clientxsrf.xsrfToken); request.AddHeader("Content-Type", "application/json"); request.AddParameter("query", deactivateQuery, ParameterType.RequestBody); // Act var response = client.Execute(request); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); var activatedInDatabase = UserHelper.GetUserFromDB(userEntity.Id).EmailConfirmed; Assert.False(activatedInDatabase); }
/// <summary> /// Finds the student users by company. /// </summary> /// <param name="companyId">The company id.</param> /// <param name="view">The view.</param> /// <returns></returns> public List <Model.Entities.User> FindStudentUsersByCompany(int companyId, int view) { List <Model.Entities.User> userList = new List <Model.Entities.User>(); try { IQueryable <User> userQuery = this.Context.Set <Student>() .Where(u => u.CompanyId.Equals(companyId)) .Include(s => s.CourseRegistrations) .Include(p => p.CourseRegistrations.Select(x => x.Course)) .OrderByDescending(u => u.Id); if (view != 0) { userQuery = userQuery.Take(view); } // Return Users userList = UserEntityFactory.CreateFromDataModel(userQuery.ToList(), ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(userList); }
public async Task InactivateAsync(long userId) { var userEntity = UserEntityFactory.Create(userId); userEntity.Inactivate(); await UserRepository.UpdatePartialAsync(userEntity.UserId, new { userEntity.Status }); await DatabaseUnitOfWork.SaveChangesAsync(); }
public void CreateValidRegisteredUserTests(UserEntityFactory entityFactory) { var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); var loginResponse = AttemptLogin(userEntity.EmailAddress, userEntity.Password); Assert.Equal(HttpStatusCode.OK, loginResponse.StatusCode); }
public async Task InactivateAsync(long userId) { var userEntity = UserEntityFactory.Create(userId); userEntity.Inactivate(); await UserRepository.UpdateStatusAsync(userEntity); await UnitOfWork.SaveChangesAsync(); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> public override Model.Entities.User Add(Model.Entities.User model) { User newEntity = UserEntityFactory.CreateFromDomainModel(model, ObjectMapper); DbEntityEntry entry = Context.Entry <User>(newEntity); if (entry.State == System.Data.Entity.EntityState.Detached) { Context.Entry <User>(newEntity).State = System.Data.Entity.EntityState.Added; Context.SaveChanges(); } return(UserEntityFactory.CreateFromDataModel(newEntity, ObjectMapper)); }
/// <summary> /// Finds the user by email id. /// </summary> /// <param name="emailId">The email id.</param> /// <returns></returns> public Model.Entities.User FindUserByEmailId(string emailId) { Model.Entities.User user = null; try { User userEntity = this.Context.Set <User>().FirstOrDefault(x => x.Email.ToLower() == emailId.ToLower()); user = UserEntityFactory.CreateFromDataModel(userEntity, ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(user); }
/// <summary> /// Finds the user by member ship id. /// </summary> /// <param name="membershipId">The membership id.</param> /// <returns></returns> public Model.Entities.User FindUserByMemberShipId(int membershipId) { Model.Entities.User user = null; try { IQueryable <User> users = this.Context.Set <User>().Where(p => p.Membership_Id == membershipId).Take(1); User userEntity = users.ToList().FirstOrDefault(); user = UserEntityFactory.CreateFromDataModel(userEntity, ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(user); }
public CommentService( BaseRepository <CommentEntity> commentRepository, BaseRepository <UserEntity> userRepository, IUserService userService, UserEntityFactory userEntityFactory, CommentFactory commentFactory, IMapper mapper) { _commentRepository = commentRepository; _userRepository = userRepository; _userService = userService; _userEntityFactory = userEntityFactory; _commentFactory = commentFactory; _mapper = mapper; }
/// <summary> /// Finds all. /// </summary> /// <returns></returns> public override IQueryable <Model.Entities.User> FindAll() { List <Model.Entities.User> userList = new List <Model.Entities.User>(); try { IQueryable <User> userQuery = this.Context.Set <User>().OrderByDescending(u => u.Id); // Return Users userList = UserEntityFactory.CreateFromDataModel(userQuery.ToList(), ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(userList.AsQueryable()); }
/// <summary> /// Finds the student by studentName. /// </summary> /// <param name="userName">The studentName</param> /// <returns>Student</returns> public Model.Entities.Student FindStudentByName(string studentName) { Model.Entities.Student student = null; try { Student studentEntity = this.Context.Set <Student>() .Where(u => (u.FirstName + " " + u.LastName).ToLower().Contains(studentName.ToLower())) .FirstOrDefault(); student = UserEntityFactory.CreateFromDataModel(studentEntity, ObjectMapper) as Model.Entities.Student; } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(student); }
public UserService( BaseRepository <UserEntity> userRepository, BaseRepository <OrderEntity> orderRepository, BaseRepository <UserStatisticEntity> userStatisticRepository, UserStatisticFactory userStatisticFactory, UserEntityFactory userEntityFactory, IMapper mapper, IHttpContextAccessor httpContextAccessor) { _userRepository = userRepository; _userEntityFactory = userEntityFactory; _mapper = mapper; _httpContextAccessor = httpContextAccessor; _userStatisticFactory = userStatisticFactory; _userStatisticRepository = userStatisticRepository; _orderRepository = orderRepository; }
public void RegistrationInvalidPasswordTests(UserEntityFactory userEntityFactory, string password, string expectedException) { var userEntity = userEntityFactory.Construct(); userEntity.Password = password; try { new Registration(userEntity, _output); } catch (AggregateException e) { var exceptionInList = e.InnerExceptions.Select(x => x.Message); Assert.Contains(expectedException, exceptionInList); return; } throw new Exception("User creation succeeded when it was expected to fail"); }
public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel) { var validation = new AddUserModelValidator().Validate(addUserModel); if (validation.IsError) { return(DataResult <long> .Error(validation.Message)); } addUserModel.SignIn = SignInService.CreateSignIn(addUserModel.SignIn); var userEntity = UserEntityFactory.Create(addUserModel); userEntity.Add(); await UserRepository.AddAsync(userEntity); await UnitOfWork.SaveChangesAsync(); return(DataResult <long> .Success(userEntity.UserId)); }
public async Task <IDataResult <long> > AddAsync(AddUserModel addUserModel) { var validation = new AddUserModelValidator().Valid(addUserModel); if (!validation.Success) { return(new ErrorDataResult <long>(validation.Message)); } UserDomainService.GenerateHash(addUserModel.SignIn); var userEntity = UserEntityFactory.Create(addUserModel); userEntity.Add(); await UserRepository.AddAsync(userEntity); await UnitOfWork.SaveChangesAsync(); return(new SuccessDataResult <long>(userEntity.UserId)); }
/// <summary> /// Updates the specified model. /// </summary> /// <param name="model">The model.</param> public override void Update(Model.Entities.User model) { // Detach existing Entity User existingEntity = Context.Set <User>().Find(ObjectMapper.GetEntityIdentifier <Model.Entities.User>(model)); System.Data.Entity.EntityState existingState = Context.Entry <User>(existingEntity).State; if (existingState != System.Data.Entity.EntityState.Detached) { Context.Entry <User>(existingEntity).State = System.Data.Entity.EntityState.Detached; } User updatedEntity = UserEntityFactory.CreateFromDomainModel(model, ObjectMapper); DbEntityEntry entry = Context.Entry <User>(updatedEntity); if (entry.State == System.Data.Entity.EntityState.Detached) { //Context.Set<User>().Attach(updatedEntity); Context.Entry <User>(updatedEntity).State = System.Data.Entity.EntityState.Modified; Context.SaveChanges(); } }
public void ResetPassword(UserEntityFactory entityFactory) { throw new SkipException("Test has been deprecated and will be replaced soon"); var userEntity = entityFactory.ConstructAndSave(_output); // send change password request and read token from locally saved email RequestResetPassword(userEntity.EmailAddress); var token = GetResetTokenFromEmail(userEntity.EmailAddress); // set the new password and check that it works var testPassword = "******"; SetNewPassword(token, userEntity.EmailAddress, testPassword); CheckPasswordChanged(userEntity.EmailAddress, testPassword, userEntity.Password); // set password back to original // TODO replace this with database delete user RequestResetPassword(userEntity.EmailAddress); token = GetResetTokenFromEmail(userEntity.EmailAddress); SetNewPassword(token, userEntity.EmailAddress, userEntity.Password); }
public void GetAllUsersEndpointTests(UserEntityFactory entityFactory) { // Arrange var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); // Endpoint requires sorting and pagination options to be supplied. var sortOptions = new[] { new { Path = "id", Descending = false } }; var paginationOptions = new { PageNo = 1, PageSize = 10 }; // Search query for the user entity that we have created. var searchConditions = new[] { new[] { new { comparison = "Like", path = "Email", value = new string[] { $"%{userEntity.EmailAddress}%" } } } }; // Add required sorting and pagination options, and the search for our created entity to the body of the query. var query = JsonConvert.SerializeObject(new { PaginationOptions = paginationOptions, SearchConditions = searchConditions, SortConditions = sortOptions }); var clientxsrf = ClientXsrf.GetValidClientAndxsrfTokenPair(_configure); var client = clientxsrf.client; client.BaseUrl = new Uri(_configure.BaseUrl + $"/api/account/users"); var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; request.AddHeader("X-XSRF-TOKEN", clientxsrf.xsrfToken); request.AddHeader("Content-Type", "application/json"); request.AddParameter("query", query, ParameterType.RequestBody); // Act var response = client.Execute(request); var returnedObject = JsonConvert.DeserializeObject <AccountController.UserListModel>(response.Content); // Assert Assert.Equal(userEntity.Id, returnedObject.Users.First().Id); }
/// <summary> /// Finds the student users by company. /// </summary> /// <param name="companyId">The company id.</param> /// <param name="view">The view.</param> /// <returns></returns> public List <Model.Entities.User> FindStudentUsersByCompany(int companyId, string filter) { List <Model.Entities.User> userList = new List <Model.Entities.User>(); try { IQueryable <User> userQuery; if (String.IsNullOrEmpty(filter)) { userQuery = this.Context.Set <Student>() .Where(u => u.CompanyId.Equals(companyId)) .Include(s => s.CourseRegistrations) .Include(p => p.CourseRegistrations.Select(x => x.Course)) .OrderByDescending(u => u.Id); } else { userQuery = this.Context.Set <Student>() .Where(u => u.CompanyId.Equals(companyId) && (u.FirstName.ToLower().Contains(filter.ToLower()) || u.LastName.ToLower().Contains(filter.ToLower()) || u.Email.ToLower().Contains(filter.ToLower()))) .Include(s => s.CourseRegistrations) .Include(p => p.CourseRegistrations.Select(x => x.Course)) .OrderByDescending(u => u.Id); } // Return Users userList = UserEntityFactory.CreateFromDataModel(userQuery.ToList(), ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(userList); }
public async Task <IResult> UpdateAsync(UpdateUserModel updateUserModel) { var validation = new UpdateUserModelValidator().Valid(updateUserModel); if (!validation.Success) { return(ErrorResult(validation.Message)); } var userEntity = await UserRepository.SelectAsync(updateUserModel.UserId); var userDomain = UserDomainFactory.Create(userEntity); userDomain.Update(updateUserModel); userEntity = UserEntityFactory.Create(userDomain); await UserRepository.UpdateAsync(userEntity.UserId, userEntity); await DatabaseUnitOfWork.SaveChangesAsync(); return(SuccessResult()); }
/// <summary> /// Finds the user by UserName. /// </summary> /// <param name="userName">The username</param> /// <returns></returns> public Model.Entities.User FindUserByUserName(string userName) { Model.Entities.User user = null; try { /*IQueryable<User> users = this.Context.Set<Student>() * .Where(u => u.UserName.ToLower().Equals(userName.ToLower())) * .Include(s => s.CourseRegistrations) * .Include(p => p.CourseRegistrations.Select(x => x.Course)) * .Take(1);*/ IQueryable <User> users = this.Context.Set <User>().Include(u => u.Roles) .Where(u => u.UserName.ToLower().Equals(userName.ToLower())) .Take(1); User userEntity = users.ToList().FirstOrDefault(); user = UserEntityFactory.CreateFromDataModel(userEntity, ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(user); }
public OrderService( BaseRepository <OrderEntity> orderRepository, BaseRepository <UserEntity> userRepository, BaseRepository <OrderItemEntity> orderItemRepository, BaseRepository <UserStatisticEntity> userStatisticRepository, UserEntityFactory userEntityFactory, OrderEntityFactory orderEntityFactory, OrderItemFactory orderItemFactory, IUserService userService, IMapper mapper, ILogger <OrderService> logger) { _orderRepository = orderRepository; _userRepository = userRepository; _userEntityFactory = userEntityFactory; _orderEntityFactory = orderEntityFactory; _orderItemFactory = orderItemFactory; _userService = userService; _mapper = mapper; _logger = logger; _userStatisticRepository = userStatisticRepository; _orderItemRepository = orderItemRepository; }
/// <summary> /// Finds the by. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public override Model.Entities.User FindBy(int id) { User entity = Context.Set <User>().Find(id); return(UserEntityFactory.CreateFromDataModel(entity, ObjectMapper)); }