Esempio n. 1
0
        public void CreateExaminationQuerySuccessReturnsExamination()
        {
            // Arrange
            var examination                = new MedicalExaminer.Models.Examination();
            var connectionSettings         = new Mock <IExaminationConnectionSettings>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var myUser = new Mock <MeUser>();
            CreateExaminationQuery query = new CreateExaminationQuery(examination, myUser.Object);
            var dbAccess        = new Mock <IDatabaseAccess>();
            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.CreateItemAsync(
                               connectionSettings.Object,
                               examination,
                               false)).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new CreateExaminationService(dbAccess.Object, connectionSettings.Object, locationService.Object, _urgencySettingsMock.Object);

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

            // Assert
            dbAccess.Verify(db => db.CreateItemAsync(connectionSettings.Object, examination, false), Times.Once);
            Assert.NotNull(result.Result);
            Assert.Equal(myUser.Object.UserId, result.Result.LastModifiedBy);
        }
Esempio n. 2
0
        public void CreateExaminationQueryIsNullThrowsException()
        {
            // Arrange
            var connectionSettings             = new Mock <IExaminationConnectionSettings>();
            var locationConnectionSettings     = new Mock <ILocationConnectionSettings>();
            const CreateExaminationQuery query = null;
            var dbAccess        = new Mock <IDatabaseAccess>();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);
            var sut             = new CreateExaminationService(dbAccess.Object, connectionSettings.Object, locationService.Object, _urgencySettingsMock.Object);

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

            // Assert
            act.Should().Throw <ArgumentNullException>();
        }
Esempio n. 3
0
        public void CreateExaminationQueryWithNoUrgencyIndicatorsSuccessReturnsExaminationWithIsUrgentFalse()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination()
            {
                ChildPriority    = false,
                CoronerPriority  = false,
                CulturalPriority = false,
                FaithPriority    = false,
                OtherPriority    = false,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };

            var userId = "userId";
            var user   = new MeUser()
            {
                UserId = userId
            };
            var connectionSettings       = new Mock <IExaminationConnectionSettings>();
            CreateExaminationQuery query = new CreateExaminationQuery(examination, user);
            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.CreateItemAsync(
                               connectionSettings.Object,
                               examination,
                               false)).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new CreateExaminationService(dbAccess.Object, connectionSettings.Object, locationService.Object, _urgencySettingsMock.Object);

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

            // Assert
            result.Result.Should().NotBeNull();
            result.Result.IsUrgent().Should().BeFalse();
            result.Result.LastModifiedBy.Should().Be(user.UserId);
        }