public RolesControllerTests()
        {
            validator = Substitute.For<IRoleValidator>();
            service = Substitute.For<IRoleService>();
            role = new RoleView();

            controller = Substitute.ForPartsOf<RolesController>(validator, service);
            controller.ControllerContext = new ControllerContext();
            controller.ControllerContext.RouteData = new RouteData();
        }
Example #2
0
        public void Init()
        {
            _ctrl = new RolesController(new FakeRolesRepository());

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/be/api");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "roles" } });

            _ctrl.ControllerContext = new HttpControllerContext(config, routeData, request);
            _ctrl.Request = request;
            _ctrl.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
        }
Example #3
0
        public static void Populate(this DropDownList ddl, DropDownType type, string defaultSelectionValue = null, bool retainFirst = false)
        {
            switch (type)
            {
                case DropDownType.Role:
                    using (RolesController rc = new RolesController())
                    {
                        var roles = rc.Get().Select(i => new { Label = i.RoleName, Value = i.RoleID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = roles;
                    }
                    break;

                case DropDownType.ScopeType:
                    using (ScopesController sc = new ScopesController())
                    {
                        var scopes = sc.Get().Select(i => new { Label = i.ScopeName, Value = i.ScopeID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = scopes;
                    }
                    break;

                case DropDownType.Permission:
                    using (PermissionsController pc = new PermissionsController())
                    {
                        var permissions = pc.Get().Select(i => new { Label = i.PermissionName, Value = i.PermissionID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = permissions;
                    }
                    break;

                default: break;
            }

            Reset(ddl, retainFirst);
            ddl.DataValueField = "Value";
            ddl.DataTextField = "Label";
            ddl.DataBind();

            SelectDefault(ddl, defaultSelectionValue);
        }
 public void SetUp()
 {
     rolesController = new RolesController();
     userId = 2;
 }