public UserTest() { var faker = new Faker(); userViewModel = new UserViewModel() { Email = "*****@*****.**", Hash = HashMD5.getMD5("1"), Name = "faker user", Password = "******", Role = 1 }; loginViewModel = new LoginViewModel() { Login = "******", Password = "******" }; //auto mapper configuration var profiles = new List<Profile>() { new EntityToViewModelMapping(), new ViewModelToEntityMapping() }; var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfiles(profiles); }); _mapper = mockMapper.CreateMapper(); _user = new Mock<IUser>(); _userApplication = new UserApplication(_user.Object, _mapper); }
public static void Initializer(BaseContext context) { if (context.User.Any() && context.Article.Any()) { return; } else { var defaultUser = new User(); defaultUser.Name = "Admin"; defaultUser.Email = "*****@*****.**"; defaultUser.Hash = HashMD5.getMD5("*****@*****.**"); defaultUser.Password = HashMD5.getMD5("123456"); defaultUser.Role = (int)RoleType.Admin; context.Add(defaultUser); context.SaveChanges(); var defaultArticle = new Article(); defaultArticle.PublishedDate = DateTime.Now; defaultArticle.Text = "New Text"; defaultArticle.Title = "Same Title"; defaultArticle.User = context.User.FirstOrDefault(); context.Add(defaultArticle); context.SaveChanges(); var like = new ArticleLikes(); like.Article = context.Article.FirstOrDefault(); like.User = context.User.FirstOrDefault(); context.Add(like); context.SaveChanges(); } }
public async Task <Usuario> Authenticate(string login, string senha) { var usuario = await _dbSet.Where(x => x.Login == login && x.Senha == HashMD5.getMD5(senha)) .OrderByDescending(x => x.DataAtivacao) .Include(x => x.Pessoa) .FirstOrDefaultAsync(); return(usuario); }
public async Task <bool> Create(CreateUserViewModel model) { var user = new User(); user.Name = "Admin"; user.Email = model.Email; user.Hash = HashMD5.getMD5(model.Email + model.Password + DateTime.Now); user.Password = HashMD5.getMD5(model.Password); user.Role = (int)RoleType.Admin; await _user.Add(user); return(true); }
public static void Initializer(BaseContext context) { if (context.User.Any()) { return; } else { var defaultUser = new User(); defaultUser.Name = "Admin"; defaultUser.Email = "*****@*****.**"; defaultUser.Hash = HashMD5.getMD5("*****@*****.**"); defaultUser.Password = HashMD5.getMD5("123456"); defaultUser.Role = (int)RoleUser.Administrator; context.Add(defaultUser); context.SaveChanges(); } }
public async Task <RegistrarViewModel> Create(RegistrarViewModel model) { var pessoa = new Pessoa(); pessoa.Nome = model.Nome; pessoa.Email = model.Email; pessoa.IdCidade = model.IdCidade; await _pessoa.Add(pessoa); var usuario = new Usuario(); usuario.Login = model.Email; usuario.Senha = HashMD5.getMD5(model.Senha); usuario.DataAtivacao = DateTime.Now; usuario.Pessoa = pessoa; await _usuario.Add(usuario); return(model); }
public async Task <User> Authenticate(string email, string password) => await _dbSet.Where(x => x.Email == email && x.Password == HashMD5.getMD5(password)).FirstOrDefaultAsync();