-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathCustomerApiTests.cs
More file actions
55 lines (46 loc) · 1.57 KB
/
CustomerApiTests.cs
File metadata and controls
55 lines (46 loc) · 1.57 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
using Bogus;
using Equinox.Application.ViewModels;
using Equinox.Tests.Integration.Support;
using System.Net.Http.Json;
using Xunit;
namespace Equinox.Tests.Integration;
public class CustomerApiTests : IClassFixture<CustomWebApplicationFactory>
{
private readonly HttpClient _client;
private readonly Faker _faker = new();
public CustomerApiTests(CustomWebApplicationFactory factory)
{
_client = factory.CreateClient();
}
[Fact(DisplayName = "Posting a new customer should succeed")]
public async Task PostCustomer_ShouldReturnSuccess()
{
// Arrange
var model = new CustomerViewModel
{
Name = _faker.Person.FullName,
Email = _faker.Internet.Email(),
BirthDate = _faker.Person.DateOfBirth.AddYears(-20)
};
// Act
var response = await _client.PostAsJsonAsync("customer", model);
// Assert
Assert.True(response.IsSuccessStatusCode);
}
[Fact(DisplayName = "New customer should appear in get list")]
public async Task CreatedCustomer_ShouldAppear_OnGetAll()
{
// Arrange
var model = new CustomerViewModel
{
Name = _faker.Person.FullName,
Email = _faker.Internet.Email(),
BirthDate = _faker.Person.DateOfBirth.AddYears(-25)
};
await _client.PostAsJsonAsync("customer", model);
// Act
var customers = await _client.GetFromJsonAsync<List<CustomerViewModel>>("customer");
// Assert
Assert.Contains(customers!, c => c.Email == model.Email);
}
}