public void SQLite_Delete_Rows_Created_Before_Date() { // Prepare SignalRepository signalRepo = new SignalRepository(this.GetService <CacheContext>()); int count = signalRepo.QueryAll.Count(); // Pre-validate signalRepo.Truncate(); Assert.Empty(signalRepo.QueryAll); DateTime border = DateTime.Now.AddMinutes(-1); string topGuid = Guid.NewGuid().ToString(); signalRepo.Add(new Signal[] { Signal.New(deviceId: "fooDevice", data: Guid.NewGuid().ToString(), timestamp: DateTime.Now.AddMinutes(-3)), Signal.New(deviceId: "fooDevice", data: Guid.NewGuid().ToString(), timestamp: DateTime.Now.AddMinutes(-2)), Signal.New(deviceId: "fooDevice", data: topGuid, timestamp: border) }); Assert.Equal(3, signalRepo.QueryAll.Count()); // Perform List <Signal> toDelete = signalRepo.QueryAll.Where(x => x.Timestamp < border).ToList(); signalRepo.Delete(toDelete); // Truncate(); // Post-validate Assert.Equal(1, signalRepo.QueryAll.Count()); Assert.Equal(topGuid, signalRepo.QueryAll.First().Data); }
public void SQLite__Truncate_Table() { // Prepare SignalRepository signalRepo = new SignalRepository(this.GetService <CacheContext>()); int count = signalRepo.QueryAll.Count(); if (count == 0) { signalRepo.Add(Signal.New(deviceId: "fooDevice", data: "foo", timestamp: DateTime.Now)); } // Pre-validate Assert.NotEmpty(signalRepo.QueryAll); // Perform signalRepo.Truncate(); // Post-validate Assert.Empty(signalRepo.QueryAll); //adapter.Disconnect(); }