private void InitializeDataBase() { // Create a Temporary Database options = new DbContextOptionsBuilder <AtividadeContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; // Insert data into the database using one instance of the context using (var context = new AtividadeContext(options)) { context.Atividade.Add(new Atividade { Id = 1, Descricao = "Correr", DataInicio = DateTime.Now, DataFim = DateTime.Now, Responsavel = new Responsavel { Id = 1, Nome = "Saulo" } }); context.Atividade.Add(new Atividade { Id = 2, Descricao = "Andar", DataInicio = DateTime.Now, DataFim = DateTime.Now, Responsavel = new Responsavel { Id = 2, Nome = "Hugo" } }); context.Atividade.Add(new Atividade { Id = 3, Descricao = "Nadar", DataInicio = DateTime.Now, DataFim = DateTime.Now, Responsavel = new Responsavel { Id = 3, Nome = "Saulo" } }); context.SaveChanges(); } }
public void Delete() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { AtividadeController atividadeController = new AtividadeController(context); Atividade atividade = atividadeController.DeleteAtividade(2).Result.Value; Assert.Null(atividade); } }
public void Delete() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { ResponsavelController responsavelController = new ResponsavelController(context); Responsavel responsavel = responsavelController.DeleteResponsavel(2).Result.Value; Assert.Null(responsavel); } }
public void GetbyId() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { int atividadeId = 2; AtividadeController atividadeController = new AtividadeController(context); Atividade atividade = atividadeController.GetAtividade(atividadeId).Result.Value; Assert.Equal(2, atividade.Id); } }
public void GetAll() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { AtividadeController atividadeController = new AtividadeController(context); IEnumerable <Atividade> atividades = atividadeController.GetAtividade().Result.Value; Assert.Equal(3, atividades.Count()); } }
public void GetbyId() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { int ativiId = 2; ResponsavelController responsavelController = new ResponsavelController(context); Responsavel responsavel = responsavelController.GetResponsavel(ativiId).Result.Value; Assert.Equal(2, responsavel.Id); } }
public void GetAll() { InitializeDataBase(); // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { ResponsavelController responsavelController = new ResponsavelController(context); IEnumerable <Responsavel> responsavels = responsavelController.GetResponsavel().Result.Value; Assert.Equal(3, responsavels.Count()); } }
public void Update() { InitializeDataBase(); Responsavel responsavel = new Responsavel() { Id = 1, Nome = "Saulo" }; // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { ResponsavelController responsavelController = new ResponsavelController(context); Responsavel at = responsavelController.PutResponsavel(4, responsavel).Result.Value; Assert.Equal("Saulo", responsavel.Nome); } }
public void Update() { InitializeDataBase(); Atividade atividade = new Atividade() { Id = 3, Descricao = "Bolacha", DataInicio = DateTime.Now, DataFinal = DateTime.Now }; // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { AtividadeController atividadeController = new AtividadeController(context); Atividade ativ = atividadeController.PutAtividade(3, atividade).Result.Value; Assert.Equal("Bolacha", ativ.Descricao); } }
private void InitializeDataBase() { options = new DbContextOptionsBuilder <AtividadeContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid() .ToString()).Options; using (var context = new AtividadeContext(options)) { context.Atividade.Add(new Atividade { Id = 1, Descricao = "Name 1", DataInicio = DateTime.Now, DataFinal = DateTime.Now }); context.Atividade.Add(new Atividade { Id = 2, Descricao = "Name 2", DataInicio = DateTime.Now, DataFinal = DateTime.Now }); context.Atividade.Add(new Atividade { Id = 3, Descricao = "Name 3", DataInicio = DateTime.Now, DataFinal = DateTime.Now }); context.SaveChanges(); } }
private void InitializeDataBase() { // Create a Temporary Database options = new DbContextOptionsBuilder <AtividadeContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; // Insert data into the database using one instance of the context using (var context = new AtividadeContext(options)) { context.Responsavel.Add(new Responsavel { Id = 1, Nome = "Saulo" }); context.Responsavel.Add(new Responsavel { Id = 2, Nome = "Hugo" }); context.Responsavel.Add(new Responsavel { Id = 3, Nome = "Thiago" }); context.SaveChanges(); } }
public void Update() { InitializeDataBase(); Atividade atividade = new Atividade() { Id = 1, Descricao = "Pedalar", DataInicio = DateTime.Now, DataFim = DateTime.Now, Responsavel = new Responsavel { Id = 1, Nome = "Saulo" } }; // Use a clean instance of the context to run the test using (var context = new AtividadeContext(options)) { AtividadeController atividadeController = new AtividadeController(context); Atividade at = atividadeController.PutAtividade(4, atividade).Result.Value; Assert.Equal("Pedalar", atividade.Descricao); } }
public AtividadeController(AtividadeContext context) { _context = context; }
public ResponsavelController(AtividadeContext context) { _context = context; }