public void GetAllOutputTables_Test()
        {
            // Arrange
            int tablesCount = tablesDbSet.Count();

            // Act
            IEnumerable <OutputTable> tables = outRepo.GetAll();

            // Assert
            Assert.AreEqual(tablesCount, tables.Count());
            Assert.AreEqual(tablesCount, tablesDbSet.Count());

            Assert.AreEqual(tables.First().OutputTableId, tablesDbSet.First().OutputTableId);
            Assert.AreEqual(tables.Last().FileName, tablesDbSet.Last().FileName);
        }
        public void Execute_GivenUpdateQuestionAnswerCommand_QuestionAnswerShouldBeUpdatedInContext()
        {
            var          questionAnswerId   = Guid.NewGuid();
            const string furtherInformation = "further";

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <QuestionAnswer> {
                new QuestionAnswer()
                {
                    QuestionAnswerId = questionAnswerId
                }
            };

            var command = new UpdateQuestionAnswerCommand()
            {
                QuestionAnswerId   = questionAnswerId,
                FurtherInformation = furtherInformation
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <QuestionAnswer>()).Returns(set);

            _handler.Execute(command);

            var questionAnswer = set.First(x => x.QuestionAnswerId == questionAnswerId);

            questionAnswer.FurtherInformation.Should().Be(furtherInformation);
        }
        public void Execute_GivenUpdateAssessmentStatusCommandReadyToComplete_AssessmentShouldBeUpdatedInContext()
        {
            var       assessmentId = Guid.NewGuid();
            const int statusId     = (int)AssessmentStatusEnum.ReadyToComplete;

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Assessment> {
                new Assessment()
                {
                    AssessmentId = assessmentId
                }
            };

            var command = new UpdateAssessmentStatusCommand()
            {
                AssessmentId = assessmentId,
                StatusId     = statusId
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Assessment>()).Returns(set);

            _handler.Execute(command);

            set.First(x => x.AssessmentId == assessmentId).StatusId.Should().Be(statusId);
        }
Exemple #4
0
        public void Execute_GivenUpdateAssessmentCommand_AssessmentShouldBeUpdatedInContext()
        {
            var assessmentId   = Guid.NewGuid();
            var assessmentDate = new DateTime(2015, 1, 1);

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Assessment> {
                new Assessment()
                {
                    AssessmentId = assessmentId
                }
            };

            var command = new UpdateAssessmentCompleteCommand()
            {
                AssessmentId        = assessmentId,
                DateAssessmentEnded = assessmentDate
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Assessment>()).Returns(set);

            _handler.Execute(command);

            var assessment = set.First(x => x.AssessmentId == assessmentId);

            assessment.DateAssessmentEnded.Should().Be(assessmentDate);
        }
Exemple #5
0
        public void Execute_GivenAddUpdatePatientCommandAdd_PatientShouldBeAddedToContext()
        {
            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Patient>();

            var patientId = Guid.NewGuid();

            var patientCommand = new AddUpdatePatientCommand()
            {
                PatientId        = patientId,
                ClinicalSystemId = "1",
                DateOfBirth      = new DateTime(1965, 01, 01),
                FirstName        = "David",
                LastName         = "Miller",
                GenderId         = 1,
                NhsNumber        = 123
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Patient>()).Returns(set);

            _handler.Execute(patientCommand);

            set.Count(x => x.PatientId == patientId).Should().Be(1);

            var patient = set.First(x => x.PatientId == patientId);

            patient.PatientId.Should().Be(patientId);
            patient.ClinicalSystemId.Should().Be("1");
            patient.DateOfBirth.ShouldBeEquivalentTo(new DateTime(1965, 01, 01));
            patient.FirstName.Should().Be("David");
            patient.LastName.Should().Be("Miller");
            patient.GenderId.Should().Be(1);
            patient.NhsNumber.Should().Be(123);
        }
        public void Execute_GivenUpdateAssessmentQuestionsCommand_AssessmentShouldBeUpdatedInContext()
        {
            var assessmentId       = Guid.NewGuid();
            var nextQuestion       = Guid.NewGuid();
            var previousQuestionId = Guid.NewGuid();
            var resetQuestionId    = Guid.NewGuid();

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Assessment> {
                new Assessment()
                {
                    AssessmentId = assessmentId
                }
            };

            var command = new UpdateAssessmentQuestionsCommand()
            {
                AssessmentId            = assessmentId,
                NextQuestionId          = nextQuestion,
                PreviousQuestionId      = previousQuestionId,
                ResetWorkflowQuestionId = resetQuestionId
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Assessment>()).Returns(set);

            _handler.Execute(command);

            var assessment = set.First(x => x.AssessmentId == assessmentId);

            assessment.CurrentWorkflowQuestionId.Should().Be(nextQuestion);
            assessment.PreviousWorkflowQuestionId.Should().Be(previousQuestionId);
            assessment.ResetWorkflowQuestionId.Should().Be(resetQuestionId);
        }
Exemple #7
0
        public void Execute_GivenUpdateAssessmentCommand_AssessmentShouldBeUpdatedInContext()
        {
            var          assessmentId   = Guid.NewGuid();
            var          assessmentDate = new DateTime(2015, 1, 1);
            const string decision       = "decision";
            var          roleid         = (int)RoleIdEnum.DecisionMaker;

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Assessment> {
                new Assessment()
                {
                    AssessmentId = assessmentId, RoleId = (int)RoleIdEnum.Assessor, DecisionMaker = "decisionmakername"
                }
            };

            var command = new UpdateAssessmentCommand()
            {
                AssessmentId           = assessmentId,
                DateAssessmentStarted  = assessmentDate,
                Stage1DecisionToBeMade = decision,
                RoleId = roleid
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Assessment>()).Returns(set);

            _handler.Execute(command);

            var assessment = set.First(x => x.AssessmentId == assessmentId);

            assessment.DateAssessmentStarted.Should().Be(assessmentDate);
            assessment.Stage1DecisionToBeMade.Should().Be(decision);
            assessment.RoleId.Should().Be(roleid);
            assessment.DecisionMaker.Should().BeNull();
        }
        public void Execute_GivenUpdateAssessmentReadOnlyCommand_AssessmentShouldBeUpdatedInContext()
        {
            var        assessmentId = Guid.NewGuid();
            const bool readOnly     = true;

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Assessment> {
                new Assessment()
                {
                    AssessmentId = assessmentId
                }
            };

            var command = new UpdateAssessmentReadOnlyCommand()
            {
                AssessmentId = assessmentId,
                ReadOnly     = readOnly
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Assessment>()).Returns(set);

            _handler.Execute(command);

            set.First(x => x.AssessmentId == assessmentId).ReadOnly.Should().Be(readOnly);
        }
        public void GetAllParameters()
        {
            // Arrange
            int ElementsCountBeforeAct = parametersDbSet.Count();

            // Act
            IEnumerable <Parameter> allParameters = repository.GetAll();

            // Assert
            Assert.AreEqual(ElementsCountBeforeAct, allParameters.Count());
            Assert.AreEqual(
                parametersDbSet.First().ParameterName,
                allParameters.ToList()[0].ParameterName
                );
            Assert.AreEqual(
                parametersDbSet.ToList()[1].ParameterName,
                allParameters.ToList()[1].ParameterName
                );
        }
        public void GetAllQueryParameters_Test()
        {
            // Arrange
            int queryParametersCountBeforeAct = queryParametersDbSet.Count();

            // Act
            IEnumerable <SqlQueryParameter> queryParameters = queryParamRepo.GetAll();

            // Assert
            Assert.AreEqual(
                queryParametersCountBeforeAct,
                queryParameters.Count()
                );
            Assert.AreEqual(
                queryParametersCountBeforeAct,
                queryParametersDbSet.Count()
                );
            Assert.AreEqual(
                queryParametersDbSet.First().SqlQueryParameterId,
                queryParameters.First().SqlQueryParameterId
                );
        }
        public void Execute_GivenAddUpdateDisclaimerCommandUpdate_DisclaimerShouldBeUpdatedInContext()
        {
            var disclaimerId = Guid.NewGuid();

            var command = new AddUpdateDisclaimerCommand()
            {
                DisclaimerId = disclaimerId,
                IsAgreed = true
            };

            var fakeContext = A.Fake<DbContext>();
            var set = new TestDbSet<Disclaimer>() { new Disclaimer(){ DisclaimerId = disclaimerId} };

            A.CallTo(() => fakeContext.Set<Disclaimer>()).Returns(set);
            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);

            _handler.Execute(command);

            set.Count(x => x.DisclaimerId == disclaimerId).Should().Be(1);

            var disclaimer = set.First(x => x.DisclaimerId == disclaimerId);
            disclaimer.IsAgreed.Should().BeTrue();
        }
        public void Execute_GivenAddUpdateDisclaimerCommandAdd_DisclaimerShouldBeAddedToContext()
        {
            var disclaimerId = Guid.NewGuid();

            var command = new AddUpdateDisclaimerCommand()
            {
                DisclaimerId = disclaimerId,
                IsAgreed = true
            };

            var fakeContext = A.Fake<DbContext>();
            var set = new TestDbSet<Disclaimer>();

            A.CallTo(() => _userPrincipalProvider.CurrentUserName).Returns("user");
            A.CallTo(() => fakeContext.Set<Disclaimer>()).Returns(set);
            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);

            _handler.Execute(command);

            var disclaimer = set.First(x => x.DisclaimerId == disclaimerId);
            disclaimer.AssessorDomainName.Should().Be("user");
            disclaimer.IsAgreed.Should().BeTrue();
        }
Exemple #13
0
        public void Execute_GivenUpdatePatientCommandUpdate_PatientShouldBeUpdatedInContext()
        {
            var patientId = Guid.NewGuid();

            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Patient> {
                new Patient()
                {
                    PatientId = patientId
                }
            };

            var command = new AddUpdatePatientCommand()
            {
                PatientId        = patientId,
                ClinicalSystemId = "clinicalsystemid",
                NhsNumber        = 123456789,
                FirstName        = "firstname",
                LastName         = "lastname",
                DateOfBirth      = new DateTime(2015, 1, 1),
                GenderId         = 1
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Patient>()).Returns(set);

            _handler.Execute(command);

            var patient = set.First(x => x.PatientId == patientId);

            patient.ClinicalSystemId.Should().Be("clinicalsystemid");
            patient.NhsNumber.Should().Be(123456789);
            patient.FirstName.Should().Be("firstname");
            patient.LastName.Should().Be("lastname");
            patient.DateOfBirth.Should().Be(new DateTime(2015, 1, 1));
            patient.GenderId.Should().Be(1);
        }
Exemple #14
0
        public void GetAllQueries()
        {
            // Act
            IEnumerable <SqlQuery> queries = queryRepo.GetAll();

            // Assert
            Assert.AreEqual(queriesDbSet.Count(), queries.Count());
            Assert.AreEqual(
                queriesDbSet.First(),
                queries.First()
                );
            Assert.AreEqual(
                queriesDbSet.Last(),
                queries.Last()
                );
            Assert.AreEqual(
                queriesDbSet.First().SqlQueryName,
                queries.First().SqlQueryName
                );
        }
        public void GetSqlQueryIdByParameterId_Test()
        {
            // Arrange
            TestDbSet <Parameter> parameters = new TestDbSet <Parameter>()
            {
                new Parameter()
                {
                    ParameterId          = 0,
                    ParameterName        = "@Name",
                    ParameterRuName      = "RuName",
                    ParameterType        = "text",
                    ParameterCreatedDate = DateTime.Today
                },
                new Parameter()
                {
                    ParameterId          = 1,
                    ParameterName        = "@Age",
                    ParameterRuName      = "RuAge",
                    ParameterType        = "number",
                    ParameterCreatedDate = DateTime.Today.AddDays(-1)
                }
            };
            TestDbSet <SqlQuery> queries = new TestDbSet <SqlQuery>()
            {
                new SqlQuery()
                {
                    SqlQueryId          = 0,
                    SqlQueryName        = "SelectAllFromTable",
                    SqlQueryContent     = "Select * from Table",
                    SqlQueryCreatedDate = DateTime.Now
                },
                new SqlQuery()
                {
                    SqlQueryId          = 1,
                    SqlQueryName        = "DropTable",
                    SqlQueryContent     = "Drop table Table",
                    SqlQueryCreatedDate = DateTime.Today
                }
            };
            TestDbSet <SqlQueryParameter> queryParams = new TestDbSet <SqlQueryParameter>()
            {
                new SqlQueryParameter()
                {
                    SqlQueryParameterId = 0,
                    ParameterId         = 0,
                    SqlQueryId          = 1
                },
                new SqlQueryParameter()
                {
                    SqlQueryParameterId = 1,
                    ParameterId         = 1,
                    SqlQueryId          = 0
                }
            };

            Mock <IContext> mock = new Mock <IContext>();

            mock
            .Setup(p => p.Parameters)
            .Returns(parameters);
            mock
            .Setup(q => q.SqlQueries)
            .Returns(queries);
            mock
            .Setup(s => s.SqlQueryParameters)
            .Returns(queryParams);

            SqlQueryParameterRepository queryParamRepo = new SqlQueryParameterRepository(mock.Object);

            int        parameterId = parameters.First().ParameterId;
            List <int> queryIds    = queryParams.
                                     Where(p => p.ParameterId == parameterId).
                                     Select(q => q.SqlQueryId).
                                     ToList();

            // Act
            IEnumerable <int> funcResult = queryParamRepo.GetSqlQueryIdByParameterId(parameters.First().ParameterId);

            // Assert
            Assert.AreEqual(queryIds.Count(), funcResult.Count());
            Assert.AreEqual(queryIds.First(), funcResult.First());
        }