Ejemplo n.º 1
0
 public static UserRole ToUserRole(UserRolePostModel userRolePost)
 {
     return(new UserRole
     {
         Name = userRolePost.Name,
         Description = userRolePost.Description
     });
 }
Ejemplo n.º 2
0
        public void ValidGetCurentRole()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetCurentRole))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, config);
                var added        = new Lab2Expense.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "fdsfsdfs",
                    LastName  = "fdsfs",
                    Password  = "******",
                    Username  = "******"
                };

                var userRoleService = new UserRoleService(context);
                var addedRole       = new Lab2Expense.ViewModels.UserRolePostModel
                {
                    Name        = "Regular",
                    Description = "jskds"
                };
                var result = userRoleService.Create(addedRole);

                var resultAdded          = usersService.Register(added);
                var resultAuthentificate = usersService.Authenticate(added.Username, added.Password);

                var user = context.Users.FirstOrDefault(u => u.Id == resultAuthentificate.Id);

                var userRole = usersService.GetCurrentUserRole(user);
                Assert.AreEqual("Regular", userRole.Name);
            }
        }