public PersonaControllerTest()
        {
            List <EFPersona> table = new List <EFPersona>();

            mockSet = EFMockHelper <EFPersona, fiscaliaEntities> .getMockedSet(table);

            mockContext = new Mock <fiscaliaEntities>();
            mockContext.Setup(c => c.EFPersonas).Returns(mockSet.Object);
            // este es porque el Servicio usa Genericos
            mockContext.Setup(m => m.Set <EFPersona>()).Returns(mockSet.Object);
            mockContext.Object.EFPersonas.Add(
                new EFPersona
            {
                id              = 1,
                nombre          = "Loco",
                apellido        = "Del Coco",
                sexo            = true,
                numeroDocumento = 66666
            });
            mockContext.Object.EFPersonas.Add(
                new EFPersona
            {
                id              = 2,
                nombre          = "Chiflado",
                apellido        = "Del Coco",
                sexo            = true,
                numeroDocumento = 66666
            });

            //Test
            entityFrameworkService = new EntityFrameworkService <DataModel.fiscaliaEntities>(mockContext.Object);
        }
예제 #2
0
        public ServiceQueryTest()
        {
            var table = new List <EFPersona>();

            mockSet = EFMockHelper <EFPersona, fiscaliaEntities> .getMockedSet(table);

            mockContext = new Mock <fiscaliaEntities>();
            mockContext.Setup(c => c.EFPersonas).Returns(mockSet.Object);
            // este es porque el Servicio usa Genericos
            mockContext.Setup(m => m.Set <EFPersona>()).Returns(mockSet.Object);
            service = new EntityFrameworkService <DataModel.fiscaliaEntities>(mockContext.Object);
        }
        // Todo: This method is duplicated with the ViewGenerator.
        private async Task <ModelTypeAndContextModel> ValidateModelAndGetMetadata(CommonCommandLineModel commandLineModel)
        {
            ModelType model       = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", ModelTypesLocator);
            ModelType dataContext = ValidationUtil.ValidateType(commandLineModel.DataContextClass, "dataContext", ModelTypesLocator, throwWhenNotFound: false);

            // Validation successful
            Contract.Assert(model != null, CodeGenerators.Mvc.MessageStrings.ValidationSuccessfull_modelUnset);

            var dbContextFullName = dataContext != null ? dataContext.FullName : commandLineModel.DataContextClass;

            var modelMetadata = await EntityFrameworkService.GetModelMetadata(
                dbContextFullName,
                model);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                DbContextFullName = dbContextFullName,
                ContextProcessingResult = modelMetadata
            });
        }
예제 #4
0
        private async void cmd_grabar()
        {
            _entityFrameworkService = new EntityFrameworkService();

            try
            {
                var producto = new Producto();


                producto.prod_codi   = textcodigo.Text;
                producto.prod_descr  = textnombre.Text;
                producto.prod_unid   = combounidad.SelectedItem.ToString();
                producto.prod_stock  = textcantidad.Text;
                producto.prod_precio = textprecio.Text;



                textcodigo.Text   = "";
                textnombre.Text   = "";
                textprecio.Text   = "";
                textcantidad.Text = "";

                // _entityFrameworkService.ProductoInse(producto);



                data.Insert <Producto>(producto);

                await   DisplayAlert("System", "Producto agregado con exito", "ok");

                //Alerta.Text = "Producto agregado con exito";
                var result = data.GetList <Producto>(false);
            }
            catch (Exception ex)
            {
                await  DisplayAlert("System", ex.Message, "ok");
            }
        }
예제 #5
0
        public override async Task <EmbededViewResult> Execute()
        {
            Model            = new EFRunSqlModel();
            Model.DbContexts = _entityFrameworkCoreService.GetDbContexts(this.HttpContext);

            if (this.HttpContext.Request.Query.ContainsKey("EFExecutedDbCommand"))
            {
                var efExecutedDbCommand = this.HttpContext.Request.Query["EFExecutedDbCommand"].ToString().Trim();
                var decodedSql          = _entityFrameworkCoreService.DecodeSqlFromLogEntry(efExecutedDbCommand);
                return(new EmbededViewRedirectResult(Url.Link("/EFRunSql", new { _sql = decodedSql })));
            }

            string appDbContext = null;

            if (this.HttpContext.Request.Query.ContainsKey("_dbContext"))
            {
                appDbContext = this.HttpContext.Request.Query["_dbContext"].ToString().Trim();
            }
            Model.DbContext = appDbContext;

            if (string.Equals(this.HttpContext.Request.Method, "POST", StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    string sql = this.HttpContext.Request.Form["_sql"];
                    appDbContext = this.HttpContext.Request.Form["_dbContext"];

                    var results = new EntityFrameworkService().RunSql(this.HttpContext, appDbContext, sql);
                    return(await Json(JsonConvert.SerializeObject(results)));
                } catch (Exception ex)
                {
                    return(await Json(JsonConvert.SerializeObject(new { Error = ex.Message })));
                }
            }

            return(await View());
        }
예제 #6
0
        private async void cmd_grabar()
        {
            _entityFrameworkService = new EntityFrameworkService();
            DataAcces data = new DataAcces();

            try
            {
                var cliente = new Cliente();


                cliente.tipodocu  = combotipodocu.SelectedItem.ToString();
                cliente.nombres   = textnombre.Text;
                cliente.documento = textdocu.Text;
                cliente.direccion = textdireccion.Text;
                cliente.email     = textemail.Text;
                cliente.celular   = textcelular.Text;

                textdireccion.Text = "";
                textnombre.Text    = "";
                textdocu.Text      = "";
                textemail.Text     = "";
                textcelular.Text   = "";

                // _entityFrameworkService.ClienteInse(cliente);

                data.Insert <Cliente>(cliente);

                await DisplayAlert("System", "Cliente agregado con exito", "ok");

                //Alerta.Text = "Producto agregado con exito";
                var result = data.GetList <Cliente>(false);
            }
            catch (Exception ex)
            {
                await DisplayAlert("System", ex.Message, "ok");
            }
        }
예제 #7
0
        public void CreatePersonas()
        {
            var mockSet     = new Mock <DbSet <EFPersona> >();
            var mockContext = new Mock <fiscaliaEntities>();

            mockContext.Setup(m => m.EFPersonas).Returns(mockSet.Object);
            mockContext.Setup(m => m.Set <EFPersona>()).Returns(mockSet.Object);

            var service      = new EntityFrameworkService <DataModel.fiscaliaEntities>(mockContext.Object);
            var personaNueva = new PersonaModel
            {
                nombre          = "Loco",
                apellido        = "Del Coco",
                sexo            = true,
                numeroDocumento = 66666
            };
            int idPersonaNueva = service.CreatePersonas(personaNueva);

            // test verifies that the service added a new Persona
            mockSet.Verify(m => m.Add(It.IsAny <EFPersona>()), Times.Once());

            // test that service called SaveChanges on the context
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
예제 #8
0
        static void Main(string[] args)
        {
            var servicio = new DataModel.Service.EntityFrameworkService <DataModel.fiscaliaEntities>(new DataModel.fiscaliaEntities());
            var personas = servicio.GetPersonaApellido("Gonzalez");
            //foreach (PersonaModel p in personas)
            //{
            //    Console.WriteLine(p.apellido + ", " + p.nombre);
            //}

            //var personaNueva = new PersonaModel
            //{
            //    id = 3,
            //    nombre = "Loco",
            //    apellido = "Del Coco",
            //    sexo = true,
            //    numeroDocumento = 66666
            //};
            //int idPersonaNueva = servicio.CreatePersonas(personaNueva);

            //var ape = servicio.GetPersonaApellido("Del Coco");
            //bool wasDeleted = servicio.DeletePersonaById(638282);

            ////ninject
            //Ninject.IKernel kernal = new StandardKernel();
            //kernal.Bind<IService>().To<EntityFrameworkService<fiscaliaEntities>>();
            //var instance = kernal.Get<EntityFrameworkService<fiscaliaEntities>>();
            //instance.GetPersonaApellido("Del Coco");
            //Console.ReadLine();

            List <EFPersona> table = new List <EFPersona>();
            var mockSet            = EFMockHelper <EFPersona, fiscaliaEntities> .getMockedSet(table);

            var mockedDbContext = new Mock <fiscaliaEntities>();

            mockedDbContext.Setup(c => c.EFPersonas).Returns(mockSet.Object);
            // este es porque el Servicio usa Genericos
            mockedDbContext.Setup(m => m.Set <EFPersona>()).Returns(mockSet.Object);

            mockedDbContext.Object.EFPersonas.Add(
                new EFPersona
            {
                id              = 1,
                nombre          = "Loco",
                apellido        = "Del Coco",
                sexo            = true,
                numeroDocumento = 66666
            });
            mockedDbContext.Object.EFPersonas.Add(
                new EFPersona
            {
                id              = 2,
                nombre          = "Chiflado",
                apellido        = "Del Coco",
                sexo            = true,
                numeroDocumento = 66666
            });
            //Test
            var service = new EntityFrameworkService <DataModel.fiscaliaEntities>(mockedDbContext.Object);
            //delete
            bool wasDeleted = service.DeletePersonaById(1);
        }
예제 #9
0
        public override async Task <EmbededViewResult> Execute()
        {
            Model = new EFEntityEditorModel();

            var contextName = this.HttpContext.Request.Query.FirstOrDefault(x => x.Key == "_dbContext").Value.ToString().Trim();
            var entityName  = this.HttpContext.Request.Query.FirstOrDefault(x => x.Key == "_entity").Value.ToString().Trim();
            var entityInfo  = new EntityFrameworkService()
                              .GetDbContexts(this.HttpContext)
                              .FirstOrDefault(x => x.Name == contextName)
                              .Entities
                              .FirstOrDefault(x => x.ClrTypeName == entityName);

            Model.EntityName      = entityName;
            Model.EntityNamePart1 = string.Join(".", entityName?.Split(".").Reverse().Skip(1).Reverse());
            Model.EntityNamePart2 = entityName?.Split(".").Last();

            var fieldsValues = new Dictionary <string, string>();

            var pkValues = this.HttpContext.Request.Query
                           .Where(x => x.Key.StartsWith("_") == false && string.IsNullOrEmpty(x.Value.FirstOrDefault()) == false)
                           .ToDictionary(x => x.Key.Trim(), x => x.Value.FirstOrDefault()?.ToString()?.Trim());
            var isUpdate = pkValues.Count > 0;

            if (IsPost())
            {
                fieldsValues = this.HttpContext.Request.Form
                               .Where(x => x.Key.StartsWith("_") == false && string.IsNullOrEmpty(x.Value.FirstOrDefault()) == false)
                               .ToDictionary(x => x.Key, x => x.Value.FirstOrDefault()?.ToString());
            }

            if (IsGet())
            {
                var entity = new EntityFrameworkService().GetEntityByPrimaryKey(this.HttpContext, contextName, entityInfo, pkValues);
                if (entity != null)
                {
                    fieldsValues = entity.FieldsValues.ToDictionary(x => x.Key, x => Binder.ConvertToString(x.Value));
                }
            }

            Model.DbContext        = contextName;
            Model.Entity           = entityInfo;
            Model.FieldsWithValues = entityInfo.Fields.Select(x => (x, fieldsValues.FirstOrDefault(v => v.Key == x.Name).Value)).ToList();
            Model.IsUpdate         = isUpdate;
            if (IsSubmit())
            {
                DbContextEntityResult result = null;
                if (isUpdate)
                {
                    result = new EntityFrameworkService().Update(this.HttpContext, contextName, entityInfo, pkValues, fieldsValues);
                }
                else
                {
                    result = new EntityFrameworkService().Add(this.HttpContext, contextName, entityInfo, fieldsValues);
                }
                if ((result?.IsSuccess).GetValueOrDefault(false))
                {
                    var routeValues = entityInfo.Fields.Where(x => x.IsPrimaryKey).ToDictionary(x => x.Name, x => Reflector.GetPropertyOrFieldValue(result.Entity, x.Name));
                    routeValues.TryAdd("_dbContext", contextName);
                    routeValues.TryAdd("_entity", entityInfo.ClrTypeName);
                    var url = Url.Link("/EFEntityEditor", routeValues);
                    return(new EmbededViewRedirectResult(url));
                }
                Model.Errors   = result.Errors;
                Model.Warnings = result.Warnings;
            }

            return(await View());
        }