Beispiel #1
0
        public async Task UpdatePlayerIncrementalJsonPatch_BadRequest_TestAsync()
        {
            //Arrange
            int playerId = 1;
            var player   = new PlayerDto
            {
                Description = "He's still playing for Chelsea."
            };

            var request = TestExtensions.GetJsonRequest(player, "PATCH", $"/world-cup/v1/players/{playerId}/update");
            //Act
            var response = await _httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Beispiel #2
0
        public async Task CreateNewPlayer_BadRequest_TestAsync()
        {
            //Arrange
            var player = new NewPlayerDto
            {
                FirstName   = "Test Player",
                Description = "He plays for Codit.",
                IsTopPlayer = false
            };
            var request = TestExtensions.GetJsonRequest(player, "POST", "/world-cup/v1/players");
            //Act
            var response = await _httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Beispiel #3
0
        public async Task CreateNewCustomization_BadRequest_TestAsync()
        {
            //Arrange
            var newCustomization = new NewCustomizationDto
            {
                Name           = "My Customization",
                InventoryLevel = 1,
                CarId          = 200
            };
            var request = TestExtensions.GetJsonRequest(newCustomization, "POST", "/codito/v1/customization/");
            //Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task ProblemJson_Validation_400_Test()
        {
            //Arrange
            var customization = new NewCustomizationDto
            {
                Name = "My customization",
            };
            var request = TestExtensions.GetJsonRequest(customization, "POST", "/codito/v1/customization");
            //Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            response.Content.Headers.ContentLength.Should().BeGreaterThan(0);
            response.ShouldBeProblemJson();
        }
Beispiel #5
0
        public async Task UpdateCustomizationIncremental_NotFound_TestAsync()
        {
            //Arrange
            int id            = -1;
            var customization = new CustomizationDto
            {
                InventoryLevel = 100
            };

            var request = TestExtensions.GetJsonRequest(customization, "PATCH", $"/codito/v1/customization/{id}");

            // Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
        public async Task ProblemJson_UnsupportedContentType_415_Test()
        {
            //Arrange
            var customization = new NewCustomizationDto
            {
                Name  = "My customization",
                CarId = 1
            };
            var request = TestExtensions.GetJsonRequest(customization, "POST", "/codito/v1/customization/", "application/pdf");
            //Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType);
            response.Content.Headers.ContentLength.Should().BeGreaterThan(0);
            response.ShouldBeProblemJson();
        }
        public async Task ProblemJson_Validation_400_Test()
        {
            //Arrange
            var player = new NewPlayerDto
            {
                FirstName   = "Test Player",
                Description = "He plays for Codit.",
                IsTopPlayer = false
            };
            var request = TestExtensions.GetJsonRequest(player, "POST", "/world-cup/v1/players");
            //Act
            var response = await _httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            response.Content.Headers.ContentLength.Should().BeGreaterThan(0);
            response.ShouldBeProblemJson();
        }
        public async Task ProblemJson_UnsupportedContentType_415_Test()
        {
            //Arrange
            var player = new NewPlayerDto
            {
                FirstName   = "Test Player",
                Description = "He plays for MUTD.",
                IsTopPlayer = false,
                TeamId      = 1
            };
            var request = TestExtensions.GetJsonRequest(player, "POST", "/world-cup/v1/players", "application/pdf");
            //Act
            var response = await _httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType);
            response.Content.Headers.ContentLength.Should().BeGreaterThan(0);
            response.ShouldBeProblemJson();
        }
        public async Task ProblemJson_InternalServerError_500_Test()
        {
            //Arrange
            var player = new NewPlayerDto
            {
                FirstName   = "Test Player",
                Description = "Evil",
                IsTopPlayer = false,
                TeamId      = 1
            };
            var request = TestExtensions.GetJsonRequest(player, "POST", "/world-cup/v1/players");
            //Act
            var response = await _httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
            response.Content.Headers.ContentLength.Should().BeGreaterThan(0);
            response.ShouldBeProblemJson();
        }
Beispiel #10
0
        public async Task UpdateCustomizationIncremental_NoContent_TestAsync()
        {
            //Arrange
            int id            = 1;
            var customization = new CustomizationDto
            {
                InventoryLevel = 100
            };

            var request  = new HttpRequestMessage(HttpMethod.Get, $"/codito/v1/customization/{id}");
            var response = await fixture._httpClient.SendAsync(request);

            var actualDto = JsonConvert.DeserializeObject <CustomizationDto>(await response.Content.ReadAsStringAsync());

            request = TestExtensions.GetJsonRequest(customization, "PATCH", $"/codito/v1/customization/{id}");

            //actualDto.Should().BeNull();

            // Act
            response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            request  = new HttpRequestMessage(HttpMethod.Get, $"/codito/v1/customization/{id}");
            response = await fixture._httpClient.SendAsync(request);

            var updatedDto = JsonConvert.DeserializeObject <CustomizationDto>(await response.Content.ReadAsStringAsync());

            updatedDto.Id.Should().Be(actualDto.Id);

            //these should stay the same
            updatedDto.Name.Should().Be(actualDto.Name);
            updatedDto.NumberSold.Should().Be(actualDto.NumberSold);
            updatedDto.CarId.Should().Be(actualDto.CarId);

            // this one is updated
            updatedDto.InventoryLevel.Should().Be(customization.InventoryLevel);
            updatedDto.InventoryLevel.Should().NotBe(actualDto.InventoryLevel);
        }