Ejemplo n.º 1
0
 public static DomainModels.Medication ToDomain(
     this Dto.Medication medication)
 {
     return(new DomainModels.Medication
     {
         ExternalId = medication.Id,
         Name = medication.Name,
         Quantity = medication.Quantity,
         CreatedAt = medication.CreatedAt,
     });
 }
        public async Task CreateMedicationAsync_Success(Dto.Medication medication)
        {
            // Act
            var result = await this.medicationService.CreateMedicationAsync(medication);

            // Assert
            Assert.True(result);

            this.medicationRepositoryMock.Verify(
                s => s.CreateMedicationAsync(
                    It.Is <Medication>(
                        m => m.ExternalId == medication.Id &&
                        m.Name == medication.Name &&
                        m.Quantity == medication.Quantity)),
                Times.Once);
        }
Ejemplo n.º 3
0
        public async Task <bool> CreateMedicationAsync(Dto.Medication medication)
        {
            var result = await this.medicationRepository.GetAllMedicationsAsync(medicationId : medication.Id);

            if (result.Any())
            {
                return(false);
            }

            var medicationDomain = medication.ToDomain();

            medicationDomain.Id = Guid.NewGuid();

            await this.medicationRepository.CreateMedicationAsync(medicationDomain);

            return(true);
        }
        public async Task CreateMedicationAsync_AlreadyExists(Dto.Medication medication, Medication medicationDomain)
        {
            // Arrange
            this.medicationRepositoryMock
            .Setup(s => s.GetAllMedicationsAsync(medication.Id, null))
            .ReturnsAsync(new[] { medicationDomain });

            // Act
            var result = await this.medicationService.CreateMedicationAsync(medication);

            // Assert
            Assert.False(result);

            this.medicationRepositoryMock.Verify(
                s => s.CreateMedicationAsync(
                    It.IsAny <Medication>()),
                Times.Never);
        }