Exemplo n.º 1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] CoordinateList value)
        {
            if (!ModelState.IsValid || value == null)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var existingList = await _service.GetList(id).ConfigureAwait(false);

            if (existingList == null)
            {
                return(new NotFoundResult());
            }

            var validator        = new CoordinateListValidator();
            var validationResult = validator.Validate(value);

            if (!validationResult.IsValid)
            {
                return(new BadRequestObjectResult(MapValidationResultToModelState(validationResult)));
            }

            var result = await _service.SaveList(value.ToCoordinateListEntity(id)).ConfigureAwait(false);

            return(new ObjectResult(result.ToCoordinateListDto()));
        }
Exemplo n.º 2
0
        public void Validate_ShouldNotAllowEmptyListNames()
        {
            _validator = new CoordinateListValidator();
            //arrange
            var coordinates = new List <Coordinate>();

            coordinates.Add(new Coordinate(0, 0));
            var cooList = new CoordinateList(0, null, coordinates);

            //act
            var result = _validator.Validate(cooList);

            //assert
            Assert.False(result.IsValid);
            Assert.Equal(result.Errors.Count, 1);
            Assert.Equal(result.Errors.First().PropertyName, nameof(CoordinateList.Name));
        }
Exemplo n.º 3
0
        public void Validate_ShouldNotAllowMoreThanMaxAvailableCoordinations()
        {
            _validator = new CoordinateListValidator();
            //arrange
            var coordinates = new List <Coordinate>();

            for (var i = CoordinateValidator.smallestCoordinate; i <= CoordinateListValidator.MaxCoordinateCount / 2; i++)
            {
                coordinates.Add(new Coordinate(0, i));
            }
            var cooList = new CoordinateList(0, "test", coordinates);

            //act
            var result = _validator.Validate(cooList);

            //assert
            Assert.False(result.IsValid);
            Assert.Equal(result.Errors.Count, 1);
            Assert.Equal(result.Errors.First().PropertyName, nameof(CoordinateList.Coordinates));
        }