public async Task Handle_Fetch_Should_GetPatients_Return_Empty()
        {
            // Arrange
            var hospitalId = Guid.NewGuid();
            var query      = new GetPatientsByHospitalId.Query(hospitalId);

            var mockAppDbRepository = new Mock <IAppDbRepository>();

            mockAppDbRepository
            .Setup(x => x.GetPatientsByHospitalIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync((IEnumerable <Patient>)null);

            var handler = new GetPatientsByHospitalId.Handler(mockAppDbRepository.Object);
            // Act
            var result = await handler.Handle(query, new CancellationToken());

            // Assert
            Assert.Null(result);
        }
        public async Task Handle_Fetch_Should_GetPatients_Return_List()
        {
            // Arrange
            var hospitalId = Guid.NewGuid();
            var query      = new GetPatientsByHospitalId.Query(hospitalId);
            var patients   = new List <Patient>
            {
                new Patient
                {
                    Address    = new Address(),
                    HospitalId = hospitalId
                },
                new Patient
                {
                    Address    = new Address(),
                    HospitalId = hospitalId
                },
                new Patient
                {
                    Address    = new Address(),
                    HospitalId = hospitalId
                }
            };
            var mockAppDbRepository = new Mock <IAppDbRepository>();

            mockAppDbRepository
            .Setup(x => x.GetPatientsByHospitalIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(patients);

            var handler = new GetPatientsByHospitalId.Handler(mockAppDbRepository.Object);
            // Act
            var result = await handler.Handle(query, new CancellationToken());

            // Assert
            Assert.Equal(3, result.Count());
            Assert.All(result, item => Assert.Equal(hospitalId, item.HospitalId.Value));
        }
Exemple #3
0
        public async Task <IEnumerable <Patient> > GetPatientsByHospitalIdAsync(Guid hospitalId)
        {
            var query = new GetPatientsByHospitalId.Query(hospitalId);

            return(await Mediator.Send(query));
        }