예제 #1
0
        public void GetAll_ReturnsListOfUserRoles()
        {
            var userRolesList = fixture.Create <IEnumerable <UserRole> >();

            mockUserRoleRepo.Setup(x => x.GetAll()).Returns(userRolesList);
            mockUserRoleService.Setup(x => x.GetAll()).Returns(userRolesList);

            var result = userRoleService.GetAll();

            mockUserRoleRepo.Verify(x => x.GetAll(), Times.Once());
            //mockUserRoleService.Verify(x => x.GetAll(), Times.Once());

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <IEnumerable <UserRole> >(result);
            Assert.IsNotEmpty(result);
        }
예제 #2
0
        /// <summary>
        /// This method is called when the page is loaded and paramters are set
        /// </summary>
        /// <returns></returns>
        protected async override Task OnParametersSetAsync()
        {
            Employee = await UserService.GetUser(EmployeeId);

            UserRoles = await UserRoleService.GetAll();

            await base.OnParametersSetAsync();
        }
예제 #3
0
        public override IHttpActionResult GetAll()
        {
            var result = UserRoleService.GetAll();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
예제 #4
0
        public void GetAll()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAll))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var roleService = new UserRoleService(context, config);
                var first       = new UserRolePostDto
                {
                    Name = "God"
                };
                var second = new UserRolePostDto
                {
                    Name = "Slave Master"
                };
                var third = new UserRolePostDto
                {
                    Name = "Matroana"
                };
                var fourth = new UserRolePostDto
                {
                    Name = "Shobolan"
                };
                var fifth = new UserRolePostDto
                {
                    Name = "Tod Howard"
                };
                roleService.Create(first);
                roleService.Create(second);
                roleService.Create(third);
                roleService.Create(fourth);
                roleService.Create(fifth);
                context.SaveChanges();

                PaginatedList <UserRoleGetDto> populated = roleService.GetAll(1);
                PaginatedList <UserRoleGetDto> empty     = roleService.GetAll(2);

                Assert.AreEqual(5, populated.Entries.Count);
                Assert.Zero(empty.Entries.Count);
            }
        }
        public ActionResult UserAuthorizationEdit(int userId, AuthorizationModel authorizationModel)
        {
            try
            {
                var oldUserRoles = UserRoleService.GetAll(userId);
                foreach (var authorization in oldUserRoles)
                {
                    UserRoleService.Delete(authorization.Id);
                }

                var userModules = authorizationModel.UserModules?.ToList();
                if (userModules != null)
                {
                    foreach (var item in userModules)
                    {
                        var a = new UserRole
                        {
                            ModuleId = item,
                            UserId   = userId
                        };
                        UserRoleService.Add(a);
                    }
                }

                var userRoles = authorizationModel.UserRoles?.ToList();
                if (userRoles != null)
                {
                    foreach (var item in userRoles)
                    {
                        var a = new UserRole
                        {
                            RoleId = item,
                            UserId = userId
                        };
                        UserRoleService.Add(a);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e);
            }
            return(RedirectToAction("UserList"));
        }
예제 #6
0
        public void ValidGetAll()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetAll))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                UserRoleService userRoleService = new UserRoleService(context);
                var             added           = new Labo2.ViewModels.UserRolePostModel
                {
                    Name        = "Regular",
                    Description = "regular description"
                };
                var result = userRoleService.GetAll();

                Assert.IsNotNull(result);
            }
        }
예제 #7
0
        public void GetAllShouldReturnUserRoles()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnUserRoles))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = userRoleService.Create(new ExamenNet.ViewModels.UserRolePostModel
                {
                    Name        = "Rol testare",
                    Description = "Creat pentru testare"
                });

                var allUsers = userRoleService.GetAll();
                Assert.IsNotNull(allUsers);
            }
        }
        public void GetAllShouldReturnAllUserRoles()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnAllUserRoles))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = new UserRolePostModel()
                {
                    Name        = "Newbegginer",
                    Description = "A role for a new guy..."
                };


                var current  = userRoleService.Create(addUserRole);
                var allUsers = userRoleService.GetAll();
                Assert.IsNotNull(allUsers);
                Assert.AreEqual(1, allUsers.Count());
            }
        }
예제 #9
0
        public IHttpActionResult GetAllRoles(int userId)
        {
            var results = _userRoleService.GetAll(userId);

            return(Ok(results));
        }
예제 #10
0
        /// <summary>
        /// This method is called when the page is loaded
        /// </summary>
        /// <returns></returns>
        protected async override Task OnInitializedAsync()
        {
            UserRoles = await UserRoleService.GetAll();

            await base.OnParametersSetAsync();
        }
예제 #11
0
 public IEnumerable <UserRoleViewModel> Get()
 {
     return(UserRoleService.GetAll());
 }