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); } } }
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); }
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); })); }
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); } }