public async Task Get_All() { //Given var repo = new SqliteRepository <TestTable, int>(_tempDbPath); TestTable expected1 = TestTable.Generate(); TestTable expected2 = TestTable.Generate(); //When TestTable actual1 = null; TestTable actual2 = null; using (var conn = await repo.OpenAsync(CancellationToken.None)) { await TestTable.CreateTableAsync(conn); await expected1.InsertAsync(conn); await expected2.InsertAsync(conn); var actual = await repo.GetAllAsync(); actual1 = actual.SingleOrDefault(x => x.Id == expected1.Id); actual2 = actual.SingleOrDefault(x => x.Id == expected2.Id); await TestTable.DropAsync(conn); } //Then Assert.NotNull(actual1); Assert.NotNull(actual2); Assert.Equal(expected1.Id, actual1.Id); Assert.Equal(expected1.Message, actual1.Message); Assert.Equal(expected2.Id, actual2.Id); Assert.Equal(expected2.Message, actual2.Message); }
public static int Main(string[] args) { var app = new CommandLineApplication() { Name = "taxi", Description = "Predict taxi rides in NYC.", }; app.Command("boroughs", (command) => { var queryOption = command.Option <string>("-q|--query <QUERY>", "A query string to fuzzy search with", CommandOptionType.SingleOrNoValue); command.OnExecuteAsync(async(ct) => { try { var repo = new SqliteRepository <TaxiZone, short>(DbPath); var zones = await repo.GetAllAsync(); if (!string.IsNullOrEmpty(queryOption.ParsedValue)) { zones = zones.Where(z => z.Borough.StartsWith(queryOption.ParsedValue)); } foreach (var zone in zones) { System.Console.WriteLine($" [{zone.Id}]: {zone.Zone}, {zone.Borough}"); } return(0); } catch (Exception e) { System.Console.Error.WriteLine(e.ToString()); return(-1); } }); }); app.Command("predict", (command) => { var pickUpArgument = command.Argument <short>("[pick-up]", "Where you will be picked up from."); var dropOffArgument = command.Argument <short>("[drop-off]", "Where you will be dropped of at."); var vehicleOption = command.Option <VehicleType>("-v|--vehicle <VEHICLE>", "The type of vehicle to take", CommandOptionType.SingleValue); command.OnExecuteAsync(async(ct) => { try { var repo = new SqliteRepository <TaxiTrip, long>(DbPath); var query = new TaxiTripMetricsQuery { PickUpLocationId = pickUpArgument.ParsedValue, DropOffLocationId = dropOffArgument.ParsedValue, VehicleType = vehicleOption.ParsedValue }; IEnumerable <TaxiTripMetrics> results = await repo.QueryAsync <TaxiTripMetrics>(query, ct); TaxiTripMetrics metrics = results.SingleOrDefault(); System.Console.WriteLine($"Estimated Cost => ${metrics.AverageCost:0.00}"); System.Console.WriteLine($"Estimated Duration => {TimeSpan.FromSeconds(metrics.AverageDurationSeconds)}"); return(0); } catch (Exception e) { System.Console.Error.WriteLine(e.ToString()); return(-1); } }); }); return(app.Execute(args)); }