1- using Devpro . TerraformBackend . WebApi . IntegrationTests . Http ;
1+ using System . Net ;
2+ using Devpro . TerraformBackend . WebApi . IntegrationTests . Http ;
23
34namespace Devpro . TerraformBackend . WebApi . IntegrationTests . Resources ;
45
@@ -18,7 +19,7 @@ public async Task StateResource_GetNotExisting_ReturnsNoContent()
1819 var response = await client . GetAsync ( $ "/state/{ name } ") ;
1920
2021 // Assert
21- await response . CheckResponseAndGetContent ( System . Net . HttpStatusCode . NoContent , null ) ;
22+ await response . CheckResponseAndGetContent ( HttpStatusCode . NoContent , null ) ;
2223 }
2324
2425 [ Fact ]
@@ -35,7 +36,7 @@ public async Task StateResource_CreateNew_ReturnsCreated()
3536
3637 // Assert
3738 //TODO: test resource URL in response
38- await response . CheckResponseAndGetContent ( System . Net . HttpStatusCode . OK , null , string . Empty ) ;
39+ await response . CheckResponseAndGetContent ( HttpStatusCode . OK , null , string . Empty ) ;
3940 }
4041
4142 [ Fact ]
@@ -45,9 +46,22 @@ public async Task StateResource_LockLifeCycle_IsSuccess()
4546 var client = CreateClient ( true ) ;
4647 var name = Faker . Random . Word ( ) ;
4748 var stateLock = StateLockFaker . Generate ( ) ;
49+ var payload = GeneratePayload ( ) ;
4850
4951 // Act & Assert
5052 var createLockResponse = await client . PostAsync ( $ "/state/{ name } /lock", Serialize ( stateLock ) ) ;
51- await createLockResponse . CheckResponseAndGetContent ( System . Net . HttpStatusCode . OK , "application/json; charset=utf-8" , null ) ;
53+ await createLockResponse . CheckResponseAndGetContent ( HttpStatusCode . OK , "application/json; charset=utf-8" , null ) ;
54+ var deleteLockRequest = new HttpRequestMessage ( HttpMethod . Delete , $ "/state/{ name } /lock")
55+ {
56+ Content = Serialize ( stateLock )
57+ } ;
58+ var missingLockIdUpdateResponse = await client . PostAsync ( $ "/state/{ name } ", payload ) ;
59+ await missingLockIdUpdateResponse . CheckResponseAndGetContent ( HttpStatusCode . Locked , "application/json; charset=utf-8" , "{\" message\" :\" The state is locked.\" }" ) ;
60+ var wrongLockIdUpdateResponse = await client . PostAsync ( $ "/state/{ name } ?ID=1234", payload ) ;
61+ await wrongLockIdUpdateResponse . CheckResponseAndGetContent ( HttpStatusCode . Conflict , "text/plain; charset=utf-8" , "LockId doesn't match with the existing lock" ) ;
62+ var updateResponse = await client . PostAsync ( $ "/state/{ name } ?ID={ stateLock . Id } ", payload ) ;
63+ await updateResponse . CheckResponseAndGetContent ( HttpStatusCode . OK , null , string . Empty ) ;
64+ var deleteLockResponse = await client . SendAsync ( deleteLockRequest ) ;
65+ await deleteLockResponse . CheckResponseAndGetContent ( HttpStatusCode . OK , null ) ;
5266 }
5367}
0 commit comments