public void ProjectCannotHaveSameHealthRiskTwice()
        {
            var projects     = A.Fake <IProjects>();
            var projectId    = Guid.NewGuid();
            var healthRiskId = Guid.NewGuid();

            A.CallTo(() => projects.GetById(A <Guid> ._)).Returns(
                new Project
            {
                Id          = projectId,
                HealthRisks = new[] { new ProjectHealthRisk()
                                      {
                                          HealthRiskId = healthRiskId
                                      }, }
            }
                );

            var healthRisks = A.Fake <IHealthRisks>();

            A.CallTo(() => healthRisks.GetById(A <Guid> ._)).Returns(
                new HealthRisk()
                );

            IProjectHealthRiskRules projectHealthRiskRules = new ProjectHealthRiskRules(projects, healthRisks);
            var validator        = new AddProjectHealthRiskValidator(projectHealthRiskRules);
            var validationResult =
                validator.Validate(new AddProjectHealthRisk {
                HealthRiskId = healthRiskId, ProjectId = projectId
            });

            Assert.False(validationResult.IsValid);
        }
        public void ProjectCannotAddNotExistingHealthRisk()
        {
            var projects  = A.Fake <IProjects>();
            var projectId = Guid.NewGuid();

            A.CallTo(() => projects.GetById(A <Guid> ._)).Returns(
                new Project
            {
                Id = projectId,
            }
                );

            var healthRisks = A.Fake <IHealthRisks>();

            A.CallTo(() => healthRisks.GetById(A <Guid> ._)).Returns(
                null
                );

            IProjectHealthRiskRules projectHealthRiskRules = new ProjectHealthRiskRules(projects, healthRisks);
            var validator        = new AddProjectHealthRiskValidator(projectHealthRiskRules);
            var validationResult =
                validator.Validate(new AddProjectHealthRisk {
                HealthRiskId = Guid.NewGuid(), ProjectId = projectId
            });

            Assert.False(validationResult.IsValid);
        }
        public void ProjectCannotHaveMoreThanFiveHealthRisks(int numberOfRisks, bool shouldValidate)
        {
            var projects  = A.Fake <IProjects>();
            var projectId = Guid.NewGuid();

            A.CallTo(() => projects.GetById(A <Guid> ._)).Returns(
                new Project
            {
                Id          = projectId,
                HealthRisks =
                    new List <ProjectHealthRisk>(
                        Enumerable.Repeat(new ProjectHealthRisk {
                    HealthRiskId = Guid.NewGuid()
                }, numberOfRisks))
                    .ToArray()
            }
                );

            var healthRisks = A.Fake <IHealthRisks>();

            A.CallTo(() => healthRisks.GetById(A <Guid> ._)).Returns(
                new HealthRisk());

            IProjectHealthRiskRules projectHealthRiskRules = new ProjectHealthRiskRules(projects, healthRisks);
            var validator        = new AddProjectHealthRiskValidator(projectHealthRiskRules);
            var validationResult = validator.Validate(new AddProjectHealthRisk());

            Assert.Equal(shouldValidate, validationResult.IsValid);
        }