Exemple #1
0
        public void TestMethod02() // SP de valor nulo
        {
            string query         = null;
            String ConnectionStr = ConfigurationManager.AppSettings["ConnStr"];

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });

            String Code    = ErrorsAndExceptionsCatalog._602_Code;
            String Message = ErrorsAndExceptionsCatalog._602_StoredProdecureNotFound;
            DataAccessException resultEX = new DataAccessException();

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.StoredProcedure, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
Exemple #2
0
        public void TestMethod03() // query mal estructurado
        {
            string query         = "delect count(*) from Albums";
            String ConnectionStr = ConfigurationManager.AppSettings["ConnStr"];

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });

            String Code    = ErrorsAndExceptionsCatalog._603_Code;
            String Message = ErrorsAndExceptionsCatalog._603_InvalidQuery;
            DataAccessException resultEX = new DataAccessException();

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.Text, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
Exemple #3
0
        public void TestMethod013() // error no controlado
        {
            string query = "Select count(*) from Albums";

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });


            String ConnectionStr = "data source =./; initial catalog = MvcMusicStore; integrated security = True; MultipleActiveResultSets = True;";

            String Code    = ErrorsAndExceptionsCatalog._613_Code;
            String Message = ErrorsAndExceptionsCatalog._613_ErrorNotHandled;
            DataAccessException resultEX = new DataAccessException();

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.Text, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
Exemple #4
0
        public void TestMethod012() // conexion no establecida
        {
            string query         = "Select count(*) from Albums";
            String ConnectionStr = "sdfnksdf";

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });

            String Code    = ErrorsAndExceptionsCatalog._612_Code;
            String Message = ErrorsAndExceptionsCatalog._612_ConnectionFailed;
            DataAccessException resultEX = new DataAccessException();

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.Text, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
Exemple #5
0
        public void TestMethod06() // cadena de conexion mal estructurada
        {
            string query         = "Select count(*) from Albums";
            String ConnectionStr = "user/Caro";

            String Code    = ErrorsAndExceptionsCatalog._606_Code;
            String Message = ErrorsAndExceptionsCatalog._606__InvalidConnectionString;
            DataAccessException resultEX = new DataAccessException();

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.Text, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
Exemple #6
0
        public void TestMethod01() // SP mal estructurado
        {
            // var
            String ConnectionStr = ConfigurationManager.AppSettings["ConnStr"];

            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter()
            {
                ParameterName = "Caro"
            });

            String Code    = ErrorsAndExceptionsCatalog._601_Code;
            String Message = ErrorsAndExceptionsCatalog._601_InvalidStoredProcedure;
            DataAccessException resultEX = new DataAccessException();

            //act
            try
            {
                DataTable dt = DataAccessADO.GetDataTable("CountAlbums", CommandType.StoredProcedure, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }
            // arrange
            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }
        public JsonResult GetStoredProceduresFromSysObjects(string txt, int idProject)
        {
            string      query = "GetStoredProcedures";
            Tb_Projects tb    = db.Tb_Projects.Find(idProject);
            string      ConnStr;

            if (tb.LocalConnection.Value)
            {
                ConnStr = string.Format("data source=./;initial catalog={0};integrated security=True;MultipleActiveResultSets=True;App=EntityFramework", tb.ProjectDatabase);
            }
            else
            {
                ConnStr = string.Format("data source={0};initial catalog={1};persist security info=True;user id={2};password={3};multipleactiveresultsets=True;application name=EntityFramework", tb.Server, tb.ProjectDatabase, tb.ProjectUser, tb.Password);
            }

            //Parameters
            List <SqlParameter> listparams = new List <SqlParameter>();

            listparams.Add(new SqlParameter("txt", txt));

            List <SelectListItem> list = new List <SelectListItem>();

            DataTable dt = DataAccessADO.GetDataTable(query, CommandType.StoredProcedure, listparams, ConnStr, null);

            list = dt.AsEnumerable().Select(x => new SelectListItem()
            {
                Text = x.Field <string>("name"), Value = x.Field <string>("id")
            }).ToList();

            return(Json(list, JsonRequestBehavior.DenyGet));
        }
        public ActionResult Edit([Bind(Include = "ID_Object,ID_Context,ObjectName,Entity,ObjDescription,ID_AuxObject")] Tb_Objects tb_Objects, int idProject)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(tb_Objects).State = EntityState.Modified;
                    db.SaveChanges();


                    //Eliminamos de la base de datos los parametros agregados con anterioridad
                    List <Tb_Parameters> tbParameters = db.Tb_Parameters.Where(x => x.ID_Object == tb_Objects.ID_Object).ToList();
                    if (tbParameters.Count > 0)
                    {
                        db.Tb_Parameters.RemoveRange(tbParameters);
                        db.SaveChanges();
                    }

                    string      ConnStr;
                    Tb_Projects tb = db.Tb_Projects.Find(idProject);
                    if (tb.LocalConnection.Value)
                    {
                        ConnStr = string.Format("data source=./;initial catalog={0};integrated security=True;MultipleActiveResultSets=True;App=EntityFramework", tb.ProjectDatabase);
                    }
                    else
                    {
                        ConnStr = string.Format("data source={0};initial catalog={1};persist security info=True;user id={2};password={3};multipleactiveresultsets=True;application name=EntityFramework", tb.Server, tb.ProjectDatabase, tb.ProjectUser, tb.Password);
                    };

                    List <SqlParameter> queryParams = new List <SqlParameter>();
                    queryParams.Add(new SqlParameter("idObject", tb_Objects.ID_AuxObject));

                    List <Tb_Parameters> listparams = new List <Tb_Parameters>();
                    DataTable            dt         = DataAccessADO.GetDataTable("GetParametersFromSP", CommandType.StoredProcedure, queryParams, ConnStr, null);

                    listparams = dt.AsEnumerable().Select(x => new Tb_Parameters()
                    {
                        ParameterName = x.Field <string>("name"), DataType = x.Field <string>("name"), Length = x.Field <int>("max_length"), Presition = x.Field <int>("precision"), Nullable = x.Field <bool>("is_nullable"), IsOut = x.Field <bool>("is_output")
                    }).ToList();

                    for (var i = 0; i < listparams.Count; i++)
                    {
                        listparams[i].ID_Object = tb_Objects.ID_Object;
                    }
                    db.Tb_Parameters.AddRange(listparams);
                    db.SaveChanges();

                    return(RedirectToAction("Index", new { idContext = tb_Objects.ID_Context, idProject = idProject }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
            ViewBag.ID_Context = new SelectList(db.Tb_Contexts, "ID_Context", "ContextName", tb_Objects.ID_Context);
            return(View(tb_Objects));
        }
Exemple #9
0
        public void TestMethod014() // parametros nulos
        {
            string query         = "Select count(*) from Albums";
            String ConnectionStr = ConfigurationManager.AppSettings["ConnStr"];

            List <SqlParameter> listparams = new List <SqlParameter>();

            String Code    = ErrorsAndExceptionsCatalog._614_Code;
            String Message = ErrorsAndExceptionsCatalog._614_ParametersNotFound;
            DataAccessException resultEX = new DataAccessException();

            try
            {
                DataTable dt = DataAccessADO.GetDataTable(query, CommandType.Text, listparams, ConnectionStr, null);
            }
            catch (DataAccessException ex)
            {
                resultEX = ex;
            }

            Assert.AreEqual(Code, resultEX.code);
            Assert.AreEqual(Message, resultEX.messageCode);
        }