Skip to content

Commit 5760de8

Browse files
committed
Added test case to check that book has been added
1 parent f3fd23a commit 5760de8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

SeleniumTests/lib/helpers/BookStoreClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ public async Task<HttpResponseMessage> CreateUserAsync(UserRequestDto user)
3535
return await _client.PostAsJsonAsync("/Account/v1/User", user);
3636
}
3737

38+
public async Task<GetUserResponseDto> GetUserAsync(string userId, string token)
39+
{
40+
Console.WriteLine($"GET /Account/v1/User/{userId}");
41+
42+
var request = new HttpRequestMessage(HttpMethod.Get, $"/Account/v1/User/{userId}");
43+
request.Headers.Add("Authorization", $"Bearer {token}");
44+
45+
var response = await _client.SendAsync(request);
46+
response.EnsureSuccessStatusCode();
47+
48+
return await response.Content.ReadFromJsonAsync<GetUserResponseDto>()
49+
?? new GetUserResponseDto();
50+
}
51+
52+
3853
public async Task<TokenResponseDto?> GenerateTokenAsync(UserRequestDto user)
3954
{
4055
Console.WriteLine("POST /GenerateToken");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SeleniumTests.lib.models;
2+
3+
public class GetUserResponseDto
4+
{
5+
public string UserId { get; set; } = string.Empty;
6+
public string Username { get; set; } = string.Empty;
7+
public List<BookDto> Books { get; set; } = new();
8+
}

SeleniumTests/tests/api/BookTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,23 @@ public async Task AddBookToUser_ShouldReturn201()
3636
{
3737
var books = await Client.GetAllBooksAsync();
3838
var isbn = books.Books.First().ISBN;
39-
4039
var addRes = await Client.AddBookToUserAsync(_userId, isbn, _token);
4140
Assert.That((int)addRes.StatusCode, Is.EqualTo(201));
4241
}
4342

43+
[Test]
44+
public async Task Verify_ThatBooksBeenAdded_ShouldReturn200()
45+
{
46+
var books = await Client.GetAllBooksAsync();
47+
var isbn = books.Books.First().ISBN;
48+
await Client.AddBookToUserAsync(_userId, isbn, _token);
49+
50+
var getRes = await Client.GetUserAsync(_userId, _token);
51+
Assert.That(getRes, Is.Not.Null);
52+
Assert.That(getRes.Books, Is.Not.Empty);
53+
Assert.That(getRes.Books[0].ISBN, Is.EqualTo(isbn));
54+
}
55+
4456
[Test]
4557
public async Task DeleteBookFromUser_ShouldReturn204()
4658
{

0 commit comments

Comments
 (0)