Skip to content

Commit 268b88f

Browse files
committed
Merge branch 'release/v0.1.0'
2 parents e5c4018 + 50fd22b commit 268b88f

52 files changed

Lines changed: 2989 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API.Test/API.Test.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
14+
<PackageReference Include="NUnit" Version="3.13.3" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
16+
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
17+
<PackageReference Include="coverlet.collector" Version="3.2.0" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\WebUntisAPI.Client\WebUntisAPI.Client.csproj" />
22+
</ItemGroup>
23+
24+
</Project>

API.Test/AuthentificationTests.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using WebUntisAPI.Client;
7+
8+
namespace API.Test;
9+
10+
[Order(3)]
11+
[TestFixture]
12+
internal class AuthentificationTests
13+
{
14+
public static WebUntisClient Client { get; set; } = new("WebUntisAPI_TEST", 1000);
15+
16+
static AuthentificationTests()
17+
{
18+
// Load a file where i saved login data
19+
using StreamReader str = new("LoginData.txt");
20+
s_Server = str.ReadLine();
21+
s_LoginName = str.ReadLine();
22+
s_UserName = str.ReadLine();
23+
s_Password = str.ReadLine();
24+
}
25+
26+
// Login data to test
27+
public static string s_Server;
28+
public static string s_LoginName;
29+
public static string s_UserName;
30+
public static string s_Password;
31+
32+
[Test]
33+
public void Authentification()
34+
{
35+
try
36+
{
37+
using WebUntisClient client = new("WebUntisAPI_TEST");
38+
client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
39+
client.LogoutAsync().Wait();
40+
}
41+
catch
42+
{
43+
Assert.Fail();
44+
return;
45+
}
46+
Assert.Pass();
47+
}
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using WebUntisAPI.Client.Extensions;
8+
9+
namespace API.Test.ExtensionsTests;
10+
11+
[TestFixture]
12+
internal class ColorExtensionsTests
13+
{
14+
[Test]
15+
public void ToHexColorFormat()
16+
{
17+
// Example 1
18+
Color c1 = Color.FromArgb(200, 150, 255);
19+
Assert.That(c1.ToHexColorFormat(), Is.EqualTo("C896FF"));
20+
21+
// Example 2
22+
Color c2 = Color.FromArgb(10, 16, 0);
23+
Assert.That(c2.ToHexColorFormat(), Is.EqualTo("0A1000"));
24+
}
25+
26+
[Test]
27+
public void FromHexColorFormat()
28+
{
29+
// Example 1
30+
Color c1 = Color.FromArgb(200, 150, 255);
31+
Assert.That(new Color().FromHexColorFormat("C896FF"), Is.EqualTo(c1));
32+
33+
// Example 2
34+
Color c2 = Color.FromArgb(10, 16, 0);
35+
Assert.That(new Color().FromHexColorFormat("0A1000"), Is.EqualTo(c2));
36+
}
37+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using WebUntisAPI.Client.Extensions;
7+
8+
namespace API.Test.ExtensionsTests;
9+
10+
[Order(1)]
11+
[TestFixture]
12+
internal class DateTimeExtensionTests
13+
{
14+
[Order(1)]
15+
[Test]
16+
public static void ToWebUntisTimeFormatTest()
17+
{
18+
// Example 1 (True)
19+
new DateTime(2023, 5, 31, 20, 0, 0).ToWebUntisTimeFormat(out string E1_Date, out string E1_Time);
20+
string E1_Date_Res = "20230531";
21+
string E1_Time_Res = "2000";
22+
Assert.Multiple(() =>
23+
{
24+
Assert.That(E1_Date, Is.EqualTo(E1_Date_Res));
25+
Assert.That(E1_Time, Is.EqualTo(E1_Time_Res));
26+
});
27+
28+
// Example 2 (True)
29+
new DateTime(2019, 12, 2, 7, 40, 0).ToWebUntisTimeFormat(out string E2_Date, out string E2_Time);
30+
string E2_Date_Res = "20191202";
31+
string E2_Time_Res = "740";
32+
Assert.Multiple(() =>
33+
{
34+
Assert.That(E2_Date, Is.EqualTo(E2_Date_Res));
35+
Assert.That(E2_Time, Is.EqualTo(E2_Time_Res));
36+
});
37+
}
38+
39+
[Order(2)]
40+
[Test]
41+
public static void FromWebUntisTimeFormatTest()
42+
{
43+
// Example 1
44+
string E1_Date = "20230531";
45+
string E1_Time = "2000";
46+
DateTime? E1_DateTime = new DateTime().FromWebUntisTimeFormat(E1_Date, E1_Time);
47+
Assert.That(new DateTime(2023, 5, 31, 20, 0, 0), Is.EqualTo(E1_DateTime));
48+
49+
// Example 2
50+
string E2_Date = "20230601";
51+
string E2_Time = "740";
52+
DateTime? E2_DateTime = new DateTime().FromWebUntisTimeFormat(E2_Date, E2_Time);
53+
Assert.That(new DateTime(2023, 6, 1, 7, 40, 0), Is.EqualTo(E2_DateTime));
54+
}
55+
}

API.Test/SchoolSearchTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using WebUntisAPI.Client;
7+
using WebUntisAPI.Client.Exceptions;
8+
using WebUntisAPI.Client.Models;
9+
10+
namespace API.Test;
11+
12+
[Order(2)]
13+
[TestFixture]
14+
internal class SchoolSearchTests
15+
{
16+
[Order(1)]
17+
[Test]
18+
public void NormalSearch()
19+
{
20+
Task<School[]> schools = SchoolSearch.SearchAsync("Marie-Curie");
21+
schools.Wait();
22+
if (schools.Result.Length > 0)
23+
Assert.Pass();
24+
else
25+
Assert.Fail();
26+
}
27+
28+
[Order(2)]
29+
[Test]
30+
public void ToManySchoolsFound()
31+
{
32+
Task<School[]> schools = SchoolSearch.SearchAsync("M");
33+
schools.Wait();
34+
if (schools.Result == null)
35+
Assert.Pass();
36+
else
37+
Assert.Fail();
38+
}
39+
40+
[Order(3)]
41+
[Test]
42+
public void NoSchoolsFound()
43+
{
44+
Task<School[]> schools = SchoolSearch.SearchAsync("MMMMMMMMMMMMMMMMMMMMMMMMMMM");
45+
schools.Wait();
46+
if (schools.Result.Length == 0)
47+
Assert.Pass();
48+
else
49+
Assert.Fail();
50+
}
51+
}

API.Test/TeachingTests.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using WebUntisAPI.Client.Models;
7+
using static API.Test.AuthentificationTests;
8+
9+
namespace API.Test;
10+
11+
[Order(5)]
12+
[TestFixture]
13+
internal class TeachingTests
14+
{
15+
[Test]
16+
public void GetSubject()
17+
{
18+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
19+
20+
Task<Subject[]> subjects = Client.GetAllSubjectsAsync();
21+
subjects.Wait();
22+
if (subjects.Result.Length > 0)
23+
Assert.Pass();
24+
else
25+
Assert.Fail();
26+
}
27+
28+
[Test]
29+
public void GetClass()
30+
{
31+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
32+
33+
Task<Class[]> classes = Client.GetClassesAsync(new SchoolYear() { Id = 5});
34+
classes.Wait();
35+
if (classes.Result.Length > 0)
36+
Assert.Pass();
37+
else
38+
Assert.Fail();
39+
}
40+
41+
[Test]
42+
public void GetRoom()
43+
{
44+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
45+
46+
Task<Room[]> rooms = Client.GetAllRoomsAsync();
47+
rooms.Wait();
48+
if (rooms.Result.Length > 0)
49+
Assert.Pass();
50+
else
51+
Assert.Fail();
52+
}
53+
54+
[Test]
55+
public void GetDepartment()
56+
{
57+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
58+
59+
Task<Department[]> departments = Client.GetAllDepartmentsAsync();
60+
departments.Wait();
61+
if (departments.Result != null)
62+
Assert.Pass();
63+
else
64+
Assert.Fail();
65+
}
66+
67+
[Test]
68+
public void GetLatestImportTime()
69+
{
70+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
71+
72+
Task<DateTime> time = Client.GetLatestImportTimeAsync();
73+
time.Wait();
74+
if (time.Result <= DateTime.Now)
75+
Assert.Pass();
76+
else
77+
Assert.Fail();
78+
}
79+
}

API.Test/TimeTableTests.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using WebUntisAPI.Client.Models;
8+
using static API.Test.AuthentificationTests;
9+
10+
namespace API.Test;
11+
12+
[TestFixture]
13+
internal class TimeTableTests
14+
{
15+
[Test]
16+
public void GetStatusData()
17+
{
18+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
19+
20+
Task<StatusData> status = Client.GetStatusDataAsync();
21+
status.Wait();
22+
if (status.Result != null)
23+
Assert.Pass();
24+
else
25+
Assert.Fail();
26+
}
27+
28+
[Test]
29+
public void GetTimeGrid()
30+
{
31+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
32+
33+
Task<Timegrid> timegrid = Client.GetTimegridAsync();
34+
timegrid.Wait();
35+
if (timegrid.Result.SchoolDayCount > 0)
36+
Assert.Pass();
37+
else
38+
Assert.Fail();
39+
}
40+
41+
[Test]
42+
public void GetSchoolYears()
43+
{
44+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
45+
46+
Task<SchoolYear[]> schoolYears = Client.GetAllSchoolYearsAsync();
47+
schoolYears.Wait();
48+
if (schoolYears.Result.Length > 0)
49+
Assert.Pass();
50+
else
51+
Assert.Fail();
52+
}
53+
54+
[Test]
55+
public void GetCurrentSchoolYear()
56+
{
57+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
58+
59+
Task<SchoolYear> schoolYear = Client.GetCurrentSchoolYearAsync();
60+
schoolYear.Wait();
61+
if (schoolYear.Result != null)
62+
Assert.Pass();
63+
else
64+
Assert.Fail();
65+
}
66+
67+
[Test]
68+
public void GetHolidays()
69+
{
70+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
71+
72+
Task<Holidays[]> holidays = Client.GetAllHolidaysAsync();
73+
holidays.Wait();
74+
if (holidays.Result.Length > 0)
75+
Assert.Pass();
76+
else
77+
Assert.Fail();
78+
}
79+
80+
[Test]
81+
public void GetTimetable()
82+
{
83+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
84+
85+
Task<Period[]> timetable = Client.GetTimetableForStudentAsync(Client.User as Student, new DateTime(2023, 05, 29), new DateTime(2023, 09, 2));
86+
timetable.Wait();
87+
if (timetable.Result.Length > 0)
88+
Assert.Pass();
89+
else
90+
Assert.Fail();
91+
}
92+
}

0 commit comments

Comments
 (0)