Exemplo n.º 1
0
        public async Task AddRole_returns_error_string_when_role_has_special_characters()
        {
            //Arrange
            var controller = new RolesController(_configuration, _contextAccessor);

            Role role = new Role
            {
                Id   = new Guid(),
                Name = "Admin!@#$"
            };

            dynamic roleObj = new ExpandoObject();

            roleObj.Role = role;

            JObject data = JObject.FromObject(roleObj);

            //Act
            var result = await controller.AddRole(data);

            //Assert
            var messageResult = Assert.IsType <string>(result);                          //Asserting that the return is a String

            Assert.Contains("Name cannot be contain special characters", messageResult); //Asserting that message is equal as mentioned
        }
Exemplo n.º 2
0
        public async Task AddRole_returns_error_string_when_role_has_same_name()
        {
            //Arrange
            var controller = new RolesController(_bosAuthClient);

            Role role = new Role
            {
                Id   = new Guid(),
                Name = "Admin"
            };

            dynamic roleObj = new ExpandoObject();

            roleObj.Role = role;

            JObject data = JObject.FromObject(roleObj);

            //Act
            var result = await controller.AddRole(data);

            //Assert
            var messageResult = Assert.IsType <string>(result);                     //Asserting that the return is a String

            Assert.Contains("A role with that name already exists", messageResult); //Asserting that message is equal as mentioned
        }
Exemplo n.º 3
0
        public async Task AddRole_returns_error_string_when_data_is_null()
        {
            //Arrange
            var controller = new RolesController(_configuration, _contextAccessor);

            //Act
            var result = await controller.AddRole(null);

            //Assert
            var messageResult = Assert.IsType <string>(result);    //Asserting that the return is a String

            Assert.Contains("Data cannot be null", messageResult); //Asserting that message is equal as mentioned
        }
Exemplo n.º 4
0
        public async Task DeleteRole_returns_string_when_role_is_incorrect()
        {
            //Arrange
            var controller = new RolesController(_bosAuthClient);

            //Act
            var result = await controller.AddRole(null);

            //Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result); //Asserting that the return is a View

            Assert.Equal("Roles", redirectResult.ControllerName);                //Asseting that the returned Controller is "Role"
            Assert.Equal("Index", redirectResult.ActionName);                    //Asseting that the Action Methond of the controller is "Index"
        }
Exemplo n.º 5
0
        public async Task AddRole_returns_string_when_role_is_null()
        {
            //Arrange
            var controller = new RolesController(_configuration, _contextAccessor);

            dynamic roleObj = new ExpandoObject();
            JObject data    = JObject.FromObject(roleObj);

            //Act
            var result = await controller.AddRole(data);

            //Assert
            var messageResult = Assert.IsType <string>(result);                //Asserting that the return is a String

            Assert.Contains("The data for role is inaccurate", messageResult); //Asserting that message is equal as mentioned
        }