public void PatientDetailsUpdateQuerySuccessReturnsExaminationId()
        {
            // Arrange
            var examination        = new MedicalExaminer.Models.Examination();
            var patientDetails     = new Mock <MedicalExaminer.Models.PatientDetails>();
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var user = new Mock <MeUser>();

            var query    = new PatientDetailsUpdateQuery("a", patientDetails.Object, user.Object, _locationPath);
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            dbAccess.Setup(db => db.GetItemAsync(connectionSettings.Object,
                                                 It.IsAny <Expression <Func <MedicalExaminer.Models.Examination, bool> > >()))
            .Returns(Task.FromResult(examination)).Verifiable();
            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new PatientDetailsUpdateService(dbAccess.Object, connectionSettings.Object, Mapper, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            dbAccess.Verify(
                db => db.UpdateItemAsync(
                    connectionSettings.Object,
                    It.IsAny <MedicalExaminer.Models.Examination>()),
                Times.Once);
            Assert.NotNull(result.Result);
        }
        public void PatientDetailsUpdateOnExaminationWithAllUrgencyIndicatorsSuccessReturnsExaminationWithIsUrgentTrue()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination()
            {
                ChildPriority    = true,
                CoronerPriority  = true,
                CulturalPriority = true,
                FaithPriority    = true,
                OtherPriority    = true,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };
            var patientDetails = new MedicalExaminer.Models.PatientDetails()
            {
                ChildPriority    = true,
                CoronerPriority  = true,
                CulturalPriority = true,
                FaithPriority    = true,
                OtherPriority    = true,
            };

            const string userId = "userId";
            var          user   = new MeUser()
            {
                UserId = userId,
            };

            var connectionSettings = new Mock <IExaminationConnectionSettings>();

            var query    = new PatientDetailsUpdateQuery("a", patientDetails, user, _locationPath);
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            dbAccess.Setup(db => db.GetItemAsync(connectionSettings.Object,
                                                 It.IsAny <Expression <Func <MedicalExaminer.Models.Examination, bool> > >()))
            .Returns(Task.FromResult(examination)).Verifiable();
            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new PatientDetailsUpdateService(dbAccess.Object, connectionSettings.Object, Mapper, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            result.Result.IsUrgent().Should().BeTrue();
            result.Result.LastModifiedBy.Should().Be(userId);
        }
        public void PatientDetailsUpdateQueryIsNullThrowsException()
        {
            // Arrange
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            const PatientDetailsUpdateQuery query = null;

            var mapper   = new Mock <IMapper>();
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            var sut = new PatientDetailsUpdateService(dbAccess.Object, connectionSettings.Object, mapper.Object, locationService.Object, _urgencySettingsMock.Object);

            // Act
            Action act = () => sut.Handle(query).GetAwaiter().GetResult();

            // Assert
            act.Should().Throw <ArgumentNullException>();
        }