public void CriarPontoCorretamente() { try { var bd = new BancoContext(); var transaction = bd.Database.BeginTransaction(); var pontoEntrada = new Ponto { Data = DateTime.Now, NomeFuncionario = "José", Tipo = TipoPonto.Entrada }; CorePonto.CriarPonto(bd, pontoEntrada); var pontoSaida = new Ponto { Data = DateTime.Now, NomeFuncionario = "José", Tipo = TipoPonto.Saida }; CorePonto.CriarPonto(bd, pontoSaida); transaction.Rollback(); } catch (Exception e) { Assert.True(false, e.Message); } }
public void Setup() { var options = new DbContextOptionsBuilder <BancoContext>().UseSqlServer("Server=.\\;Database=Banco;Trusted_Connection=True;MultipleActiveResultSets=true").Options; _context = new BancoContext(options); unitOfWork = new UnitOfWork(_context); }
public void SetUp() { var optionsInMemory = new DbContextOptionsBuilder <BancoContext>().UseInMemoryDatabase("Banco").Options; _context = new BancoContext(optionsInMemory); this.CrearCuentaDeAhorros(); }
public void Setup() { var optionsSqlServer = new DbContextOptionsBuilder <BancoContext>() .UseSqlServer("Server=localhost\\SQLEXPRESS;Database=master;Trusted_Connection=True;").Options; _context = new BancoContext(optionsSqlServer); }
private static void DeleteCountry(BancoContext context, CountryService service) { Country country = FindCountry(context, service); service.Delete(country); Paused(); }
public void Setup() { var options = new DbContextOptionsBuilder <BancoContext>().UseSqlServer("Server=.\\;Database=Banco;Trusted_Connection=True;MultipleActiveResultSets=true").Options; BancoContext context = new BancoContext(options); unit = new UnitOfWork(context); #region List list.Add(new SavingsAccount { Name = "Cuenta de Ahorro", City = "Valledupar", Number = "0001", }); list.Add(new CheckingAccount { Name = "Cuenta Corriente", City = "Bogota", Number = "0002", }); list.Add(new CreditCard { Name = "Tarjeta de Credito", City = "Barranquilla", Number = "0003", }); list.Add(new Tdc { Name = "CDT", City = "Santa Marta", Number = "0004", }); #endregion }
public UnitOfWork(BancoContext context) { _context = context; Usuario = new UsuarioRepository(_context); TipoUsuario = new TipoUsuarioRepository(_context); Log = new LogRepository(_context); Socios = new SociosRepository(_context); Categoria = new CategoriaRepository(_context); DadosComplementares = new DadosComplementaresRepository(_context); Escolaridade = new EscolaridadeRepository(_context); EstadoCivil = new EstadoCivilRepository(_context); Estado = new EstadoRepository(_context); Livros = new LivrosRepository(_context); Editoras = new EditorasRepository(_context); Autores = new AutoresRepository(_context); EntradasLivros = new EntradasLivrosRepository(_context); Estoque = new EstoqueRepository(_context); Atividade = new AtividadesRepository(_context); LocalAtividade = new LocalAtividadeRepository(_context); PeriodoAtividade = new PeriodoAtividadeRepository(_context); VendaLivros = new VendaLivrosRepository(_context); Pagamentos = new PagamentosRepository(_context); Mes = new MesRepository(_context); Doacoes = new DoacoesRepository(_context); }
public ICollection <T> Listar() { using (var conexao = new BancoContext()) { var lista = conexao.Set <T>().ToList(); return(lista); } }
public T PegarPorId(int id) { using (var conexao = new BancoContext()) { var obj = conexao.Set <T>().Find(id); return(obj); } }
public bool Cadastrar(T item) { using (var conexao = new BancoContext()) { conexao.Set <T>().Add(item); return(conexao.SaveChanges() > 0 ? true : false); } }
public bool Deletar(T item) { using (var conexao = new BancoContext()) { conexao.Entry(item).State = EntityState.Deleted; return(conexao.SaveChanges() > 0 ? true : false); } }
private void AlterarStatus(int id, bool status) { using BancoContext context = new BancoContext(); Pessoa pessoa = context.Pessoas.SingleOrDefault(_ => _.Id == id); pessoa.Status = status; context.Update(pessoa); context.SaveChanges(); }
private static Country FindCountry(BancoContext context, CountryService service) { Console.Write("Write the Id: "); int id = Convert.ToInt32(Console.ReadLine()); Country country = service.Find(id); Console.WriteLine($"Id: {country.Id} Name: {country.Name}"); Paused(); return(country); }
private static void GetAllCountry(BancoContext context, CountryService service) { List <Country> countries = service.GetAll().ToList(); foreach (var country in countries) { Console.WriteLine($"Id: {country.Id} Name: {country.Name}"); } Paused(); }
public TransferenciaServiceTests() { var optionsBuilder = new DbContextOptionsBuilder <BancoContext>(); optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); _context = new BancoContext(optionsBuilder.Options); _transferenciaService = new TransferenciaService(_context); }
public void Setup() { var optionsInMemory = new DbContextOptionsBuilder <BancoContext>().UseInMemoryDatabase("Banco").Options; var optionsBD = new DbContextOptionsBuilder <BancoContext>().UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=BancoParcial;Trusted_Connection=True;MultipleActiveResultSets=true").Options; _context = new BancoContext(optionsInMemory); _unitOfWork = new UnitOfWork(_context); _context = new BancoContext(optionsBD); _unitOfWorkBD = new UnitOfWork(_context); }
public void Setup() { var optionsSqlServer = new DbContextOptionsBuilder <BancoContext>() .UseSqlServer("server=localhost;Database=Banco;Trusted_Connection=True;") .Options; //var optionsInMemory = new DbContextOptionsBuilder<BancoContext>().UseInMemoryDatabase("Banco").Options; _context = new BancoContext(optionsSqlServer); }
public void Setup() { /*var optionsSqlServer = new DbContextOptionsBuilder<BancoContext>() * .UseSqlServer("Server=.\\;Database=Banco;Trusted_Connection=True;MultipleActiveResultSets=true") * .Options;*/ var optionsInMemory = new DbContextOptionsBuilder <BancoContext>().UseInMemoryDatabase("Banco").Options; _context = new BancoContext(optionsInMemory); }
static void Main(string[] args) { var optionsInMemory = new DbContextOptionsBuilder <BancoContext>() .UseInMemoryDatabase("Banco") .Options; BancoContext context = new BancoContext(optionsInMemory); CrearCuentaBancaria(context); ConsignarCuentaBancaria(context); }
public AcaoTask(IAcaoService acaoService, BancoContext context, IOpcaoService opcaoService, IInfoMoneyService infoMoneyService ) { _acaoService = acaoService; _context = context; _opcaoService = opcaoService; _informoneyService = infoMoneyService; }
public void BancoContextTeste() { var obj = new BancoContext() { Id_Banco = 341, Nome = "Teste" }; Assert.AreEqual(341, obj.Id_Banco); Assert.AreEqual("Teste", obj.Nome); }
private static void CrearCuentaBancaria(BancoContext context) { CrearCuentaBancariaService _service = new CrearCuentaBancariaService(new UnitOfWork(context)); var requestCrer = new CreateFinancialServiceRequest() { Number = "524255", Name = "Boris Arturo" }; CreateFinancialServiceResponse responseCrear = _service.Ejecutar(requestCrer); System.Console.WriteLine(responseCrear.Message); }
private static void CrearDepositoATermino(BancoContext context) { CrearDepositoATerminoService _service = new CrearDepositoATerminoService(new UnitOfWork(context)); var requestCrer = new CrearDepositoATerminoRequest() { Numero = "12345", Nombre = "Cristian Mejia", FechaDeInicio = DateTime.Now, FechaDeTermino = new DateTime(2020, 3, 16), TasaInteres = 0.02 }; CrearDepositoATerminoResponse responseCrear = _service.Ejecutar(requestCrer); System.Console.WriteLine(responseCrear.Mensaje); System.Console.ReadKey(); }
private static void CrearCuentaBancaria(BancoContext context) { #region Crear /*CrearCuentaBancariaService _service = new CrearCuentaBancariaService(new UnitOfWork(context)); * var requestCrer = new CrearCuentaBancariaRequest() { Numero = "524255", Nombre = "Boris Arturo" }; * * CrearCuentaBancariaResponse responseCrear = _service.Ejecutar(requestCrer); * * System.Console.WriteLine(responseCrear.Mensaje);*/ #endregion }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddJsonOptions(opt => { opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); opt.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddScoped <ITransferenciaService, TransferenciaService>(); services.AddSingleton(x => { var optionsBuilder = new DbContextOptionsBuilder <BancoContext>(); optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); //optionsBuilder.UseSqlServer(Configuration.GetConnectionString("Padrao")); var banco = new BancoContext(optionsBuilder.Options); banco.Seed(); return(banco); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Avaliação Situacional", Description = "ASP.NET Core Web API", //TermsOfService = new Uri(""), Contact = new OpenApiContact { Name = "Liseane Iesbick", Email = "*****@*****.**", //Url = new Uri(""), } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.AddCors(options => { options.AddPolicy("CorsApi", builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod()); }); }
public void menu() { bool seguir = true; do { BancoContext context = new BancoContext(); System.Console.Clear(); System.Console.WriteLine("MENU DEL SISTEMA BANCARIO EN CONSOLA"); System.Console.WriteLine("1º) Country"); System.Console.WriteLine("2º) Crear Cuenta Bancaria"); System.Console.WriteLine("3º) Consignar Cuenta Bancaria"); System.Console.WriteLine("4º) Crear Persona"); System.Console.WriteLine("5º) Salir"); System.Console.Write("Seleccione una opción: "); switch (System.Console.Read()) { case '1': System.Console.Clear(); System.Console.WriteLine("Country"); menuCountry(context); // Continuar lógica y extraer métodos // break; case '2': System.Console.Clear(); System.Console.WriteLine("Crear Cuenta Bancaria"); ConsignarCuentaBancaria(context); // Continuar lógica y extraer métodos // break; case '3': System.Console.Clear(); System.Console.WriteLine("Consignar Cuenta Bancaria"); CrearCuentaBancaria(context); // Continuar lógica y extraer métodos // break; case '4': System.Console.Clear(); System.Console.WriteLine("Crear Persona"); // Continuar lógica y extraer métodos // break; case '5': System.Console.Clear(); System.Console.WriteLine("saliendo del programa.. "); seguir = false; // Continuar lógica y extraer métodos // break; } } while (seguir); }
public void PegarUltimosPontos() { try { var bd = new BancoContext(); var pontos = CorePonto.PegarUltimosPontos(bd); } catch (Exception e) { Assert.True(false, e.Message); } }
static void Main(string[] args) { using (var context = new BancoContext()) { context.Database.EnsureCreated(); } Console.WriteLine("Database!"); Console.ReadKey(); using (var context = new BancoContext()) { var author = new Author { FirstName = "William", LastName = "Shakespeare", Books = new List <Book> { new Book { Title = "Hamlet" }, new Book { Title = "Othello" }, new Book { Title = "MacBeth" } } }; context.Add(author); context.SaveChanges(); } Console.WriteLine("Save!"); Console.ReadKey(); using (var context = new BancoContext()) { foreach (var book in context.Books) { Console.WriteLine(book.Title); } } Console.WriteLine("Lista!"); Console.WriteLine("Hello World!"); Console.ReadKey(); }
private static void ConsignarCuentaBancaria(BancoContext context) { ConsignarService _service = new ConsignarService(new UnitOfWork(context)); var request = new ConsignarRequest() { AccountNumber = "524255", Amount = 1000 }; ConsignarResponse response = _service.Ejecutar(request); System.Console.WriteLine(response.Message); System.Console.ReadKey(); }
public void Editar(Pessoa pessoa) { if (pessoa.Status) { using BancoContext context = new BancoContext(); context.Update(pessoa); context.SaveChanges(); } else { throw new Exception(message: "Cliente inativo."); } }