public void Update_updates_item_from_database() { var options = new DbContextOptionsBuilder <DatabaseContext>() .UseInMemoryDatabase(databaseName: "Update_updates_item_from_database") .Options; using (var context = new DatabaseContext(options)) { var citizen = new Citizen { Name = "José", CPF = "34567890123", Id = 1 }; var service = new CitizenService(context, new CitizenRepository(context)); service.Add(citizen); Assert.Single(context.Set <Citizen>().ToList()); Assert.Equal("José", context.Set <Citizen>().Single().Name); citizen.Name = "Zé das Couves"; service.Update(1, citizen); Assert.Equal("Zé das Couves", context.Set <Citizen>().Single().Name); } }
public void Add_writes_to_database() { var options = new DbContextOptionsBuilder <DatabaseContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; using (var context = new DatabaseContext(options)) { var citizen = new Citizen { Name = "Jorge", CPF = "12345678901", Id = 1 }; var service = new CitizenService(context, new CitizenRepository(context)); service.Add(citizen); } using (var context = new DatabaseContext(options)) { Assert.Single(context.Set <Citizen>().ToList()); Assert.Equal(1, context.Set <Citizen>().Single().Id); } }
public void Delete_deletes_from_database() { var options = new DbContextOptionsBuilder <DatabaseContext>() .UseInMemoryDatabase(databaseName: "Delete_deletes_from_database") .Options; using (var context = new DatabaseContext(options)) { var citizen = new Citizen { Name = "Joana", CPF = "23456789012" }; var service = new CitizenService(context, new CitizenRepository(context)); service.Add(citizen); Assert.Single(context.Set <Citizen>().ToList()); var insertedCitizen = service.GetAll().First(); service.Delete(insertedCitizen.Id); Assert.Empty(context.Set <Citizen>().ToList()); } }