Ejemplo n.º 1
0
        public async Task <BaseResponse <Patient> > Handle(CreatePatientCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <Patient> ()
            {
                ReponseName = nameof(CreatePatientCommand), Content = new List <Patient> ()
                {
                }
            };
            var entity    = _mapper.Map <Patient> (request);
            var newentity = await _patientRepository.AddAsync(entity);

            if (newentity == null)
            {
                response.Status  = ResponseType.Error;
                response.Message = $"{nameof(Patient)} could not be created.";
                response.Content = null;
            }
            else
            {
                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(Patient)} created successfully.";
                response.Content.Add(newentity);
            }
            return(response);
        }
Ejemplo n.º 2
0
        public void ShouldValidateWhenCommandIsValid()
        {
            var command = new CreatePatientCommand();
            command.Name = "Gian Mella";
            command.Phone = "(51) 98184-1977";
            command.DateOfBirth = new DateTime(1990, 26, 06);

            Assert.AreEqual(true, command.IsValid());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] CreatePatientCommand createPatientCommand)
        {
            var response = await _mediator.Send(createPatientCommand);

            if (response.Errors.Any())
            {
                return(BadRequest(new { Errors = response.Errors }));
            }

            return(Created("", null));
        }
        public async Task <IActionResult> Post([FromHeader] Guid userId, [FromBody] CreatePatientCommand command)
        {
            var patientId = await patientLogic.SavePatient(command);

            if (patientId == Guid.Empty)
            {
                return(BadRequest());
            }

            return(CreatedAtAction(nameof(GetPatient), new { id = patientId }, patientId));
        }
Ejemplo n.º 5
0
        public void ShouldRegisterCustomerWhenCommandIsValid()
        {
            var command = new CreatePatientCommand();

            command.Name        = "Gian Mella";
            command.Phone       = "(51) 98184-1977";
            command.DateOfBirth = new DateTime(1990, 26, 06);

            //Assert.AreNotEqual(null, result);
            //Assert.AreEqual(true, handler.Valid);
        }
        public async Task <ActionResult <BaseResponse <Patient> > > CreatePatient(CreatePatientCommand command)
        {
            try {
                var result = await _mediator.Send(command);

                return(Ok(result));
            } catch (ValidationException ex) {
                var err = new BaseResponse <Patient> ();
                err.Status  = ResponseType.Error;
                err.Message = ex.Message;
                err.Content = null;
                return(Ok(err));
            }
        }
Ejemplo n.º 7
0
        public void CreatePatientCommand_MapperThrowsException_PatientIsNotCreated()
        {
            var mapperMock = Substitute.For <IMapper>();
            var loggerMock = Substitute.For <ILogger <CreatePatientCommand> >();
            CreatePatientCommand testCommand = new CreatePatientCommand {
                Surname = "Steve"
            };

            mapperMock.Map <Patient>(
                Arg.Any <CreatePatientCommand>()).Returns(x => { throw new Exception(); });

            var sut = new CreatePatientCommand.Handler(_myPregnancyDbContext, mapperMock, loggerMock);

            Assert.ThrowsAsync <Exception>(async() => await sut.Handle(testCommand, CancellationToken.None));
            Assert.That(_myPregnancyDbContext.Patient.ToList(), Is.Empty);
        }
Ejemplo n.º 8
0
            public void CreatePatientCommandValidator_NullProperties_FailsValidation()
            {
                CreatePatientCommand patientCommand = new CreatePatientCommand();

                _validator.ShouldHaveValidationErrorFor(x => x.PreferredName, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.Forenames, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.Surname, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.Language, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.DateOfBirth, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.MobileTelephone, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.HomeTelephone, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.HealthCareNumber, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.KnownAllergies, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.AddressLine1, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.AddressLine2, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.City, patientCommand);
                _validator.ShouldHaveValidationErrorFor(x => x.Postcode, patientCommand);
            }
Ejemplo n.º 9
0
        public async Task CreatePatientCommand_ValidCreateCommand_SuccessfullyCreatesPatient()
        {
            var mapperMock = Substitute.For <IMapper>();
            var loggerMock = Substitute.For <ILogger <CreatePatientCommand> >();
            CreatePatientCommand testCommand = new CreatePatientCommand {
                Surname = "Steve"
            };

            mapperMock.Map <Patient>(Arg.Is <CreatePatientCommand>(x => x.Surname == testCommand.Surname))
            .Returns(new Patient {
                Surname = "test1"
            });

            var sut    = new CreatePatientCommand.Handler(_myPregnancyDbContext, mapperMock, loggerMock);
            var result = await sut.Handle(testCommand, CancellationToken.None);

            mapperMock.Received(1).Map <Patient>(Arg.Any <CreatePatientCommand>());
            Assert.That(result, Is.EqualTo(1));
        }
        public async Task <Guid> SavePatient(CreatePatientCommand command)
        {
            var patient = mapper.Map <Entities.Patient>(command);

            patient.Id        = Guid.NewGuid();
            patient.IsActive  = true;
            patient.Created   = DateTime.UtcNow;
            patient.CreatedBy = command.CreatedBy;
            patient.Updated   = DateTime.UtcNow;
            patient.UpdatedBy = command.CreatedBy;

            await context.Patient.AddAsync(patient);

            var rowChanged = await context.SaveChangesAsync();

            if (rowChanged == 0)
            {
                return(Guid.Empty);
            }

            return(patient.Id);
        }
Ejemplo n.º 11
0
        public async Task PatientsControllerCreate_ValidCreatePatientCommand_CommandSentSuccessfully()
        {
            int successfulCreationId = 1;
            var mediatorMock         = Substitute.For <IMediator>();
            var loggerMock           = Substitute.For <ILogger <PatientsController> >();

            mediatorMock.Send(Arg.Any <CreatePatientCommand>()).Returns(successfulCreationId);
            CreatePatientCommand testCommand = new CreatePatientCommand {
                Surname = "Steve"
            };
            var sut = new PatientsController(mediatorMock, loggerMock);

            var result = await sut.Create(testCommand);

            var okResult = result as OkObjectResult;

            Assert.IsNotNull(okResult);
            Assert.That(okResult.StatusCode, Is.EqualTo(200));
            Assert.That(okResult.Value, Is.EqualTo(successfulCreationId));
            await mediatorMock.Received(1).Send(Arg.Is <CreatePatientCommand>(x => x.Surname == testCommand.Surname));

            loggerMock.Received(1);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([FromBody] CreatePatientCommand command)
        {
            _logger.LogInformation($"Entering {nameof(Create)}");

            return(Ok(await _mediator.Send(command)));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <int> > Create([FromBody] CreatePatientCommand command)
        {
            var newId = await Mediator.Send(command);

            return(CreatedAtAction(nameof(Get), new { id = newId }, newId));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> InsertAsync(CreatePatientCommand command)
        {
            await _mediator.Send(command);

            return(Success());
        }
Ejemplo n.º 15
0
        public ICommandResult Post([FromBody] CreatePatientCommand command)
        {
            var result = (CommandResult)_handler.Handle(command);

            return(result);
        }
 public CreatePatientViewModel(IBus bus)
 {
     _bus     = bus;
     _command = new CreatePatientCommand(Guid.NewGuid());
 }
Ejemplo n.º 17
0
 public async Task <ActionResult <int> > Create(CreatePatientCommand command)
 {
     return(await Mediator.Send(command));
 }
Ejemplo n.º 18
0
        public async Task <ActionResult> CreatePatient([FromBody] CreatePatientCommand command)
        {
            var patient = await Mediator.Send(command);

            return(CreatedAtAction("GetPatient", new { id = patient.Id }, patient));
        }