Ejemplo n.º 1
0
        public async Task UpdatePlayerIncrementalJsonPatch_Ok_TestAsync()
        {
            //Arrange
            int playerId = 1;
            JsonPatchDocument <PlayerDto> player = new JsonPatchDocument <PlayerDto>();

            player.Replace(p => p.Description, "He's still playing for Chelsea.");
            player.Replace(p => p.IsTopPlayer, false);

            var request  = new HttpRequestMessage(new HttpMethod("GET"), $"/world-cup/v1/players/{playerId}");
            var response = await _httpClient.SendAsync(request);

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

            request = TestExtensions.GetJsonRequest(player, "PATCH", $"/world-cup/v1/players/{playerId}/update", ContentTypeNames.Application.JsonPatch);

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

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var updatedDto = JsonConvert.DeserializeObject <PlayerDto>(await response.Content.ReadAsStringAsync());

            updatedDto.FirstName.Should().Be(actualDto.FirstName);
            updatedDto.Description.Should().NotBe(actualDto.Description);
            updatedDto.IsTopPlayer.Should().Be(!actualDto.IsTopPlayer);
            updatedDto.TeamId.Should().Be(actualDto.TeamId);
        }
Ejemplo n.º 2
0
        public async Task SellCustomization_SoldOut409_TestAsync()
        {
            //Arrange
            //(Create new customization. InventoryLevel is not set, so will be zero.)
            var newCustomization = new NewCustomizationDto
            {
                Name  = "My Soldout Customization",
                CarId = 1
            };

            var request  = TestExtensions.GetJsonRequest(newCustomization, "POST", "/codito/v1/customization/");
            var response = await fixture._httpClient.SendAsync(request);

            response.StatusCode.Should().Be(HttpStatusCode.Created);
            //(Get Id of this new customization)
            var newDto = JsonConvert.DeserializeObject <CustomizationDto>(await response.Content.ReadAsStringAsync());
            int id     = newDto.Id;

            //(Try to sell this "sold out" customization)
            request = new HttpRequestMessage(HttpMethod.Post, $"/codito/v1/customization/{id}/sale");

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

            //Assert
            response.StatusCode.Should().Be(409);
        }
Ejemplo n.º 3
0
        public async Task UpdatePlayerIncremental_NoContent_TestAsync()
        {
            //Arrange
            int playerId = 1;
            var player   = new PlayerDto
            {
                Description = "He's still playing for Chelsea."
            };

            var request  = new HttpRequestMessage(new HttpMethod("GET"), $"/world-cup/v1/players/{playerId}");
            var response = await _httpClient.SendAsync(request);

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

            request = TestExtensions.GetJsonRequest(player, "PATCH", $"/world-cup/v1/players/{playerId}");

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

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            request  = new HttpRequestMessage(new HttpMethod("GET"), $"/world-cup/v1/players/{playerId}");
            response = await _httpClient.SendAsync(request);

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

            updatedDto.FirstName.Should().Be(actualDto.FirstName);
            updatedDto.Description.Should().NotBe(actualDto.Description);
            updatedDto.IsTopPlayer.Should().Be(actualDto.IsTopPlayer);
            updatedDto.TeamId.Should().Be(actualDto.TeamId);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 13
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);
        }