public async void GetById_test() { // Given var faker = AutoFaker.Create(); var bus = faker.Generate <IMediatrHandler>(); var options = new DbContextOptionsBuilder <DCDroneDelivery>() .UseInMemoryDatabase(databaseName: "DroneDelivery") .Options; var clientes = faker.Generate <Cliente>(3); using (var contexto = new DCDroneDelivery(options, bus)) { contexto.Cliente.AddRange(clientes); contexto.SaveChanges(); } var expectResponse = clientes.FirstOrDefault(); using (var contexto = new DCDroneDelivery(options, bus)) { ClienteRepository clienteRepository = new ClienteRepository(contexto); //When var cliente = await clienteRepository.ObterPorId(expectResponse.Id); //Then CompareLogic comparer = new CompareLogic(); Assert.True(comparer.Compare(expectResponse, cliente).AreEqual); } }
public async void Update_test() { // Given var faker = AutoFaker.Create(); var bus = faker.Generate <IMediatrHandler>(); var options = new DbContextOptionsBuilder <DCDroneDelivery>().UseInMemoryDatabase(databaseName: "DroneDelivery").Options; var cliente = faker.Generate <Cliente>(); //Seed using (var contexto = new DCDroneDelivery(options, bus)) { contexto.Cliente.AddRange(cliente); contexto.SaveChanges(); } bool expectResponse; bool result; using (var contexto = new DCDroneDelivery(options, bus)) { contexto.Cliente.Update(cliente); expectResponse = contexto.SaveChanges() > 0; } using (var contexto = new DCDroneDelivery(options, bus)) { var clienteRepository = new ClienteRepository(contexto); await clienteRepository.Atualizar(cliente); result = contexto.SaveChanges() > 0; } var comparer = new CompareLogic(); Assert.True(comparer.Compare(expectResponse, result).AreEqual); }