Ejemplo n.º 1
0
        public void InvalidRegisterShouldReturnErrorsCollection()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(InvalidRegisterShouldReturnErrorsCollection))
                          .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.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "lastName1",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"   //invalid password should invalidate register
                };

                var result = usersService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.ErrorMessages.Count());
            }
        }
Ejemplo n.º 2
0
        public void ValidDeleteShouldRemoveTheUser()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteShouldRemoveTheUser))
                          .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.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "firstName1",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var userCreated = usersService.Register(added);

                Assert.NotNull(userCreated);

                //Assert.AreEqual(0, usersService.GetAll().Count());

                var userDeleted = usersService.Delete(1);

                Assert.Null(userDeleted);
                Assert.AreEqual(0, usersService.GetAll().Count());
            }
        }
Ejemplo n.º 3
0
        public void GetByIdShouldReturnAnValidUser()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnAnValidUser))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var regValidator = new RegisterValidator();
                var crValidator  = new CreateValidator();
                var usersService = new UsersService(context, regValidator, crValidator, null, config);
                var added1       = new Lab6.Viewmodels.RegisterPostModel
                {
                    FirstName = "firstName",
                    LastName  = "lastName",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                usersService.Register(added1);
                var userById = usersService.GetById(1);

                Assert.NotNull(userById);
                Assert.AreEqual("firstName", userById.FirstName);
            }
        }
Ejemplo n.º 4
0
        public void AuthenticateShouldLoginTheRegisteredUser()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginTheRegisteredUser))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var validator           = new RegisterValidator();
                var validatorUser       = new UserRoleValidator();
                var crValidator         = new CreateValidator();
                var userUserRoleService = new UserUserRoleService(validatorUser, context);
                var usersService        = new UsersService(context, validator, crValidator, userUserRoleService, config);

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

                var added = new Lab6.Viewmodels.RegisterPostModel
                {
                    FirstName = "Catalin",
                    LastName  = "Albulescu",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******",
                };
                var result = usersService.Register(added);

                var authenticated = new Lab6.Viewmodels.LoginPostModel
                {
                    Username = "******",
                    Password = "******"
                };
                //valid authentification
                var authresult = usersService.Authenticate(added.Username, added.Password);

                Assert.IsNotNull(authresult);
                Assert.AreEqual(1, authresult.Id);
                Assert.AreEqual(authenticated.Username, authresult.Username);

                //invalid user authentification
                //var authresult1 = usersService.Authenticate("unknown", "abcdefg");
                //Assert.IsNull(authresult1);
            }
        }
Ejemplo n.º 5
0
        public void GetCurentUserShouldReturnAccesToKlaims()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetCurentUserShouldReturnAccesToKlaims))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var regValidator        = new RegisterValidator();
                var crValidator         = new CreateValidator();
                var validatorUser       = new UserRoleValidator();
                var userUserRoleService = new UserUserRoleService(validatorUser, context);
                var usersService        = new UsersService(context, regValidator, crValidator, userUserRoleService, config);

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

                var added = new Lab6.Viewmodels.RegisterPostModel
                {
                    FirstName = "firstName",
                    LastName  = "lastName",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result = usersService.Register(added);

                var authenticated = new Lab6.Viewmodels.LoginPostModel
                {
                    Username = "******",
                    Password = "******"
                };
                var authresult = usersService.Authenticate(added.Username, added.Password);


                //usersService.GetCurentUser(httpContext);

                Assert.IsNotNull(authresult);
            }
        }
Ejemplo n.º 6
0
        public void ValidGetAllShouldReturnAllRegisteredUsers()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetAllShouldReturnAllRegisteredUsers))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var regValidator = new RegisterValidator();
                var crValidator  = new CreateValidator();
                var usersService = new UsersService(context, regValidator, crValidator, null, config);
                var added1       = new Lab6.Viewmodels.RegisterPostModel
                {
                    FirstName = "Catalin",
                    LastName  = "Albulescu",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******",
                };
                var added2 = new Lab6.Viewmodels.RegisterPostModel
                {
                    FirstName = "testfname",
                    LastName  = "testsname",
                    Username  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                usersService.Register(added1);
                usersService.Register(added2);

                int numberOfElements = usersService.GetAll().Count();

                Assert.NotZero(numberOfElements);
                Assert.AreEqual(2, numberOfElements);
            }
        }