Exemplo n.º 1
0
        public void GetAllShouldReturnAllUser()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogInAUser))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result = usersService.Register(added);

                var users = usersService.GetAll();

                Assert.IsNotEmpty(users);
                Assert.AreEqual(1, users.Count());
                //Assert.IsEmpty(users);
            }
        }
Exemplo n.º 2
0
        public void AuthenticateShouldLogInAUser()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogInAUser))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result        = usersService.Register(added);
                var authenticated = new LabIV.DTO.LoginPostDTO
                {
                    Username = "******",
                    Password = "******"
                };
                var authresult = usersService.Authenticate(added.Username, added.Password);

                Assert.IsNotNull(authresult);
                Assert.AreEqual(1, authresult.Id);
                Assert.AreEqual(authenticated.Username, authresult.Username);
            }
        }
Exemplo n.º 3
0
        public void InvalidRegisterShouldReturnErrorsCollection()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(InvalidRegisterShouldReturnErrorsCollection))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, null, config);
                var added        = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var result = usersService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.ErrorMessages.Count());
            }
        }
Exemplo n.º 4
0
        public void AuthenticateShouldLogInAUser()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogInAUser))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var validator           = new RegisterValidator();
                var validatorUser       = new UserRoleValidator();
                var userUserRoleService = new UserUserRolesService(validatorUser, context);
                var usersService        = new UsersService(context, validator, null, userUserRoleService, config);

                UserRole addUserRoleRegular = new UserRole
                {
                    Name        = "Regular",
                    Description = "For testing..."
                };
                context.UserRoles.Add(addUserRoleRegular);
                context.SaveChanges();


                var added = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result        = usersService.Register(added);
                var authenticated = new LabIV.DTO.LoginPostDTO
                {
                    Username = "******",
                    Password = "******"
                };
                var authresult = usersService.Authenticate(added.Username, added.Password);

                Assert.IsNotNull(authresult);
                Assert.AreEqual(1, authresult.Id);
                Assert.AreEqual(authenticated.Username, authresult.Username);
            }
        }
Exemplo n.º 5
0
        public void GetAllShouldReturnAllUser()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogInAUser))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, null, config);
                var added        = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var added1 = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Maria",
                    LastName  = "Popa",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                usersService.Register(added);
                usersService.Register(added1);

                var users = usersService.GetAll().Count();

                Assert.NotZero(users);
                Assert.AreEqual(2, users);
            }
        }
Exemplo n.º 6
0
        public void ValidRegisterShouldCreateANewUser()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new LabIV.DTO.RegisterPostDTO

                {
                    FirstName = "Julia",
                    LastName  = "Bush",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result = usersService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(added.Username, result.Username);
            }
        }