Skip to content

Commit b3e5f7c

Browse files
committed
Start point for copying testserver tests to e2e
1 parent cf99c8e commit b3e5f7c

File tree

9 files changed

+123
-28
lines changed

9 files changed

+123
-28
lines changed

E2eTest/CursorTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using E2eTestWebApp.TestPages;
2+
3+
namespace E2eTest;
4+
5+
[TestClass]
6+
public class CursorTest : TestBase<CursorTestPage>
7+
{
8+
[TestMethod]
9+
public async Task Where1Test()
10+
{
11+
Assert.Fail();
12+
}
13+
}

E2eTest/OpenTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class OpenTest : TestBase<OpenTestPage>
1212
[TestMethod]
1313
public async Task DirectOpenTest()
1414
{
15-
1615
var page = await this.NewPageAsync();
1716
await page.DeleteDatabaseAsync("Person");
1817

E2eTest/SingleRecordBasicTest.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,27 @@ public class SingleRecordBasicTest : TestBase<SingleRecordBasicTestPage>
99
[TestMethod]
1010
public async Task AddTest()
1111
{
12-
var page = await this.NewPageAsync();
13-
await page.DeleteDatabaseAsync("Person");
14-
1512
var result = await this.RunTestPageMethodAsync(p => p.Add);
1613
Assert.AreEqual(result, "OK");
1714
}
1815

1916
[TestMethod]
2017
public async Task DeleteTest()
2118
{
22-
var page = await this.NewPageAsync();
23-
await page.DeleteDatabaseAsync("Person");
24-
2519
var result = await this.RunTestPageMethodAsync(p => p.Delete);
2620
Assert.AreEqual(result, "OK");
2721
}
2822

2923
[TestMethod]
3024
public async Task UpdateTest()
3125
{
32-
var page = await this.NewPageAsync();
33-
await page.DeleteDatabaseAsync("Person");
34-
3526
var result = await this.RunTestPageMethodAsync(p => p.Update);
3627
Assert.AreEqual(result, "OK");
3728
}
3829

3930
[TestMethod]
4031
public async Task GetAllTest()
4132
{
42-
var page = await this.NewPageAsync();
43-
await page.DeleteDatabaseAsync("Person");
44-
4533
var result = await this.RunTestPageMethodAsync(p => p.GetAll);
4634
Assert.AreEqual(result, "OK");
4735
}

E2eTest/TestBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Playwright;
55
using System.Linq.Expressions;
66
using System.Reflection;
7+
using E2eTest.Extensions;
78

89
namespace E2eTest;
910

@@ -49,6 +50,10 @@ protected async ValueTask<string> RunTestPageMethodAsync(
4950

5051
await page.GotoAsync(typeof(TPage).GetCustomAttribute<RouteAttribute>()?.Template ?? "");
5152
await this.Expect(page.GetByTestId("output")).ToHaveValueAsync("Loaded.");
53+
54+
await page.DeleteDatabaseAsync("Animal");
55+
await page.DeleteDatabaseAsync("Client");
56+
await page.DeleteDatabaseAsync("Employee");
5257

5358
await page.GetByTestId("method").FillAsync(ResolveMethod(method));
5459
await page.WaitForTimeoutAsync(500);

E2eTest/WhereTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public class WhereTest : TestBase<WhereTestPage>
99
[TestMethod]
1010
public async Task Where1Test()
1111
{
12-
var page = await this.NewPageAsync();
13-
await page.DeleteDatabaseAsync("Person");
1412
var result = await this.RunTestPageMethodAsync(p => p.Where1);
1513
Assert.AreEqual(result, "OK");
1614
}

E2eTestWebApp/Data/PersonData.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using E2eTestWebApp.Models;
2+
3+
namespace E2eTestWebApp.Data;
4+
5+
public static class PersonData
6+
{
7+
public static Person[] persons =
8+
[
9+
new Person { Name = "Zack", DateOfBirth = null, TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I buried treasure behind my house", Access=Person.Permissions.CanRead},
10+
new Person { Name = "Luna", TestInt = 9, DateOfBirth = new DateTime(1980, 1, 1), _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "Jerry is my husband and I had an affair with Bob.", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite},
11+
new Person { Name = "Jerry", TestInt = 9, DateOfBirth = new DateTime(1981, 1, 1), _Age = 44, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate},
12+
new Person { Name = "Jamie", TestInt = 9, DateOfBirth = new DateTime(1982, 1, 1), _Age = 43, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate},
13+
new Person { Name = "James", TestInt = 9, DateOfBirth = new DateTime(1983, 1, 1), _Age = 42, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate},
14+
new Person { Name = "Jack", TestInt = 9, DateOfBirth = new DateTime(1984, 1, 1), _Age = 41, GUIY = Guid.NewGuid(), DoNotMapTest = "My wife is amazing", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite|Person.Permissions.CanCreate},
15+
new Person { Name = "Jon", TestInt = 9, DateOfBirth = new DateTime(1985, 1, 1), _Age = 40, GUIY = Guid.NewGuid(), DoNotMapTest = "I black mail Luna for money because I know her secret", Access = Person.Permissions.CanRead},
16+
new Person { Name = "Jack", TestInt = 9, DateOfBirth = new DateTime(1986, 1, 1), _Age = 39, GUIY = Guid.NewGuid(), DoNotMapTest = "I have a drug problem", Access = Person.Permissions.CanRead|Person.Permissions.CanWrite},
17+
new Person { Name = "Cathy", TestInt = 9, DateOfBirth = new DateTime(1987, 1, 1), _Age = 38, GUIY = Guid.NewGuid(), DoNotMapTest = "I got away with reading Bobs diary.", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite},
18+
new Person { Name = "Bob", TestInt = 3 , DateOfBirth = new DateTime(1988, 1, 1), _Age = 37, GUIY = Guid.NewGuid(), DoNotMapTest = "I caught Cathy reading my diary, but I'm too shy to confront her.", Access = Person.Permissions.CanRead },
19+
new Person { Name = "Alex", TestInt = 3 , DateOfBirth = null, _Age = 80, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm naked! But nobody can know!" },
20+
new Person { Name = "Zapoo", DateOfBirth = null, TestInt = 9, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I buried treasure behind my house", Access=Person.Permissions.CanRead},
21+
22+
new Person { Name = "Sarah", TestInt = -1, _Age = 30, GUIY = Guid.NewGuid(), DoNotMapTest = "I hate my job", Access=Person.Permissions.CanRead},
23+
new Person { Name = "Michael", TestInt = 15, _Age = 50, GUIY = Guid.NewGuid(), DoNotMapTest = "I'm hiding a big secret", Access=Person.Permissions.CanRead | Person.Permissions.CanWrite},
24+
new Person { Name = "Tommy", TestInt = 7, _Age = 12, GUIY = Guid.NewGuid(), DoNotMapTest = "I am just a kid" },
25+
new Person { Name = "Grace", TestInt = 3, _Age = 90, GUIY = Guid.NewGuid(), DoNotMapTest = "I have seen the world" },
26+
new Person { Name = "Xylophone", TestInt = 9, _Age = 27, GUIY = Guid.NewGuid(), DoNotMapTest = "I have the weirdest name" },
27+
new Person { Name = "Yasmine", TestInt = 9, _Age = 40, GUIY = Guid.NewGuid(), DoNotMapTest = null },
28+
29+
// Additional test case persons to stress-test LINQ validation
30+
new Person { Name = "Alicia", TestInt = 42, _Age = 16, GUIY = Guid.NewGuid(), DoNotMapTest = "I just got my driver's license" },
31+
new Person { Name = "Ben", TestInt = 0, _Age = 25, GUIY = Guid.NewGuid(), DoNotMapTest = "I have no TestInt value" },
32+
new Person { Name = "Clara", TestInt = 100, _Age = 65, GUIY = Guid.NewGuid(), DoNotMapTest = "I retired last week", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite },
33+
new Person { Name = "Danny", TestInt = 9, _Age = 40, GUIY = Guid.NewGuid(), DoNotMapTest = null }, // Null handling
34+
new Person { Name = "Elliot", TestInt = -20, _Age = 55, GUIY = Guid.NewGuid(), DoNotMapTest = "My test int is negative" },
35+
new Person { Name = "Fiona", TestInt = 11, _Age = 33, GUIY = Guid.NewGuid(), DoNotMapTest = "I like puzzles" },
36+
new Person { Name = "George", TestInt = 8, _Age = 72, GUIY = Guid.NewGuid(), DoNotMapTest = "I fought in a war", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite | Person.Permissions.CanCreate },
37+
new Person { Name = "Henry", TestInt = 99, _Age = 29, GUIY = Guid.NewGuid(), DoNotMapTest = "I almost made it to 100 TestInt" },
38+
new Person { Name = "Isla", TestInt = 2, _Age = 18, GUIY = Guid.NewGuid(), DoNotMapTest = "I just turned into an adult" },
39+
new Person { Name = "Jackie", TestInt = 75, _Age = 60, GUIY = Guid.NewGuid(), DoNotMapTest = "I love cooking" },
40+
new Person { Name = "Kevin", TestInt = 5, _Age = 48, GUIY = Guid.NewGuid(), DoNotMapTest = "I own a small business" },
41+
new Person { Name = "Liam", TestInt = 9, _Age = 55, GUIY = Guid.NewGuid(), DoNotMapTest = "I just became a grandfather" },
42+
new Person { Name = "Mona", TestInt = 88, _Age = 35, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a detective", Access = Person.Permissions.CanRead | Person.Permissions.CanWrite },
43+
new Person { Name = "Nathan", TestInt = 7, _Age = 27, GUIY = Guid.NewGuid(), DoNotMapTest = "I play guitar" },
44+
new Person { Name = "Olivia", TestInt = 13, _Age = 45, GUIY = Guid.NewGuid(), DoNotMapTest = "I run marathons" },
45+
new Person { Name = "Patrick", TestInt = 3, _Age = 52, GUIY = Guid.NewGuid(), DoNotMapTest = "I work in IT" },
46+
new Person { Name = "Quinn", TestInt = 22, _Age = 42, GUIY = Guid.NewGuid(), DoNotMapTest = "I design board games" },
47+
new Person { Name = "Rachel", TestInt = 77, _Age = 36, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a pilot" },
48+
new Person { Name = "Steve", TestInt = 9, _Age = 38, GUIY = Guid.NewGuid(), DoNotMapTest = "I am an engineer" },
49+
new Person { Name = "Tina", TestInt = 3, _Age = 68, GUIY = Guid.NewGuid(), DoNotMapTest = "I just got my pension" },
50+
new Person { Name = "Uma", TestInt = 14, _Age = 39, GUIY = Guid.NewGuid(), DoNotMapTest = "I teach yoga" },
51+
new Person { Name = "Victor", TestInt = 6, _Age = 31, GUIY = Guid.NewGuid(), DoNotMapTest = "I am an artist" },
52+
new Person { Name = "Wendy", TestInt = 50, _Age = 50, GUIY = Guid.NewGuid(), DoNotMapTest = "My age matches my test int" },
53+
new Person { Name = "Xander", TestInt = 19, _Age = 21, GUIY = Guid.NewGuid(), DoNotMapTest = "I am a college student" },
54+
new Person { Name = "Yara", TestInt = 90, _Age = 32, GUIY = Guid.NewGuid(), DoNotMapTest = "I work in finance" },
55+
new Person { Name = "Zane", TestInt = 101, _Age = 47, DateOfBirth = new DateTime(2020, 2, 10), GUIY = Guid.NewGuid(), DoNotMapTest = "I love motorcycles" }
56+
];
57+
}

E2eTestWebApp/Models/Person.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,37 @@ public class Person : MagicTableTool<Person>, IMagicTable<Person.DbSets>
1313
{
1414
public List<IMagicCompoundIndex> GetCompoundIndexes() =>
1515
new List<IMagicCompoundIndex>() {
16-
CreateCompoundIndex(x => x.TestIntStable, x => x.Name)
16+
CreateCompoundIndex(x => x.TestIntStable2, x => x.Name)
1717
};
18-
19-
// Endobject when compund key contains two or more keys
20-
public IMagicCompoundKey GetKeys() => CreateCompoundKey(x => x.TestIntStable);
18+
19+
// With this getKeys everything works
20+
public IMagicCompoundKey GetKeys() =>
21+
CreatePrimaryKey(x => x._Id, true);
22+
23+
// sometimes doesn't work, The JSON value could not be converted to System.Boolean
24+
/*public IMagicCompoundKey GetKeys() =>
25+
CreatePrimaryKey(x => x.TestIntStable, true);*/
26+
27+
// Doesnt work, deserialization issue json.endobject
28+
/*public IMagicCompoundKey GetKeys() =>
29+
CreateCompoundKey(x => x.TestIntStable2, x => x.TestIntStable);*/
30+
31+
// sometimes doesn't work, deserialization issue json.endobject
32+
/*public IMagicCompoundKey GetKeys() =>
33+
CreateCompoundKey(x => x.TestIntStable2, x => x._Age);*/
34+
35+
// Doesnt work, deserialization issue json.endobject
36+
/*public IMagicCompoundKey GetKeys() =>
37+
CreateCompoundKey(x => x.TestIntStable, x => x._Age);*/
38+
39+
// Doesnt work, deserialization issue json.endobject
40+
/*public IMagicCompoundKey GetKeys() =>
41+
CreateCompoundKey(x => x.TestIntStable, x => x.Name);*/
42+
43+
// sometimes doesn't work, deserialization issue json.endobject
44+
/*public IMagicCompoundKey GetKeys() =>
45+
CreateCompoundKey(x => x.TestIntStable2);*/
46+
2147

2248
public string GetTableName() => "Person";
2349
public IndexedDbSet GetDefaultDatabase() => IndexDbContext.Client;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Magic.IndexedDb;
2+
using Magic.IndexedDb.Helpers;
3+
using Microsoft.AspNetCore.Components;
4+
using System.Text.Json;
5+
using E2eTestWebApp.Models;
6+
7+
namespace E2eTestWebApp.TestPages;
8+
9+
[Route("/CursorTest")]
10+
public class CursorTestPage(IMagicIndexedDb magic) : TestPageBase
11+
{
12+
public async Task<string> Where1()
13+
{
14+
var db = await magic.Query<Person>();
15+
16+
return "Incorrect";
17+
}
18+
}

E2eTestWebApp/TestPages/WhereTestPage.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ namespace E2eTestWebApp.TestPages;
99
[Route("/WhereTest")]
1010
public class WhereTestPage(IMagicIndexedDb magic) : TestPageBase
1111
{
12-
/*[MagicTable("Records", null)]
13-
private class Record
14-
{
15-
[MagicPrimaryKey("Id")]
16-
public int Id { get; set; }
17-
18-
public int Int32Field { get; set; }
19-
}*/
20-
2112
public async Task<string> Where1()
2213
{
2314
var db = await magic.Query<Person>();

0 commit comments

Comments
 (0)