コード例 #1
0
        //[Fact]
        //public async Task Should_CloseOrder_Method_Success_Given_Correct_Ticket()
        //{
        //    //Given
        //    var client = GetClient();
        //    var parkinglotDto = GenerateOneParkinglot();
        //    await AddOneParkinglotInTestDatabase(parkinglotDto);
        //    UpdateModel updateModel = new UpdateModel("SuperPark_1", 30);
        //    var expectedCapacity = updateModel.Capacity;

        //    //When
        //    var httpContent = JsonConvert.SerializeObject(updateModel);
        //    StringContent content = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
        //    await client.PatchAsync("/ParkingLotApi/Orders", content);
        //    var getResponse = await client.GetAsync("/ParkingLotApi/Orders? name = SuperPark_1");
        //    var body = await getResponse.Content.ReadAsStringAsync();
        //    var returnedDto = JsonConvert.DeserializeObject<List<ParkinglotDTO>>(body)[0];

        //    //Then
        //    Assert.Equal(expectedStatus, actualStatus);
        //}

        private async Task <HttpResponseMessage> AddOneParkinglotInTestDatabase(ParkinglotDTO parkinglotDto)
        {
            var           client      = GetClient();
            var           httpContent = JsonConvert.SerializeObject(parkinglotDto);
            StringContent content     = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);

            return(await client.PostAsync("/ParkingLotApi/ParkingLots", content));
        }
コード例 #2
0
        public async Task Should_POST_Return_BadRequest_Given_Illegal_Input(string name, int capacity, string location)
        {
            //Given
            var           client        = GetClient();
            ParkinglotDTO parkinglotDto = new ParkinglotDTO()
            {
                Name     = name,
                Capacity = capacity,
                Location = location
            };
            var           httpContent = JsonConvert.SerializeObject(parkinglotDto);
            StringContent content     = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);

            //When
            var postResponse = await client.PostAsync("/ParkingLotApi/ParkingLots", content);

            //Then
            Assert.Equal(HttpStatusCode.BadRequest, postResponse.StatusCode);
        }
        public async Task <ActionResult <ParkinglotDTO> > CreateParkingLot(ParkinglotDTO parkinglotDto)
        {
            if (parkinglotDto.Name == null || parkinglotDto.Capacity < 0 || parkinglotDto.Location == null ||
                parkinglotDto.Name == string.Empty || parkinglotDto.Location == string.Empty)
            {
                return(BadRequest(new
                {
                    message = $"Should input all information and input positive capacity."
                }));
            }

            var id = await parkingLotService.AddParkingLotAsnyc(parkinglotDto);

            if (id == -1)
            {
                return(Conflict(new
                {
                    message = $"An existing parkinglot " +
                              $"with the name '{parkinglotDto.Name}' was already found."
                }));
            }

            return(CreatedAtAction(nameof(GetById), new { id = id }, parkinglotDto));
        }
 public ParkinglotEntity(ParkinglotDTO parkinglotDto)
 {
     Name     = parkinglotDto.Name;
     Capacity = parkinglotDto.Capacity;
     Location = parkinglotDto.Location;
 }