public async Task <IActionResult> Create(NewCustomizationDto newCustomization)
        {
            if (newCustomization.CarId == -9999)
            {
                throw new ArgumentException("this is evil code");
            }

            var car = await _coditoRepository.GetCarAsync(newCustomization.CarId, false);

            if (car == null)
            {
                return(BadRequest(new ProblemDetailsError(StatusCodes.Status400BadRequest, $"There is no car with id {newCustomization.CarId}.")));
            }

            var newCustomizationObject = new Customization
            {
                Name           = newCustomization.Name,
                CarId          = newCustomization.CarId,
                Url            = newCustomization.Url,
                InventoryLevel = newCustomization.InventoryLevel,
            };

            await _coditoRepository.CreateCustomizationAsync(newCustomizationObject);

            var result = Mapper.Map <CustomizationDto>(newCustomizationObject);

            return(CreatedAtRoute(Constants.RouteNames.v1.GetCustomization, new { id = result.Id }, result));
        }
Example #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);
        }
Example #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();
        }
        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();
        }