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); }
/// <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(); }
public override IHttpActionResult GetAll() { var result = UserRoleService.GetAll(); if (result == null) { return(NotFound()); } return(Ok(result)); }
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")); }
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); } }
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()); } }
public IHttpActionResult GetAllRoles(int userId) { var results = _userRoleService.GetAll(userId); return(Ok(results)); }
/// <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(); }
public IEnumerable <UserRoleViewModel> Get() { return(UserRoleService.GetAll()); }