public async Task Pages_With_Related_Entities() { var testConnection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new TestDataContext(testConnection)) { for (int i = 0; i < 10; i++) { var newCategory = new Category { Name = $"Category {i}" }; context.categories.Add(newCategory); await context.SaveChangesAsync(); for (int j = 0; j < 10; j++) { var newProduct = new Product { Name = $"Product {j}", Category = newCategory, }; context.products.Add(newProduct); } await context.SaveChangesAsync(); } var repository = new Repository <Product>(context); var result = await repository.GetPageAsync( 1, 10, products => products.OrderBy(product => product.Name), product => product.Category); } }
public async Task DeveAtualizarPessoa() { var pessoa = new Pessoa { Nome = "Washington Borges", Twitter = "borgeston" }; await TestDataContext.AddAsync(pessoa); await TestDataContext.SaveChangesAsync(); var pessoaEditada = new Pessoa { Id = pessoa.Id, Nome = "Ton Borges", Twitter = "borgeston" }; var response = await Client.PutAsync($"{BaseUrl}/{pessoa.Id}", new StringContent(JsonConvert.SerializeObject(pessoaEditada), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <Pessoa>(responseString); Assert.Equal(data.Nome, pessoaEditada.Nome); Assert.Equal(data.Twitter, pessoaEditada.Twitter); }
public async Task DeveDeletarPessoa() { var pessoa = new Pessoa { Nome = "Rafael dos Santos", Twitter = "rsantosdev" }; await TestDataContext.AddAsync(pessoa); await TestDataContext.SaveChangesAsync(); var response = await Client.DeleteAsync($"{BaseUrl}/{pessoa.Id}"); response.EnsureSuccessStatusCode(); response = await Client.GetAsync(BaseUrl); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <List <Pessoa> >(responseString); Assert.Equal(data.Count, 0); }
public async Task <ActionResult <TestData> > AddToTestDatabase([FromBody] TestDataCreate testDataCreate) { using (TestDataContext context = new TestDataContext()) { var testdata = new Data.TestData { TestId = testDataCreate.TestId, FretAmount = testDataCreate.FretAmount, ScaleLength = testDataCreate.ScaleLength }; context.TestData.Add(testdata); await context.SaveChangesAsync(); var response = new TestDataCreateResponse { TestId = testdata.TestId, FretAmount = testdata.FretAmount, ScaleLength = testdata.ScaleLength }; return(CreatedAtAction(nameof(GetSingleTestDataEntry), new { id = testdata.TestId, fret = testdata.FretAmount, scale = testdata.ScaleLength }, testdata)); } }
public async Task <IActionResult> DeleteSingleTestEntry(int id) { using (TestDataContext context = new TestDataContext()) { var testDataItem = await context.TestData.FindAsync(id); if (testDataItem == null) { return(NotFound()); } context.TestData.Remove(testDataItem); await context.SaveChangesAsync(); return(NoContent()); } }
public async Task Deve_Retornar_Lista_De_Pessoas_Com_Um_Item() { var pessoa = new Pessoa { Nome = "Teste", Twitter = "@teste" }; await TestDataContext.AddAsync(pessoa); await TestDataContext.SaveChangesAsync(); var response = await Client.GetAsync(BASE_URL); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <List <Pessoa> >(responseString); Assert.Equal(data.Count, 1); }
public async Task DeveRetornarListaDePessoasNaoVazia() { var pessoa = new Pessoa { Nome = "Rafael Barrelo", Twitter = "@rafaelbarrelo" }; await TestDataContext.AddAsync(pessoa); await TestDataContext.SaveChangesAsync(); var response = await Client.GetAsync(BaseUrl); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <List <Pessoa> >(responseString); Assert.Equal(data.Count, 1); Assert.Contains(data, x => x.Nome == pessoa.Nome); }
public async Task DeveObterPessoa() { var pessoa = new Pessoa { Nome = "Washington Borges", Twitter = "borgeston" }; await TestDataContext.AddAsync(pessoa); await TestDataContext.SaveChangesAsync(); var response = await Client.GetAsync($"{BaseUrl}/{pessoa.Id}"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <Pessoa>(responseString); Assert.Equal(data.Id, pessoa.Id); Assert.Equal(data.Nome, pessoa.Nome); Assert.Equal(data.Twitter, pessoa.Twitter); }