Example #1
0
        public List <MenuBean> getListMainMenu(string user)
        {
            List <MenuBean> lstRS = new List <MenuBean>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand    cmd = new SqlCommand(null, con);
                SqlDataReader rd  = null;
                cmd.CommandText = "SELECT m.id FROM menu m " +
                                  "where ((m.id in (select mr.menu_id from menu_role mr " +
                                  "				where role_id in (select uir.RoleId from aspnet_UsersInRoles uir, aspnet_Users u "+
                                  "									where u.UserId=uir.UserId and u.LoweredUserName=@userName))) "+
                                  "	or (m.secure_level<1)) and m.type = 0 and m.active > 0  order by m.[order]";
                Debug.WriteLine("Get list main menu: " + cmd.CommandText);
                cmd.Parameters.Add("@userName", System.Data.SqlDbType.NVarChar);
                cmd.Parameters["@userName"].Value = user;
                //SqlParameter parUserName = new SqlParameter();
                //parUserName.DbType = System.Data.DbType.String;
                //parUserName.Value = user;
                //parUserName.ParameterName = "@userName";
                //cmd.Parameters.Add(parUserName);
                con.Open();
                rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    MenuBean temp = loadMenu((int)rd["id"], user);
                    if (temp != null)
                    {
                        lstRS.Add(temp);
                    }
                }
            }
            return(lstRS);
        }
Example #2
0
        public static List <MenuBean> subObtenerDatosMenu(Int32 piIdPerfil)
        {
            List <MenuBean> loLstMenuBean = new List <MenuBean>();

            try
            {
                DataTable loDatatable = MenuModel.fnObtenerDatosMenu(piIdPerfil);
                MenuBean  loMenuBean;
                if (loDatatable != null && loDatatable.Rows.Count > 0)
                {
                    foreach (DataRow row in loDatatable.Rows)
                    {
                        loMenuBean             = new MenuBean();
                        loMenuBean.IdMenu      = row["idMenu"].ToString();
                        loMenuBean.IdMenuPadre = row["IdMenuPadre"].ToString();
                        loMenuBean.Descripcion = row["Descripcion"].ToString();
                        loMenuBean.UrlImagen   = row["UrlImagen"].ToString();
                        loMenuBean.Url         = row["Url"].ToString();
                        loMenuBean.Codigo      = row["Codigo"].ToString();
                        loLstMenuBean.Add(loMenuBean);
                    }
                }
            }
            catch (Exception)
            {
                // GUARDAR EN LOG
            }
            return(loLstMenuBean);
        }
Example #3
0
        private MenuBean loadMenu(int menuId, string user)
        {
            MenuBean rs = null;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand    cmd = new SqlCommand(null, con);
                SqlDataReader rd  = null;
                cmd.CommandText = "SELECT * FROM menu M WHERE M.id=@menuId";
                SqlParameter parMenuId = new SqlParameter();
                parMenuId.DbType        = System.Data.DbType.Int32;
                parMenuId.Value         = menuId;
                parMenuId.ParameterName = "menuId";
                cmd.Parameters.Add(parMenuId);
                con.Open();
                rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    rs = new MenuBean();
                    object objId = rd["id"];
                    rs.Id = (int)objId;
                    object objOrder = rd["order"];
                    rs.Order = (int)objOrder;
                    object objSecureLevel = rd["secure_level"];
                    rs.SecureLevel = (int)objSecureLevel;
                    object objSelectable = rd["selectable"];
                    int    selectable    = (int)objSelectable;
                    rs.Selectable = selectable > 0;
                    object objText = rd["text"];
                    rs.Text = objText != null ? (string)objText : "";
                    object objType = rd["type"];
                    rs.Type = (int)objType;
                    object objUrl = rd["url"];
                    rs.Url = !DBNull.Value.Equals(objUrl) ? (string)objUrl : "";
                }
            }
            if (rs != null)
            {
                rs.LstSub = loadChildrens(rs.Id, user);
                return(rs);
            }
            else
            {
                return(null);
            }
        }
Example #4
0
        private List<MenuItem> generateMenuChild(MenuBean bean)
        {
            List<MenuItem> lstRS = new List<MenuItem>();
            if (bean != null && bean.LstSub != null && bean.LstSub.Count > 0)
            {
                foreach (MenuBean it in bean.LstSub)
                {
                    MenuItem mt = new MenuItem();
                    mt.Text = it.Text;
                    mt.NavigateUrl = it.Url != null && it.Url.Trim().Length > 0 ? "~" + it.Url.Trim() : "#";
                    List<MenuItem> lstChild = generateMenuChild(it);
                    foreach (MenuItem c in lstChild)
                    {
                        mt.ChildItems.Add(c);
                    }
                    lstRS.Add(mt);
                }

            }
            return lstRS;
        }
 public void ShouldThrowExceptionForNullOptionElements()
 {
     IMenuBean bean = new MenuBean();
     bean.OptionElements = null;
 }
        public void ShouldNotBeEqual()
        {
            Mock<IWebElement> mockElementOne = new Mock<IWebElement>();
            Mock<IWebElement> mockElementTwo = new Mock<IWebElement>();

            IMenuBean beanOne = new MenuBean();
            IMenuBean beanTwo = new MenuBean();

            beanOne.ContentContainer = mockElementOne.Object;
            beanTwo.ContentContainer = mockElementTwo.Object;

            Assert.AreNotEqual(beanOne, beanTwo, "Beans with different container element references should not be " +
                "equal");

            beanTwo.ContentContainer = mockElementOne.Object;

            IList<IWebElement> optionsListOne = new List<IWebElement>();
            IList<IWebElement> optionsListTwo = new List<IWebElement>();
            Mock<IWebElement> mockOptionElementOne = new Mock<IWebElement>();
            Mock<IWebElement> mockOptionElementTwo = new Mock<IWebElement>();

            optionsListOne.Add(mockOptionElementOne.Object);
            optionsListTwo.Add(mockOptionElementTwo.Object);
            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreNotEqual(beanOne, beanTwo, "Beans with different lists of option elements should not be equal");

            beanTwo.OptionElements = optionsListOne;
            beanOne.ClickOptionWithJavascript = true;

            Assert.AreNotEqual(beanOne, beanTwo, "Beans with different Javascript click workaround values should not " +
                "be equal");
        }
        public void ShouldCallBaseForToString()
        {
            Mock<IWebElement> mockElement = new Mock<IWebElement>();

            IMenuBean bean = new MenuBean();
            bean.ContentContainer = mockElement.Object;

            Assert.AreEqual("MenuBean(ContentContainerBean(LoadableBean(Driver: null, LoadTimeout: 30), " +
                "ContentContainer: " + mockElement.Object.ToString() + "), ClickOptionWithJavascript: False, " +
                "OptionElements: System.Collections.Generic.List`1[OpenQA.Selenium.IWebElement])", bean.ToString());
        }
        public void ShouldCallBaseForHashCode()
        {
            IMenuBean bean = new MenuBean();
            IMenuBean beanToCompare = new MenuBean();

            Assert.AreEqual(bean.GetHashCode(), beanToCompare.GetHashCode(), "Hash codes for bean which have not had " +
                "setters called should be equal, but are not: " + bean.ToString() + ", " + beanToCompare.ToString());

            Mock<IWebElement> mockElement = new Mock<IWebElement>();

            bean.ContentContainer = mockElement.Object;
            Assert.AreNotEqual(bean.GetHashCode(), beanToCompare.GetHashCode(), "Hash codes for bean which have " +
                "different values for their container element fields should not be equal, but are: " +
                bean.ToString() + ", " + beanToCompare.ToString());

            beanToCompare.ContentContainer = mockElement.Object;
            Assert.AreEqual(bean.GetHashCode(), beanToCompare.GetHashCode(), "Hash codes for bean which have the " +
                "same container element should be equal, but are not: " + bean.ToString() + ", " +
                beanToCompare.ToString());
        }
        public void HashCodesShouldBeEqual()
        {
            IMenuBean beanOne = new MenuBean();
            IMenuBean beanTwo = new MenuBean();

            Mock<IWebElement> mockElement = new Mock<IWebElement>();

            beanOne.ContentContainer = mockElement.Object;
            beanTwo.ContentContainer = mockElement.Object;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same container element reference and same default JavaScript click " +
                "workaround value");

            beanOne.ClickOptionWithJavascript = true;
            beanTwo.ClickOptionWithJavascript = true;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same container element reference and same non-default JavaScript click " +
                "workaround value");

            beanOne = new MenuBean();
            beanTwo = new MenuBean();

            beanOne.ClickOptionWithJavascript = true;
            beanTwo.ClickOptionWithJavascript = true;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have null container element references and same non-default JavaScript click " +
                "workaround value");

            beanOne.ContentContainer = mockElement.Object;
            beanTwo.ContentContainer = mockElement.Object;

            List<IWebElement> optionsListOne = new List<IWebElement>();
            List<IWebElement> optionsListTwo = new List<IWebElement>();
            Mock<IWebElement> mockOptionElement = new Mock<IWebElement>();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListOne;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same contrainer element references and the same empty option elements list " +
                "reference");

            optionsListOne.Add(mockOptionElement.Object);

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same contrainer element references and the same non-empty option elements " +
                "list reference");

            optionsListTwo.Add(mockOptionElement.Object);
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same contrainer element references and two non-empty option elements list " +
                "references containing the same object");

            optionsListOne = new List<IWebElement>();
            optionsListTwo = new List<IWebElement>();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they have the same container element and two different empty option element list references");

            beanOne = new MenuBean();
            beanTwo = new MenuBean();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they both have null container element references and two different empty option element " +
                "list references");

            beanTwo.OptionElements = optionsListOne;

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they both have null container element references and the same empty option elements list " +
                "reference");

            beanTwo.OptionElements = optionsListTwo;
            optionsListOne.Add(mockOptionElement.Object);
            optionsListTwo.Add(mockOptionElement.Object);

            Assert.AreEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "The hash codes for two beans should be " +
                "equal if they both have null container element references and two non-empty option elements list " +
                "references containing the same object");
        }
        public void ShouldBeEqual()
        {
            IMenuBean beanOne = new MenuBean();
            IMenuBean beanTwo = new MenuBean();

            Assert.AreEqual(beanOne, beanTwo, "Two newly constructed beans should be equal before any setters are " +
                "invoked");

            Mock<IWebElement> mockElement = new Mock<IWebElement>();

            beanOne.ContentContainer = mockElement.Object;
            beanTwo.ContentContainer = mockElement.Object;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "reference and same default JavaScript click workaround value");

            beanOne.ClickOptionWithJavascript = true;
            beanTwo.ClickOptionWithJavascript = true;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "reference and same non-default JavaScript click workaround value");

            beanOne = new MenuBean();
            beanTwo = new MenuBean();

            beanOne.ClickOptionWithJavascript = true;
            beanTwo.ClickOptionWithJavascript = true;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have null container element " +
                "references and same non-default JavaScript click workaround value");

            beanOne.ContentContainer = mockElement.Object;
            beanTwo.ContentContainer = mockElement.Object;

            List<IWebElement> optionsListOne = new List<IWebElement>();
            List<IWebElement> optionsListTwo = new List<IWebElement>();
            Mock<IWebElement> mockOptionElement = new Mock<IWebElement>();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListOne;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "references and the same empty option elements list reference");

            optionsListOne.Add(mockOptionElement.Object);

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "references and the same non-empty option elements list reference");

            optionsListTwo.Add(mockOptionElement.Object);
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "references and two non-empty option elements list references containing the same object");

            optionsListOne = new List<IWebElement>();
            optionsListTwo = new List<IWebElement>();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they have the same container element " +
                "two different empty option element list references");

            beanOne = new MenuBean();
            beanTwo = new MenuBean();

            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they both have null container element " +
                "references and two different empty option element list references");

            beanTwo.OptionElements = optionsListOne;

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they both have null container element " +
                "references and the same empty option elements list reference");

            beanTwo.OptionElements = optionsListTwo;
            optionsListOne.Add(mockOptionElement.Object);
            optionsListTwo.Add(mockOptionElement.Object);

            Assert.AreEqual(beanOne, beanTwo, "Two beans should be equal if they both have null container element " +
                "references and two non-empty option elements list references containing the same object");
        }
        public void HashCodesShouldNotBeEqual()
        {
            Mock<IWebElement> mockElementOne = new Mock<IWebElement>();
            Mock<IWebElement> mockElementTwo = new Mock<IWebElement>();

            IMenuBean beanOne = new MenuBean();
            IMenuBean beanTwo = new MenuBean();

            beanOne.ContentContainer = mockElementOne.Object;
            beanTwo.ContentContainer = mockElementTwo.Object;

            Assert.AreNotEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "Beans with different container element " +
                "references should have different hash codes");

            beanTwo.ContentContainer = mockElementOne.Object;

            IList<IWebElement> optionsListOne = new List<IWebElement>();
            IList<IWebElement> optionsListTwo = new List<IWebElement>();
            Mock<IWebElement> mockOptionElementOne = new Mock<IWebElement>();
            Mock<IWebElement> mockOptionElementTwo = new Mock<IWebElement>();

            optionsListOne.Add(mockOptionElementOne.Object);
            optionsListTwo.Add(mockOptionElementTwo.Object);
            beanOne.OptionElements = optionsListOne;
            beanTwo.OptionElements = optionsListTwo;

            Assert.AreNotEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "Beans with different lists of option " +
                "elements should have different hash codes");

            beanTwo.OptionElements = optionsListOne;
            beanOne.ClickOptionWithJavascript = true;

            Assert.AreNotEqual(beanOne.GetHashCode(), beanTwo.GetHashCode(), "Beans with different Javascript click " +
                "workaround values should have different hash codes");
        }