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);
            }
        }
        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);
            }
        }
        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());
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }