Ejemplo n.º 1
0
        public async Task Should_Not_CreateClient_When_Payload_Data_Is_Missing()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            var client = new ClientCreateDto
            {
                TenantId      = createdTenant.TenantId,
                FirstName     = "",
                LastName      = "any",
                ContactNumber = "any",
                EmailAddress  = "any",
                Country       = "any",
                ClientType    = ClientType.Free.ToString()
            };
            var payload = JsonConvert.SerializeObject(client);

            // Act
            var createClientResponse = await customHttpClient.PostAsync("/api/clients", new StringContent(payload, Encoding.UTF8, "application/json"));

            // Assert
            createClientResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var createClientResponseBody = await createClientResponse.Content.ReadAsStringAsync();

            createClientResponseBody.Should().Contain("The FirstName field is required");
        }
Ejemplo n.º 2
0
        public async Task Should_MoveClientToNewTenant()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant1   = await TenantsControllerTests.CreateTenant(customHttpClient);

            var createdClient = await CreateClient(customHttpClient, createdTenant1.TenantId);

            var createdTenant2 = await TenantsControllerTests.CreateTenant(customHttpClient);

            var clientTenantUpdateDto = new ClientTenantUpdateDto
            {
                TenantId = createdTenant2.TenantId
            };
            var patchPayload = JsonConvert.SerializeObject(clientTenantUpdateDto);

            // Act
            var patchResponse = await customHttpClient.PatchAsync($"/api/clients/{createdClient.ClientId}", new StringContent(patchPayload, Encoding.UTF8, "application/json"));

            // Assert
            patchResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var patchResponseBody = await patchResponse.Content.ReadAsStringAsync();

            var movedToNewTenantClient = JsonConvert.DeserializeObject <ClientReadDto>(patchResponseBody);

            movedToNewTenantClient.TenantId.Should().Be(createdTenant2.TenantId);
        }
Ejemplo n.º 3
0
        public async Task Should_UpdateClient()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            var createdClient = await CreateClient(customHttpClient, createdTenant.TenantId);

            var updatedClientDto = new ClientUpdateDto
            {
                FirstName     = "any",
                LastName      = "any",
                ContactNumber = "any",
                EmailAddress  = "any",
                Country       = "new Country",
                ClientType    = ClientType.Subscriber.ToString()
            };
            var updatePayload = JsonConvert.SerializeObject(updatedClientDto);

            // Act
            var updateResponse = await customHttpClient.PutAsync($"/api/clients/{createdClient.ClientId}", new StringContent(updatePayload, Encoding.UTF8, "application/json"));

            // Assert
            updateResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var updateResponseBody = await updateResponse.Content.ReadAsStringAsync();

            var updatedClient = JsonConvert.DeserializeObject <ClientReadDto>(updateResponseBody);

            updatedClient.Country.Should().Be("new Country");
            updatedClient.ClientType.Should().Be(ClientType.Subscriber.ToString());
            updatedClient.TenantId.Should().Be(createdClient.TenantId);
        }
Ejemplo n.º 4
0
        public async Task Should_Not_Return_DeletedClient()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            var createdClient = await CreateClient(customHttpClient, createdTenant.TenantId);

            // Act
            var getResponseBeforeDeletion = await customHttpClient.GetAsync($"/api/clients/{createdClient.ClientId}");

            //Assert
            getResponseBeforeDeletion.StatusCode.Should().Be(HttpStatusCode.OK);

            // Act
            var deleteResponse = await customHttpClient.DeleteAsync($"/api/clients/{createdClient.ClientId}");

            //Assert
            deleteResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);

            // Act
            var getResponseAfterDeletion = await customHttpClient.GetAsync($"/api/clients/{createdClient.ClientId}");

            //Assert
            getResponseAfterDeletion.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
Ejemplo n.º 5
0
        public async Task Should_CreateClient()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            // Act, Assert
            await CreateClient(customHttpClient, createdTenant.TenantId);
        }
Ejemplo n.º 6
0
        public async Task Should_Get_ClientById()
        {
            // Arrange
            var customHttpClient = new CustomWebApplicationFactory <Startup>(Guid.NewGuid().ToString()).CreateClient();
            var createdTenant    = await TenantsControllerTests.CreateTenant(customHttpClient);

            var createdClient = await CreateClient(customHttpClient, createdTenant.TenantId);

            // Act
            var getResponse = await customHttpClient.GetAsync($"/api/clients/{createdClient.ClientId}");

            //Assert
            getResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var responseBody = await getResponse.Content.ReadAsStringAsync();

            var retrievedClient = JsonConvert.DeserializeObject <ClientReadDto>(responseBody);

            retrievedClient.Should().NotBeNull();
            retrievedClient.ClientId.Should().Be(createdClient.ClientId);
        }