Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions E2eTest/SingleRecordBasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public async Task AddTest()
[
{
"id":12,
"normal":"Norm",
"Normal":"Norm",
"Renamed":"R",
"Index":"I",
"UniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
"enum":0,
"nested":{"value":1234},
"largeNumber":9007199254740991
"Enum":0,
"Nested":{"value":1234},
"LargeNumber":9007199254740991
}
]
""", records);
Expand Down Expand Up @@ -67,13 +67,13 @@ public async Task UpdateTest()
[
{
"id":12,
"normal":"Updated",
"Normal":"Updated",
"Renamed":"R",
"Index":"I",
"UniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
"enum":0,
"nested":{"value":1234},
"largeNumber":9007199254740991
"Enum":0,
"Nested":{"value":1234},
"LargeNumber":9007199254740991
}
]
""", records);
Expand Down
18 changes: 18 additions & 0 deletions E2eTest/WhereTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using E2eTest.Entities;
using E2eTest.Extensions;
using E2eTestWebApp.TestPages;

namespace E2eTest;

[TestClass]
public class WhereTest : TestBase<WhereTestPage>
{
[TestMethod]
public async Task Where1Test()
{
var page = await this.NewPageAsync();
await page.DeleteDatabaseAsync("Where.Where1");
var result = await this.RunTestPageMethodAsync(p => p.Where1);
Assert.That.AreJsonEqual("[1,2]", result);
}
}
4 changes: 2 additions & 2 deletions E2eTestWebApp/TestPages/TestPageBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<input data-testid="method" type="text" @bind-value="@method" />
<input data-testid="run" type="button" @onclick="@RunAsync" />

<input data-testid="output" type="text" @bind-value="@output" />
<input data-testid="clear" type="button" @onclick="@Clear" />
<textarea data-testid="output">@output</textarea>
<input data-testid="clear" type="button" @onclick="@Clear" />
7 changes: 1 addition & 6 deletions E2eTestWebApp/TestPages/TestPageBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ private async Task RunAsync()
}
catch (Exception ex)
{
this.output = JsonSerializer.Serialize(new Dictionary<string, string>()
{
["Exception"] = ex.GetType().ToString(),
["Message"] = ex.Message,
["StackTrace"] = ex.StackTrace ?? "",
});
this.output = ex.ToString();
}
}

Expand Down
48 changes: 48 additions & 0 deletions E2eTestWebApp/TestPages/WhereTestPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Magic.IndexedDb;
using Magic.IndexedDb.Helpers;
using Microsoft.AspNetCore.Components;
using System.Text.Json;

namespace E2eTestWebApp.TestPages;

[Route("/WhereTest")]
public class WhereTestPage(IMagicDbFactory magic) : TestPageBase
{
[MagicTable("Records", null)]
private class Record
{
[MagicPrimaryKey("Id")]
public int Id { get; set; }

public int Int32Field { get; set; }
}

public async Task<string> Where1()
{
var database = await magic.OpenAsync(new DbStore()
{
Name = "Where.Where1",
Version = 1,
StoreSchemas = [SchemaHelper.GetStoreSchema(typeof(Record))]
});
await database.AddAsync<Record, int>(new Record()
{
Id = 1,
Int32Field = 1
});
await database.AddAsync<Record, int>(new Record()
{
Id = 2,
Int32Field = 2
});
await database.AddAsync<Record, int>(new Record()
{
Id = 3,
Int32Field = 3
});
var result = await database
.Where<Record>(x => x.Int32Field < 3)
.ToListAsync();
return JsonSerializer.Serialize(result.Select(x => x.Id));
}
}
11 changes: 10 additions & 1 deletion Magic.IndexedDb/Factories/MagicDbFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ public async ValueTask DisposeAsync()
var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await module.InvokeVoidAsync(IndexedDbFunctions.CLOSE_ALL, timeout.Token);
}
finally
catch
{
// do nothing
}

try
{
await module.DisposeAsync();
}
catch
{
// do nothing
}
}

public async ValueTask<IndexedDbManager> OpenAsync(
Expand Down
4 changes: 2 additions & 2 deletions Magic.IndexedDb/Helpers/MagicSerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static string SerializeObject<T>(T value, MagicJsonSerializationSettings?
if (string.IsNullOrWhiteSpace(json))
throw new ArgumentException("JSON cannot be null or empty.", nameof(json));

if (settings == null)
settings = new MagicJsonSerializationSettings();
// if (settings == null)
// settings = new MagicJsonSerializationSettings();

var options = settings.GetOptionsWithResolver<T>(); // Ensure correct resolver for deserialization

Expand Down