Beispiel #1
0
        public async Task InsertEquipment_IsSuccess_or_IsFail(EquipmentInsertDto dto, bool isExpectiongSuccess, bool expectHandledException)
        {
            try
            {
                var equipment = await equipmentAppService.InsertEquipment(dto);

                if (isExpectiongSuccess)
                {
                    Assert.NotNull(equipment);
                }
                else
                {
                    Assert.Null(equipment);
                }
            }
            catch (Exception ex)
            {
                if (expectHandledException)
                {
                    Assert.IsType <BusinessException>(ex);
                }
                else
                {
                    Assert.True(false);
                }
            }
        }
Beispiel #2
0
        public async Task <EquipmentDetailDto> InsertEquipment(EquipmentInsertDto equipmentToInsert)
        {
            var response = await client.InsertEquipmentAsync(new CommonRequestMessage { Content = JsonConvert.SerializeObject(equipmentToInsert) });

            var result = JsonConvert.DeserializeObject <EquipmentDetailDto>(response.Content);

            return(result);
        }
Beispiel #3
0
 public async Task <IActionResult> AddEquipment([FromBody] EquipmentInsertDto Equipment)
 {
     return(await ActionHandle(async() =>
     {
         var createdEquipment = await equipmentAppService.InsertEquipment(Equipment);
         if (createdEquipment == null)
         {
             return BadRequest("Unable to insert Equipment.");
         }
         return Created($"api/Equipment/{createdEquipment.Id}", createdEquipment);
     }));
 }
Beispiel #4
0
 public static Equipment ToEquipment(this EquipmentInsertDto dto)
 {
     return(new Equipment()
     {
         Name = dto.Name,
         ClinicId = dto.ClinicId,
         Price = dto.Price,
         Quantity = dto.Quantity,
         SupplyDate = DateTime.UtcNow,
         UsageRate = dto.UsageRate
     });
 }
        public async Task <EquipmentDetailDto> InsertEquipment(EquipmentInsertDto equipmentToInsert)
        {
            if (!await clinicRepository.Any(equipmentToInsert.ClinicId))
            {
                throw new BusinessException($"There is no clinic with id : {equipmentToInsert.ClinicId}");
            }

            var equipment = equipmentToInsert.ToEquipment();

            equipmentRepository.Add(equipment);

            await equipmentRepository.SaveChangesAsync();

            return(equipment.ToEquipmentDetailDto());
        }
        public async Task InsertEquipment_DataDrivenTest(EquipmentInsertDto model, bool expectation)
        {
            var requestModel = new CommonRequestMessage {
                Content = JsonConvert.SerializeObject(model)
            };

            CommonResponseMessage response = await sut.InsertEquipment(requestModel, default(ServerCallContext));

            var equipment = JsonConvert.DeserializeObject <EquipmentDetailDto>(response.Content);

            if (expectation)
            {
                Assert.True(response.Status);
                Assert.NotNull(equipment);
                Assert.Equal(equipment.Name, model.Name);
            }
            else
            {
                Assert.Null(equipment);
            }
        }