public static CreateRestaurantRequest FromDTO(this CreateRestaurantRequestDTO requestDTO)
 {
     return(new CreateRestaurantRequest
     {
         Name = requestDTO.Name,
         Address = requestDTO.Address
     });
 }
        public async Task TestPostRestaurantWithEmptyValues(string name, string address)
        {
            var createRestaurantRequest = new CreateRestaurantRequestDTO
            {
                Name    = name,
                Address = address,
            };
            var creationResponse = await client.PostAsJsonAsync(Url, createRestaurantRequest);

            Assert.Equal(HttpStatusCode.BadRequest, creationResponse.StatusCode);
        }
        public async Task TestPostRestaurantThatAlreadyExists(string name, string address)
        {
            var createRestaurantRequest = new CreateRestaurantRequestDTO
            {
                Name    = name,
                Address = address,
            };
            await client.PostAsJsonAsync(Url, createRestaurantRequest);

            // Posting twice intentionally
            var creationResponse = await client.PostAsJsonAsync(Url, createRestaurantRequest);

            Assert.Equal(HttpStatusCode.BadRequest, creationResponse.StatusCode);
        }
        public async Task TestPostRestaurant(string name, string address)
        {
            var createRestaurantRequest = new CreateRestaurantRequestDTO
            {
                Name    = name,
                Address = address,
            };
            var creationResponse = await client.PostAsJsonAsync(Url, createRestaurantRequest);

            Assert.Equal(HttpStatusCode.Created, creationResponse.StatusCode);
            Assert.NotNull(creationResponse.Headers.Location);

            var newlyCreatedRestaurantResponse = await client.GetAsync(creationResponse.Headers.Location);

            Assert.Equal(HttpStatusCode.OK, newlyCreatedRestaurantResponse.StatusCode);
            Assert.Equal("application/json; charset=utf-8", newlyCreatedRestaurantResponse.Content.Headers.ContentType.ToString());

            var newlyCreatedRestaurant = await newlyCreatedRestaurantResponse.Content.ReadAsAsync <RestaurantDTO>();

            Assert.NotNull(newlyCreatedRestaurant);
            Assert.Equal(name, newlyCreatedRestaurant.Name);
            Assert.Equal(address, newlyCreatedRestaurant.Address);
        }
示例#5
0
        public async Task <ActionResult> Post([FromBody] CreateRestaurantRequestDTO dto)
        {
            var createdRestaurant = await service.CreateRestaurant(dto.FromDTO());

            return(CreatedAtRoute("GetRestaurant", new { id = createdRestaurant.Id }, createdRestaurant.ToDTO()));
        }