Skip to content

Commit fa47f40

Browse files
committed
tests/failure reason
1 parent b5d31d1 commit fa47f40

File tree

2 files changed

+69
-52
lines changed

2 files changed

+69
-52
lines changed

E2eTest/SingleRecordBasicTest.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ public async Task AddTest()
1616
var result = await this.RunTestPageMethodAsync(p => p.Add);
1717
Assert.AreEqual("12", result);
1818
var records = await page.EvaluateAsync<string>("getAll('SingleRecordBasic.Add', 'Records')");
19+
20+
// TODO:
21+
// Ignored should not exist here
22+
// the property of Nested should be "Value" rather than "value"
1923
Assert.That.AreJsonEqual("""
2024
[
2125
{
2226
"id":12,
23-
"normal":"Norm",
27+
"Normal":"Norm",
2428
"Renamed":"R",
25-
"index":"I",
26-
"uniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
27-
"enum":0,
28-
"nested":{"value":1234},
29-
"largeNumber":9007199254740991
29+
"Index":"I",
30+
"UniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
31+
"Enum":0,
32+
"Nested":{"Value":1234},
33+
"LargeNumber":9007199254740991
3034
}
3135
]
3236
""", records);
@@ -55,17 +59,23 @@ public async Task UpdateTest()
5559
Assert.AreEqual("1", result);
5660

5761
var records = await page.EvaluateAsync<string>("getAll('SingleRecordBasic.Update', 'Records')");
62+
63+
// TODO:
64+
// Ignored should not exist here
65+
// the property of Nested should be "Value" rather than "value"
5866
Assert.That.AreJsonEqual("""
59-
[{
60-
"id":12,
61-
"normal":"Updated",
62-
"Renamed":"R",
63-
"index":"I",
64-
"uniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
65-
"enum":0,
66-
"nested":{"value":1234},
67-
"largeNumber":9007199254740991
68-
}]
67+
[
68+
{
69+
"id":12,
70+
"Normal":"Updated",
71+
"Renamed":"R",
72+
"Index":"I",
73+
"UniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
74+
"Enum":0,
75+
"Nested":{"Value":1234},
76+
"LargeNumber":9007199254740991
77+
}
78+
]
6979
""", records);
7080
}
7181

@@ -86,11 +96,14 @@ public async Task GetAllTest()
8696
await page.DeleteDatabaseAsync("SingleRecordBasic.GetAll");
8797

8898
var result = await this.RunTestPageMethodAsync(p => p.GetAll);
99+
100+
// Nested.Value should be 1234
89101
Assert.That.AreJsonEqual("""
90102
[{
91103
"Id":12,
92104
"Normal":"Norm",
93-
"Renamed":"R",
105+
"ShouldBeRenamed":"R",
106+
"Ignored":true,
94107
"Index":"I",
95108
"UniqueIndex":"633a97d2-0c92-4c68-883b-364f94ad6030",
96109
"Enum":0,

E2eTestWebApp/TestPages/SingleRecordBasicTestPage.cs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,43 @@ public class SingleRecordBasicTestPage(IMagicDbFactory magic) : TestPageBase
1515
private record NestedItem(int Value);
1616

1717
[MagicTable("Records", null)]
18-
private record Record(
19-
[property: MagicPrimaryKey]
20-
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21-
int Id,
18+
private class Record
19+
{
20+
[MagicPrimaryKey("id")]
21+
public int Id { get; set; }
2222

23-
string Normal,
23+
public string? Normal { get; set; }
2424

25-
[property: JsonIgnore]
26-
bool Ignored,
25+
[MagicNotMapped]
26+
public bool Ignored { get; set; }
2727

28-
[property: JsonPropertyName("Renamed")]
29-
char ShouldBeRenamed,
28+
[MagicIndex("Renamed")]
29+
public char ShouldBeRenamed { get; set; }
3030

31-
[property: MagicIndex]
32-
string Index,
31+
[MagicIndex]
32+
public string? Index { get; set; }
3333

34-
[property: MagicIndex]
35-
Guid UniqueIndex,
34+
[MagicIndex]
35+
public Guid UniqueIndex { get; set; }
3636

37-
DayOfWeek Enum,
37+
public DayOfWeek Enum { get; set; }
3838

39-
NestedItem Nested,
39+
public NestedItem? Nested { get; set; }
4040

41-
long LargeNumber)
42-
{
43-
public static Record Sample => new Record(
44-
Id: 12,
45-
Normal: "Norm",
46-
Ignored: true,
47-
ShouldBeRenamed: 'R',
48-
Index: "I",
49-
UniqueIndex: Guid.Parse("633A97D2-0C92-4C68-883B-364F94AD6030"),
50-
Enum: DayOfWeek.Sunday,
51-
Nested: new(1234),
52-
LargeNumber: 9007199254740991);
41+
public long LargeNumber { get; set; }
5342
}
43+
static Record NewSample => new Record()
44+
{
45+
Id = 12,
46+
Normal = "Norm",
47+
Ignored = true,
48+
ShouldBeRenamed = 'R',
49+
Index = "I",
50+
UniqueIndex = Guid.Parse("633A97D2-0C92-4C68-883B-364F94AD6030"),
51+
Enum = DayOfWeek.Sunday,
52+
Nested = new(1234),
53+
LargeNumber = 9007199254740991
54+
};
5455

5556
public async Task<string> Add()
5657
{
@@ -60,7 +61,7 @@ public async Task<string> Add()
6061
Version = 1,
6162
StoreSchemas = [SchemaHelper.GetStoreSchema<Record>(null, false)]
6263
});
63-
var id = await database.AddAsync<Record, int>(Record.Sample);
64+
var id = await database.AddAsync<Record, int>(NewSample);
6465
return id.ToString();
6566
}
6667

@@ -72,8 +73,8 @@ public async Task<string> Delete()
7273
Version = 1,
7374
StoreSchemas = [SchemaHelper.GetStoreSchema<Record>(null, false)]
7475
});
75-
_ = await database.AddAsync<Record, int>(Record.Sample);
76-
await database.DeleteAsync(Record.Sample);
76+
_ = await database.AddAsync<Record, int>(NewSample);
77+
await database.DeleteAsync(NewSample);
7778
return "OK";
7879
}
7980

@@ -85,8 +86,11 @@ public async Task<string> Update()
8586
Version = 1,
8687
StoreSchemas = [SchemaHelper.GetStoreSchema<Record>(null, false)]
8788
});
88-
_ = await database.AddAsync<Record, int>(Record.Sample);
89-
var count = await database.UpdateAsync(Record.Sample with { Normal = "Updated" });
89+
_ = await database.AddAsync<Record, int>(NewSample);
90+
91+
var updated = NewSample;
92+
updated.Normal = "Updated";
93+
var count = await database.UpdateAsync(updated);
9094
return count.ToString();
9195
}
9296

@@ -98,8 +102,8 @@ public async Task<string> GetById()
98102
Version = 1,
99103
StoreSchemas = [SchemaHelper.GetStoreSchema<Record>(null, false)]
100104
});
101-
var id = await database.AddAsync<Record, int>(Record.Sample);
102-
var result = await database.GetByIdAsync<Record, int>(id);
105+
var id = await database.AddAsync<Record, int>(NewSample);
106+
var result = await database.GetByIdAsync<Record>(id);
103107
return result.Normal;
104108
}
105109

@@ -111,7 +115,7 @@ public async Task<string> GetAll()
111115
Version = 1,
112116
StoreSchemas = [SchemaHelper.GetStoreSchema<Record>(null, false)]
113117
});
114-
_ = await database.AddAsync<Record, int>(Record.Sample);
118+
_ = await database.AddAsync<Record, int>(NewSample);
115119
var result = await database.GetAllAsync<Record>();
116120
return JsonSerializer.Serialize(result);
117121
}

0 commit comments

Comments
 (0)