Skip to content

Commit 1cdfb72

Browse files
author
Mark
committed
Added a test app to test live api
1 parent 94c4d7c commit 1cdfb72

38 files changed

+517
-86
lines changed

APIDtos/APIDtos.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
11+
</ItemGroup>
12+
913
</Project>

APIDtos/BookingDto.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace APIDtos;
2+
3+
public class BookingDto
4+
{
5+
public BookingDto(Guid id, DateTime bookingTimeUtc, ShowtimeWithIdDto showtime, SeatReservationWithIdDto seatReservation)
6+
{
7+
Id = id;
8+
BookingTimeUtc = bookingTimeUtc;
9+
Showtime = showtime;
10+
SeatReservation = seatReservation;
11+
}
12+
13+
public Guid Id { get; set; }
14+
public DateTime BookingTimeUtc { get; set; }
15+
public ShowtimeWithIdDto Showtime { get; set; }
16+
public SeatReservationWithIdDto SeatReservation { get; set; }
17+
18+
public override string ToString()
19+
{
20+
return $"Id: {Id}, BookingTimeUtc: {BookingTimeUtc}, Showtime: {Showtime}, SeatReservation: {SeatReservation}";
21+
}
22+
}

Api/Dtos/MovieDto.cs APIDtos/MovieDto.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Api.Dtos;
1+
namespace APIDtos;
22

33
public record MovieDto
44
{
@@ -9,7 +9,7 @@ public record MovieDto
99
public DateTime ReleaseDateUtc { get; set; }
1010
public MovieStatus MovieStatus { get; set; }
1111

12-
public MovieDto(string title, string description, int durationMins, string genre, DateTime releaseDateUtc, MovieStatus movieStatus)
12+
public MovieDto(string title, string description, int durationMins, string genre, DateTime releaseDateUtc, MovieStatus movieStatus = MovieStatus.Available)
1313
{
1414
Title = title;
1515
Description = description;

Api/Dtos/MovieWithIdDto.cs APIDtos/MovieWithIdDto.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Api.Dtos;
1+
namespace APIDtos;
22

33
public record MovieWithIdDto : MovieDto
44
{

APIDtos/ScreenDto.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace APIDtos;
2+
3+
public record ScreenDto(string ScreenNumber, bool IsEnable, List<SeatDto>? Seats = null)
4+
{
5+
public string ScreenNumber { get; set; } = ScreenNumber;
6+
public bool IsEnabled { get; set; } = IsEnable;
7+
8+
public List<SeatDto> Seats { get; set; } = Seats ?? [];
9+
}

APIDtos/ScreenWithIdDto.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace APIDtos;
2+
3+
public record ScreenWithIdDto(Guid Id, string ScreenNumber, bool IsEnable, List<SeatWithIdDto> Seats)
4+
{
5+
public Guid Id { get; set; } = Id;
6+
public string ScreenNumber { get; set; } = ScreenNumber;
7+
public bool IsEnabled { get; set; } = IsEnable;
8+
9+
public List<SeatWithIdDto> Seats { get; set; } = Seats ?? [];
10+
}

APIDtos/SeatDto.cs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace APIDtos;
2+
3+
public record SeatDto(string SeatNumber)
4+
{
5+
public string SeatNumber { get; } = SeatNumber;
6+
}

APIDtos/SeatReservationDto.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace APIDtos;
2+
3+
public record SeatReservationDto
4+
{
5+
public List<string> Seats { get; set; }
6+
7+
public int ShowtimeId { get; set; }
8+
9+
public SeatReservationDto(List<string> seats, int showtimeId)
10+
{
11+
Seats = seats;
12+
ShowtimeId = showtimeId;
13+
}
14+
15+
}

APIDtos/SeatReservationWithIdDto.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace APIDtos;
2+
3+
public record SeatReservationWithIdDto
4+
{
5+
public Guid Id;
6+
public List<string> Seats;
7+
public int ShowtimeId;
8+
public DateTime? ReservationTimeoutUtc;
9+
public SeatReservationStatus Status;
10+
11+
public SeatReservationWithIdDto(Guid id, List<string> seats, int showtimeId, DateTime? reservationTimeoutUtc, SeatReservationStatus status)
12+
{
13+
Id = id;
14+
Seats = seats;
15+
ShowtimeId = showtimeId;
16+
ReservationTimeoutUtc = reservationTimeoutUtc;
17+
Status = status;
18+
}
19+
20+
public enum SeatReservationStatus
21+
{
22+
Provisional,
23+
Confirmed
24+
}
25+
26+
public override string ToString()
27+
{
28+
return $"Id: {Id}, Seats: {Seats}, ShowtimeId: {ShowtimeId}, ReservationTimeoutUtc: {ReservationTimeoutUtc}, Status: {Status}";
29+
}
30+
}

APIDtos/SeatWithIdDto.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace APIDtos;
2+
3+
public record SeatWithIdDto
4+
{
5+
public string SeatNumber { get; }
6+
7+
public Guid Id { get; }
8+
9+
public SeatWithIdDto(Guid id, string seatNumber)
10+
{
11+
Id = id;
12+
SeatNumber = seatNumber;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
// DTO for the Showtime.cs entity
2-
public record ShowtimeWithIdDto
1+
namespace APIDtos;
2+
public record ShowtimeDto
33
{
4-
public ShowtimeWithIdDto(int id, int movieId, Guid screenId, DateTime showDateTimeUtc, decimal price)
4+
public ShowtimeDto(int movieId, Guid screenId, DateTime showDateTimeUtc, decimal price)
55
{
6-
Id = id;
76
MovieId = movieId;
87
ScreenId = screenId;
98
ShowDateTimeUtc = showDateTimeUtc;
109
Price = price;
1110
}
1211

13-
public int Id { get; set; }
1412
public int MovieId { get; set; }
1513
public Guid ScreenId { get; set; }
1614
public DateTime ShowDateTimeUtc { get; set; }
1715
public decimal Price { get; set; }
18-
1916
}

APIDtos/ShowtimeWithIdDto.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace APIDtos;
2+
public record ShowtimeWithIdDto : ShowtimeDto
3+
{
4+
public ShowtimeWithIdDto(int id, int movieId, Guid screenId, DateTime showDateTimeUtc, decimal price)
5+
: base(movieId, screenId, showDateTimeUtc, price)
6+
{
7+
Id = id;
8+
}
9+
10+
public int Id { get; set; }
11+
12+
13+
public override string ToString()
14+
{
15+
return $"Id: {Id}, MovieId: {MovieId}, ScreenId: {ScreenId}, ShowDateTimeUtc: {ShowDateTimeUtc}, Price: {Price}";
16+
}
17+
}

Api/Dtos/TheaterChainDto.cs APIDtos/TheaterChainDto.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Api.Dtos;
1+
namespace APIDtos;
22

33
public record TheaterChainDto
44
{
@@ -12,4 +12,9 @@ public TheaterChainDto(int id, string name, string description)
1212
public int Id { get; }
1313
public string Name { get; set; }
1414
public string Description { get; set; }
15+
16+
public override string ToString()
17+
{
18+
return $"Id: {Id}, Name: {Name}, Description: {Description}";
19+
}
1520
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace Api.Dtos;
1+
namespace APIDtos;
22

3-
public class TheaterDto(string name, string location, List<ScreenWithIdDto> screens)
3+
public class TheaterDto(string name, string location, List<ScreenWithIdDto>? screensWithIdDto = null)
44
{
55
public string Name { get; set; } = name;
66
public string Location { get; set; } = location;
77

8-
public List<ScreenWithIdDto> Screens { get; set; } = screens;
8+
public List<ScreenWithIdDto> ScreensWithIdDto { get; set; } = screensWithIdDto ?? [];
99
}

Api/Dtos/TheaterWithIdDto.cs APIDtos/TheaterWithIdDto.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Api.Dtos;
1+
namespace APIDtos;
22
public class TheaterWithIdDto(int id, string name, string location, List<ScreenWithIdDto> screensWithIdDto)
33
: TheaterDto(name, location, screensWithIdDto)
44
{

APITesterApp/APITesterApp.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,13 @@
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.6.2" />
12+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\APIDtos\APIDtos.csproj" />
17+
</ItemGroup>
18+
1019
</Project>

APITesterApp/HttpLoggerHandler.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
public class HttpLoggingHandler : DelegatingHandler
2+
{
3+
public HttpLoggingHandler(HttpMessageHandler innerHandler) : base(innerHandler)
4+
{
5+
}
6+
7+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
8+
{
9+
Console.WriteLine($"Request: {request.Method} {request.RequestUri}");
10+
11+
// Optionally log the request headers and body
12+
foreach (KeyValuePair<string, IEnumerable<string>> header in request.Headers)
13+
{
14+
Console.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}");
15+
}
16+
17+
if (request.Content != null)
18+
{
19+
string requestBody = await request.Content.ReadAsStringAsync();
20+
Console.WriteLine($"Request Body: {requestBody}");
21+
}
22+
23+
System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
24+
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
25+
stopwatch.Stop();
26+
27+
Console.WriteLine($"Response: {response.StatusCode} in {stopwatch.ElapsedMilliseconds}ms");
28+
29+
// Optionally log the response headers and body
30+
foreach (KeyValuePair<string, IEnumerable<string>> header in response.Headers)
31+
{
32+
Console.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}");
33+
}
34+
35+
if (response.Content != null)
36+
{
37+
string responseBody = await response.Content.ReadAsStringAsync();
38+
Console.WriteLine($"Response Body: {responseBody}");
39+
}
40+
41+
return response;
42+
}
43+
}

0 commit comments

Comments
 (0)