-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIntegrationTestTemplate.txt
More file actions
69 lines (58 loc) · 2.29 KB
/
IntegrationTestTemplate.txt
File metadata and controls
69 lines (58 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace exercise.tests.IntegrationTests
{
public class ValidationTests
{
private WebApplicationFactory<Program> _factory;
private HttpClient _client;
[SetUp]
public void SetUp()
{
// Arrange
_factory = new WebApplicationFactory<Program>();
_client = _factory.CreateClient();
}
[TearDown]
public void TearDown()
{
_client.Dispose();
_factory.Dispose();
}
[TestCase("Valid123!", HttpStatusCode.OK)]
[TestCase("short1!", HttpStatusCode.BadRequest)]
[TestCase("noupper123!", HttpStatusCode.BadRequest)]
public async Task validatePasswordStatus(string input, HttpStatusCode statusCode)
{
// Arrange
PasswordDTO body = new PasswordDTO { password = input };
var json = JsonSerializer.Serialize(body);
var requestBody = new StringContent(json, Encoding.UTF8, "application/json");
// Act
var response = await _client.PostAsync("/validation/password", requestBody);
// Assert
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
}
[TestCase("Valid123!", "Accepted")]
[TestCase("short1!", "Too few characters")]
[TestCase("noupper123!", "Missing uppercase characters")]
public async Task validatePasswordMessage(string input, string expected)
{
// Arrange
PasswordDTO body = new PasswordDTO { password = input };
var json = JsonSerializer.Serialize(body);
Console.WriteLine(json.ToString());
var requestBody = new StringContent(json, Encoding.UTF8, "application/json");
// Act
var response = await _client.PostAsync("/validation/password", requestBody);
Console.WriteLine("r,",response);
// Assert
var contentString = await response.Content.ReadAsStringAsync();
JsonNode? message = null;
if (!string.IsNullOrWhiteSpace(contentString))
{
message = JsonNode.Parse(contentString);
}
Console.WriteLine("Message: " + message);
Assert.That(message?.ToString(), Is.EqualTo(expected));
}
}
}