Пример #1
0
        public void CreateShouldReturnNullIfValidUserGetModel()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldReturnNullIfValidUserGetModel))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var regValidator = new RegisterValidator();
                var crValidator  = new CreateValidator();
                var usersService = new UsersService(context, regValidator, crValidator, null, config);

                UserRole addUserRoleRegular = new UserRole
                {
                    Name        = "Regular",
                    Description = "Created for test"
                };
                context.UserRoles.Add(addUserRoleRegular);
                context.SaveChanges();

                var added1 = new Lab6.Viewmodels.UserPostModel
                {
                    FirstName = "firstName",
                    LastName  = "lastName",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******",
                    UserRole  = "Regular",
                };

                var userCreated = usersService.Create(added1);

                Assert.IsNull(userCreated);
            }
        }
Пример #2
0
        public void ValidUpsertShouldModifyFieldsValues()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidUpsertShouldModifyFieldsValues))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var crValidator  = new CreateValidator();
                var usersService = new UsersService(context, validator, crValidator, null, config);
                var added        = new Lab6.Viewmodels.UserPostModel
                {
                    FirstName = "Nume",
                    LastName  = "Prenume",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                usersService.Create(added);

                var updated = new Lab6.Models.User
                {
                    FirstName = "Alin",
                    LastName  = "Popescu",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var userUpdated = usersService.Upsert(1, updated);

                Assert.NotNull(userUpdated);
                Assert.AreEqual("Alin", userUpdated.FirstName);
                Assert.AreEqual("Popescu", userUpdated.LastName);
            }
        }
Пример #3
0
        public static User ToUser(UserPostModel user)
        {
            //UserRole role = Models.UserRole.Regular;

            if (user.UserRole == "UserManager")
            {
                //role = Models.UserRole.UserManager;
            }
            else if (user.UserRole == "Admin")
            {
                //role = Models.UserRole.Admin;
            }

            return(new User
            {
                FirstName = user.FirstName,
                LastName = user.LastName,
                Username = user.UserName,
                Email = user.Email,
                Password = ComputeSha256Hash(user.Password),
                //UserRole = role
            });
        }