Ejemplo n.º 1
0
        public override IHttpActionResult GetById(int id)
        {
            var result = UserRoleService.GetById(id);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 public SysUsersRolesVw GetById(int id)
 {
     return(_service.GetById(id));
 }
Ejemplo n.º 8
0
        public IHttpActionResult GetById(int userId, int roleId)
        {
            var results = _userRoleService.GetById(userId, roleId);

            return(Ok(results));
        }