Example #1
0
        public void ShouldAuthentificate()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ShouldAuthentificate))// "ValidRegisterShouldCreateANewUser")
                          .Options;

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

                var resultAuth = usersService.Authenticate(auth.Username, auth.Password);

                Assert.IsNotNull(resultAuth.Token);
            }
        }
Example #2
0
        public void ValidGetHistoryRole()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHistoryRole))// "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 resultAdded          = usersService.Register(added);
                var resultAuthentificate = usersService.Authenticate(added.Username, added.Password);



                var userRole = usersService.GetHistoryRoles(resultAuthentificate.Id);
                Assert.IsNotNull(userRole);
            }
        }
Example #3
0
        public void ValidDeleteIsRemovedShoulBeTrue()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteIsRemovedShoulBeTrue))// "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 resultAdded  = usersService.Register(added);
                var resultAuth   = usersService.Authenticate(added.Username, added.Password);
                var resultDelete = usersService.Delete(resultAuth.Id);
                var resultNull   = usersService.Delete(238);
                Assert.IsNull(resultNull);

                Assert.AreEqual(true, resultDelete.isRemoved);
            }
        }
Example #4
0
        public void ValidRegisterShouldCreateANewUser()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser")
                          .Options;
            var validator = new RegisterValidator();

            using (var context = new ExpensesDbContext(options))
            {
                UsersService usersService = new UsersService(context, validator, config);
                var          added        = new Lab2Expense.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "fdsfsdfs",
                    LastName  = "fdsfs",
                    Password  = "******",
                    Username  = "******"
                };
                var result     = usersService.Register(added);
                var addedAgain = new Lab2Expense.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "fdsfsdfs",
                    LastName  = "fdsfs",
                    Password  = "******",
                    Username  = "******"
                };
                var resultAgain = usersService.Register(addedAgain);
                ErrorsCollection errorsCollection = new ErrorsCollection
                {
                    Entity        = nameof(RegisterPostModel),
                    ErrorMessages = new List <string> {
                        "The password must contain at least two digits!"
                    }
                };
                //  Assert.AreEqual(errorsCollection, resultAgain);

                Assert.IsNull(result);
                //   Assert.AreEqual(added.Username, result.Username);
            }
        }
Example #5
0
        public void ValidGetAll()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetAll))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new Lab2Expense.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "fdsfsdfs",
                    LastName  = "fdsfs",
                    Password  = "******",
                    Username  = "******"
                };
                var result = usersService.GetAll();
                Assert.IsNotNull(result);
            }
        }
Example #6
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);
            }
        }