public async Task Context_Query() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Id = "176694", Ok = true, Rev = "1-54f8e950cc338d2385d9b0cda2fd918e" }); httpTest.RespondWithJson(new { docs = new object[] { new { Id = "176694", Rev = "1-54f8e950cc338d2385d9b0cda2fd918e", Name = "Luke" } } }); await using var context = new MyDeathStarContext(); await context.Rebels.AddAsync(new Rebel { Name = "Luke" }); var result = await context.Rebels.ToListAsync(); Assert.NotEmpty(result); Assert.Equal("Luke", result[0].Name); }
public async Task Context_Query_MultiThread() { var context = new MyDeathStarContext(); var tasks = new int[1000].Select(_ => Task.Run(() => context.Rebels.Take(int.MaxValue).ToString())); var results = await Task.WhenAll(tasks); Assert.All(results, query => Assert.Equal(@"{""limit"":2147483647,""selector"":{}}", query)); await context.DisposeAsync(); }
public async Task Crud_Context() { await using var context = new MyDeathStarContext(); var luke = await context.Rebels.AddAsync(new Rebel { Name = "Luke", Age = 19 }); Assert.Equal("Luke", luke.Name); var result = await context.Rebels.ToListAsync(); Assert.NotEmpty(result); }
public async Task Context_Index_ToOverride() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Indexes = new[] { new { ddoc = Guid.NewGuid().ToString(), name = "skywalkers", def = new { fields = new[] { new Dictionary <string, string> { { "surname", "desc" } } } } } } }); // Delete httpTest.RespondWithJson(new { ok = true }); // Create new httpTest.RespondWithJson(new { Result = "created" }); // Query httpTest.RespondWithJson(new { docs = new object[] { new { Id = "176694", Rev = "1-54f8e950cc338d2385d9b0cda2fd918e", Name = "Luke" } } }); await using var context = new MyDeathStarContext(); var result = await context.Rebels.ToListAsync(); Assert.NotEmpty(result); Assert.Equal("Luke", result[0].Name); }
public async Task Context_Query_Discriminator() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Id = "176694", Ok = true, Rev = "1-54f8e950cc338d2385d9b0cda2fd918e" }); httpTest.RespondWithJson(new { Id = "173694", Ok = true, Rev = "1-54f8e950cc338d2385d9b0cda2fd918e" }); httpTest.RespondWithJson(new { docs = new object[] { new { Id = "176694", Rev = "1-54f8e950cc338d2385d9b0cda2fd918e", Name = "Luke" } } }); await using var context = new MyDeathStarContext(); await context.SimpleRebels.AddAsync(new SimpleRebel { Name = "Leia" }); await context.OtherRebels.AddAsync(new OtherRebel { Name = "Luke" }); var result = await context.OtherRebels.ToListAsync(); Assert.NotEmpty(result); Assert.Equal("Luke", result[0].Name); Assert.Equal(@"{""_conflicts"":[],""name"":""Leia"",""age"":0,""split_discriminator"":""SimpleRebel""}", httpTest.CallLog[0].RequestBody); Assert.Equal(@"{""_conflicts"":[],""rebel_bith_date"":""0001-01-01T00:00:00"",""name"":""Luke"",""age"":0,""isJedi"":false,""species"":0,""guid"":""00000000-0000-0000-0000-000000000000"",""split_discriminator"":""OtherRebel""}", httpTest.CallLog[1].RequestBody); Assert.Equal(@"{""selector"":{""split_discriminator"":""OtherRebel""}}", httpTest.CallLog[2].RequestBody); }
public async Task Crud_Index_Context() { // Create index await using var context = new MyDeathStarContext(); // Override index await using var newContext = new MyDeathStarContext2(); var indexes = await context.Rebels.GetIndexesAsync(); Assert.Equal(2, indexes.Count); await context.Rebels.AddAsync(new Rebel { Name = "Han", Age = 30, Surname = "Solo" }); await context.Rebels.AddAsync(new Rebel { Name = "Leia", Age = 19, Surname = "Skywalker" }); await context.Rebels.AddAsync(new Rebel { Name = "Luke", Age = 19, Surname = "Skywalker" }); var rebels = await context.Rebels .OrderBy(r => r.Surname) .ThenBy(r => r.Name) .ToListAsync(); Assert.NotEmpty(rebels); }
public async Task Context_CreateIndex_Test() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Id = "176694", Ok = true, Rev = "1-54f8e950cc338d2385d9b0cda2fd918e" }); await using var context = new MyDeathStarContext(); await context.Rebels.IndexProvider.CreateAsync(index => { index.IndexName = "test-index"; index.Fields = x => new { x.Name, x.Age }; }); var call = httpTest.CallLog.First(); Assert.NotNull(call); Assert.Equal(@"{""name"":""test-index"",""index"":{""fields"":[""Name"",""Age""]},""type"":""json""}", call.RequestBody); }
public RebelsController(MyDeathStarContext context) { _context = context; }