public async Task Should_Do_Crud_On_Simple_Model_Object_With_Different_Primary_Key(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // create var car = AutomobileFixture.GetCar(); await db.Create(car); // assert create var actualCar = await db.Query <Automobile>().Where(c => c.Vin == car.Vin).SingleAsync(); actualCar.Should().NotBeNull(); actualCar.Should().BeEquivalentTo(car); // update car.WheelCount = 6; car.VehicleType = "Argo"; await db.Update(car); // assert update actualCar = await db.Query <Automobile>().Where(c => c.Vin == car.Vin).SingleAsync(); actualCar.Should().NotBeNull(); actualCar.Should().BeEquivalentTo(actualCar); // delete await db.Delete <Automobile>(c => c.Vin == car.Vin); // assert delete actualCar = await db.Query <Automobile>().Where(c => c.Vin == car.Vin).SingleOrDefaultAsync(); actualCar.Should().BeNull(); }
public void Should_Update_With_Different_Primary_Key(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // create var car = AutomobileFixture.GetCar(); db.Create(car); // assert create var actualCar = db.Query <AutomobileModel>().Where(c => c.Vin == car.Vin).Single(); actualCar.Should().NotBeNull(); actualCar.ShouldBeEquivalentTo(car); // update car.WheelCount = 6; car.VehicleType = "Argo"; db.Update(car); // assert update actualCar = db.Query <AutomobileModel>().Where(c => c.Vin == car.Vin).Single(); actualCar.Should().NotBeNull(); actualCar.ShouldBeEquivalentTo(actualCar); }
public async Task Should_Do_CUD_In_Transactions(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // create var motorcycle = AutomobileFixture.GetMotorcycle(); var car = AutomobileFixture.GetCar(); await db.RunInTransaction(async transaction => { await transaction.Create(motorcycle); // create only await transaction.CreateOrUpdate(car); // create or update }); // assert create var actualMotorcycle = await db.Query <Automobile>().Where(a => a.Vin == motorcycle.Vin).SingleOrDefaultAsync(); var actualCar = await db.Query <Automobile>().Where(a => a.Vin == car.Vin).SingleOrDefaultAsync(); actualMotorcycle.Should().NotBeNull(); actualCar.Should().NotBeNull(); // update motorcycle.VehicleType = "scooter"; car.VehicleType = "truck"; await db.RunInTransaction(async transaction => { await transaction.CreateOrUpdate(motorcycle); // create or update await transaction.Update(car); // update only }); // assert update actualMotorcycle = await db.Query <Automobile>().Where(a => a.Vin == motorcycle.Vin).SingleOrDefaultAsync(); actualCar = await db.Query <Automobile>().Where(a => a.Vin == car.Vin).SingleOrDefaultAsync(); actualMotorcycle.Should().NotBeNull(); actualCar.Should().NotBeNull(); actualMotorcycle.VehicleType.Should().Be(motorcycle.VehicleType); actualCar.VehicleType.Should().Be(car.VehicleType); // delete await db.RunInTransaction(async transaction => { await transaction.Delete <Automobile>(a => a.Vin == motorcycle.Vin); await transaction.Delete <Automobile>(a => a.Vin == car.Vin); }); // assert delete actualMotorcycle = await db.Query <Automobile>().Where(a => a.Vin == motorcycle.Vin).SingleOrDefaultAsync(); actualCar = await db.Query <Automobile>().Where(a => a.Vin == car.Vin).SingleOrDefaultAsync(); actualMotorcycle.Should().BeNull(); actualCar.Should().BeNull(); }
public async Task Should_Perform_Faster_When_Run_In_Transaction(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // setup var carWatch = new Stopwatch(); var bikeWatch = new Stopwatch(); // transaction test var car = AutomobileFixture.GetCar(); carWatch.Start(); await db.RunInTransaction(async trans => { for (var i = 10; i < 1000; i++) // 990 records { car.Vin = i.ToString(); await trans.CreateOrUpdate(car); } }); carWatch.Stop(); // non transaction test var motorcycle = AutomobileFixture.GetMotorcycle(); bikeWatch.Start(); for (var i = 1010; i < 2000; i++) // 990 records { motorcycle.Vin = i.ToString(); await db.CreateOrUpdate(motorcycle); } bikeWatch.Stop(); carWatch.ElapsedTicks.Should().BeLessThan(bikeWatch.ElapsedTicks); // assert record count var vehicleCount = (await db.Query <Automobile>().ToListAsync()).Count; vehicleCount.Should().Be(1980); Trace.WriteLine($"Non Transactionable: {bikeWatch.Elapsed:hh\\:mm\\:ss} \t(Ticks {bikeWatch.ElapsedTicks})"); Trace.WriteLine($"Transactionable: {carWatch.Elapsed:hh\\:mm\\:ss} \t\t(Ticks {carWatch.ElapsedTicks})"); }
public void Should_Perform_Faster_When_Run_In_Transaction(IDbProvider db) { // setup var carWatch = new Stopwatch(); var bikeWatch = new Stopwatch(); // transaction test var car = AutomobileFixture.GetCar(); carWatch.Start(); db.RunInTransaction(trans => { for (var i = 10; i < 1000; i++) // 990 records { car.Vin = i.ToString(); trans.CreateOrUpdate(car); } }); carWatch.Stop(); // non transaction test var motorcycle = AutomobileFixture.GetMotorcycle(); bikeWatch.Start(); for (var i = 1010; i < 2000; i++) // 990 records { motorcycle.Vin = i.ToString(); db.CreateOrUpdate(motorcycle); } bikeWatch.Stop(); carWatch.ElapsedTicks.Should().BeLessThan(bikeWatch.ElapsedTicks); // assert record count var vehicleCount = db.Query <AutomobileModel>().ToList().Count; vehicleCount.Should().Be(1980); Trace.WriteLine($"Non Transaction: {bikeWatch.Elapsed.ToString(@"hh\:mm\:ss")} \t(Ticks {bikeWatch.ElapsedTicks})"); Trace.WriteLine($"Transaction: {carWatch.Elapsed.ToString(@"hh\:mm\:ss")} \t\t(Ticks {carWatch.ElapsedTicks})"); }