public override IHttpActionResult GetById(int id) { var result = UserRoleService.GetById(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public void GetByIdShouldReturnUserRole() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnUserRole)) .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 userRole = userRoleService.GetById(1); Assert.AreEqual("Rol testare", userRole.Name); } }
public void GetById() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetById)) .Options; using (var context = new ExpensesDbContext(options)) { var roleService = new UserRoleService(context, config); var toAdd = new UserRolePostDto { Name = "GOD" }; UserRole expected = roleService.Create(toAdd); UserRole actual = roleService.GetById(expected.Id); Assert.AreEqual(expected, actual); } }
public void Create() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(Create)) .Options; using (var context = new ExpensesDbContext(options)) { var roleService = new UserRoleService(context, config); var toAdd = new UserRolePostDto { Name = "GOD" }; UserRole role = roleService.Create(toAdd); Assert.AreEqual(toAdd.Name, role.Name); Assert.IsNotNull(roleService.GetById(role.Id)); } }
public void GetByIdShouldReturnAValidUserRole() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnAValidUserRole)) .Options; using (var context = new ExpensesDbContext(options)) { UserRoleService userRoleService = new UserRoleService(context); var addUserRole = new UserRolePostModel() { Name = "NewUser", Description = "New user added" }; var current = userRoleService.Create(addUserRole); var expected = userRoleService.GetById(current.Id); Assert.IsNotNull(expected); Assert.AreEqual(expected.Name, current.Name); Assert.AreEqual(expected.Id, current.Id); } }
public void GetByIdShouldReturnUserRoleWithCorrectId() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnUserRoleWithCorrectId)) .Options; using (var context = new TasksDbContext(options)) { var userRoleService = new UserRoleService(context); var addUserRole = new UserRolePostDTO() { Name = "Newcomer", Description = "A new guy..." }; var current = userRoleService.Create(addUserRole); var expected = userRoleService.GetById(current.Id); Assert.IsNotNull(expected); Assert.AreEqual(expected.Name, current.Name); Assert.AreEqual(expected.Id, current.Id); } }
public SysUsersRolesVw GetById(int id) { return(_service.GetById(id)); }
public IHttpActionResult GetById(int userId, int roleId) { var results = _userRoleService.GetById(userId, roleId); return(Ok(results)); }