public UnitOfMeasureRepositoryFixture()
        {
            MockUnitOfMeasureService = new Mock <IUnitOfMeasureService>();

            UnitOfMeasures = new List <UnitOfMeasure> {
                new UnitOfMeasure {
                    Id = 1, Code = "kg", Description = "kg units"
                },
                new UnitOfMeasure {
                    Id = 2, Code = "g", Description = "g units"
                },
                new UnitOfMeasure {
                    Id = 3, Code = "ml", Description = "ml units"
                }
            };

            CreateUnitOfMeasureDto = new CreateUnitOfMeasureDto {
                Code = "l", Description = "l units"
            };

            CreatedNewUnitOfMeasure = new UnitOfMeasure {
                Id = 4, Code = CreateUnitOfMeasureDto.Code, Description = CreateUnitOfMeasureDto.Description
            };

            EditUnitOfMeasureDto = new EditUnitOfMeasureDto {
                Code = "ml", Description = "ml units to add"
            };
        }
 public CreateUnitOfMeasureDtoValidatorFixture()
 {
     Validator = new CreateUnitOfMeasureDtoValidator();
     Model     = new CreateUnitOfMeasureDto
     {
         Code        = "kg",
         Description = "Items in kg unit"
     };
 }
        public async Task <GetUnitOfMeasureDto> CreateUnitOfMeasureAsync(CreateUnitOfMeasureDto unitOfMeasureDto)
        {
            await CheckUnitOfMeasureAsync(0, unitOfMeasureDto.Code);

            var unitOfMeasure = _mapper.Map <UnitOfMeasure>(unitOfMeasureDto);

            unitOfMeasure = await _unitOfMeasure.AddUnitOfMeasureAsync(unitOfMeasure);

            return(_mapper.Map <GetUnitOfMeasureDto>(unitOfMeasure));
        }
Exemple #4
0
        public UnitOfMeasureControllerFixture()
        {
            ApiVersion = new ApiVersion(1, 0);

            MockUnitOfMeasureRepository = new Mock <IUnitOfMeasureRepository>();

            UnitOfMeasures = new List <GetUnitOfMeasureDto>
            {
                new GetUnitOfMeasureDto {
                    Id = 1, Code = "kg", Description = "Kilogram"
                },
                new GetUnitOfMeasureDto {
                    Id = 2, Code = "g", Description = "Gram"
                }
            };

            ValidCreateUnitOfMeasureDto = new CreateUnitOfMeasureDto
            {
                Code        = "l",
                Description = "Liter"
            };

            CreateUnitOfMeasureDtoResult = new GetUnitOfMeasureDto
            {
                Id          = 3,
                Code        = "l",
                Description = "Liter"
            };

            ValidEditUnitOfMeasureDto = new EditUnitOfMeasureDto
            {
                Code        = "g",
                Description = "Gram test"
            };

            EditUnitOfMeasureDtoResult = new GetUnitOfMeasureDto
            {
                Id          = 2,
                Code        = "g",
                Description = "Gram test"
            };
        }
        public async Task <IActionResult> CreateUnitOfMeasure(CreateUnitOfMeasureDto unitOfMeasureDto, ApiVersion version)
        {
            var result = await _repository.CreateUnitOfMeasureAsync(unitOfMeasureDto);

            return(CreatedAtRoute(new { id = result.Id, version = $"{version}" }, result));
        }