Skip to content

Commit 9db6ff0

Browse files
committed
Use StateModel for tests
1 parent 5f1286a commit 9db6ff0

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

test/WebApi.IntegrationTests/IntegrationTestBase.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ protected HttpClient CreateClient(bool isAuthorizationNeeded = false)
3333
return client;
3434
}
3535

36-
protected StringContent GeneratePayload()
37-
{
38-
var dummy = new
39-
{
40-
Property1 = Faker.Random.String(),
41-
Property2 = Faker.Random.Int()
42-
};
43-
return Serialize(dummy);
44-
}
45-
4636
protected static StringContent Serialize<T>(T value, string mediaType = "application/json")
4737
{
4838
return new StringContent(JsonSerializer.Serialize(value), Encoding.UTF8, mediaType);

test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public async Task StateResource_CreateFindDelete_IsSuccess()
2828
// Arrange
2929
var client = CreateClient(true);
3030
var name = Faker.Random.Word();
31-
var payload = GeneratePayload();
31+
var state = StateFaker.Generate();
3232

3333
// Act & Assert
34-
var createResponse = await client.PostAsync($"/state/{name}", payload);
34+
var createResponse = await client.PostAsync($"/state/{name}", Serialize(state));
3535
//TODO: test resource URL in response
3636
await createResponse.CheckResponseAndGetContent(HttpStatusCode.OK, null, string.Empty);
3737
var findResponse = await client.GetAsync($"/state/{name}");
@@ -46,8 +46,8 @@ public async Task StateResource_LockLifeCycle_IsSuccess()
4646
// Arrange
4747
var client = CreateClient(true);
4848
var name = Faker.Random.Word();
49+
var state = StateFaker.Generate();
4950
var stateLock = StateLockFaker.Generate();
50-
var payload = GeneratePayload();
5151

5252
// Act & Assert
5353
var createLockResponse = await client.PostAsync($"/state/{name}/lock", Serialize(stateLock));
@@ -56,11 +56,11 @@ public async Task StateResource_LockLifeCycle_IsSuccess()
5656
{
5757
Content = Serialize(stateLock)
5858
};
59-
var missingLockIdUpdateResponse = await client.PostAsync($"/state/{name}", payload);
59+
var missingLockIdUpdateResponse = await client.PostAsync($"/state/{name}", Serialize(state));
6060
await missingLockIdUpdateResponse.CheckResponseAndGetContent(HttpStatusCode.Locked, "application/json; charset=utf-8", "{\"message\":\"The state is locked.\"}");
61-
var wrongLockIdUpdateResponse = await client.PostAsync($"/state/{name}?ID=1234", payload);
61+
var wrongLockIdUpdateResponse = await client.PostAsync($"/state/{name}?ID=1234", Serialize(state));
6262
await wrongLockIdUpdateResponse.CheckResponseAndGetContent(HttpStatusCode.Conflict, "text/plain; charset=utf-8", "LockId doesn't match with the existing lock");
63-
var updateResponse = await client.PostAsync($"/state/{name}?ID={stateLock.Id}", payload);
63+
var updateResponse = await client.PostAsync($"/state/{name}?ID={stateLock.Id}", Serialize(state));
6464
await updateResponse.CheckResponseAndGetContent(HttpStatusCode.OK, null, string.Empty);
6565
var deleteLockResponse = await client.SendAsync(deleteLockRequest);
6666
await deleteLockResponse.CheckResponseAndGetContent(HttpStatusCode.OK, null);

0 commit comments

Comments
 (0)