Ejemplo n.º 1
0
        public void MustBePending_NonDraft_ReturnsError(
            [Values(
                 Roles.Buyer,
                 Roles.Supplier,
                 Roles.Admin
                 )]
            string role,
            [Values(
                 StandardsApplicableStatus.Submitted,
                 StandardsApplicableStatus.Remediation,
                 StandardsApplicableStatus.Approved,
                 StandardsApplicableStatus.ApprovedFirstOfType,
                 StandardsApplicableStatus.ApprovedPartial,
                 StandardsApplicableStatus.Rejected
                 )]
            StandardsApplicableStatus status)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new StandardsApplicableValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetStandardsApplicable(status: status);

            validator.MustBePending();
            var valres = validator.Validate(claim);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Only supplier can delete a draft claim")
            .And
            .HaveCount(1);
        }
        public void ForUpdate_ToSubmitted_Sets_SubmittedOn_ToUtcNow()
        {
            var modifier    = new StandardsApplicableModifier();
            var submittedOn = new DateTime(2006, 2, 20, 6, 3, 0);
            var claim       = Creator.GetStandardsApplicable(status: StandardsApplicableStatus.Submitted, submittedOn: submittedOn);

            modifier.ForUpdate(claim);

            claim.SubmittedOn.Should().BeCloseTo(DateTime.UtcNow);
        }
        public void ForUpdate_NotSubmitted_DoesNotSet_SubmittedOn(StandardsApplicableStatus status)
        {
            var modifier    = new StandardsApplicableModifier();
            var submittedOn = new DateTime(2006, 2, 20, 6, 3, 0);
            var claim       = Creator.GetStandardsApplicable(status: status, submittedOn: submittedOn);

            modifier.ForUpdate(claim);

            claim.SubmittedOn.Should().BeCloseTo(submittedOn);
        }
        public void ForUpdate_DefaultAssignedOn_Sets_SubmittedOn_ToUnixEpoch()
        {
            var modifier   = new StandardsApplicableModifier();
            var assignedOn = default(DateTime);
            var claim      = Creator.GetStandardsApplicable(assignedOn: assignedOn);

            modifier.ForUpdate(claim);

            claim.AssignedOn.Should().BeCloseTo(DateTime.UnixEpoch);
        }
        public void ForUpdate_AssignedOn_DoesNotSet_SubmittedOn()
        {
            var modifier   = new StandardsApplicableModifier();
            var assignedOn = new DateTime(2006, 2, 20, 6, 3, 0);
            var claim      = Creator.GetStandardsApplicable(assignedOn: assignedOn);

            modifier.ForUpdate(claim);

            claim.AssignedOn.Should().BeCloseTo(assignedOn);
        }
Ejemplo n.º 6
0
        public void Update_Calls_Modifier([ValueSource(nameof(Statuses))] StandardsApplicableStatus status)
        {
            var logic  = new StandardsApplicableLogic(_modifier.Object, _datastore.Object, _validator.Object, _filter.Object, _context.Object);
            var claim  = Creator.GetStandardsApplicable(status: status);
            var valres = new ValidationResult();

            _validator.Setup(x => x.Validate(It.IsAny <ValidationContext>())).Returns(valres);

            logic.Update(claim);

            _modifier.Verify(x => x.ForUpdate(claim), Times.Once);
        }
Ejemplo n.º 7
0
        public void MustBeValidStatusTransition_Valid_Succeeds(StandardsApplicableStatus oldStatus, StandardsApplicableStatus newStatus, string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new StandardsApplicableValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetStandardsApplicable(status: oldStatus);
            var newClaim  = Creator.GetStandardsApplicable(status: newStatus);

            _claimDatastore.Setup(x => x.ById(newClaim.Id)).Returns(oldClaim);

            validator.MustBeValidStatusTransition();
            var valres = validator.Validate(newClaim);

            valres.Errors.Should().BeEmpty();
        }
Ejemplo n.º 8
0
        public void MustBePending_Draft_Succeeds(
            [Values(Roles.Supplier)]
            string role,
            [Values(StandardsApplicableStatus.Draft, StandardsApplicableStatus.NotStarted)]
            StandardsApplicableStatus status)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new StandardsApplicableValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetStandardsApplicable(status: status);

            validator.MustBePending();
            var valres = validator.Validate(claim);

            valres.Errors.Should().BeEmpty();
        }
        public void SolutionMustBeInReview_Review_Succeeds(SolutionStatus status)
        {
            var validator = new StandardsApplicableEvidenceValidator(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var soln      = Creator.GetSolution(status: status);
            var claim     = Creator.GetStandardsApplicable(solnId: soln.Id);
            var evidence  = Creator.GetStandardsApplicableEvidence(claimId: claim.Id);

            _claimDatastore.As <IClaimsDatastore <ClaimsBase> >().Setup(x => x.ById(evidence.ClaimId)).Returns(claim);
            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);

            validator.SolutionMustBeInReview();
            var valres = validator.Validate(evidence);

            valres.Errors.Should().BeEmpty();
        }
        public void ClaimedStandardEvidenceMustBelongToClaim_Valid_Succeeds()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var claim     = Creator.GetStandardsApplicable();
            var claimEv   = Creator.GetStandardsApplicableEvidence(claimId: claim.Id);

            soln.ClaimedStandard         = new List <StandardsApplicable>(new [] { claim });
            soln.ClaimedStandardEvidence = new List <StandardsApplicableEvidence>(new[] { claimEv });

            validator.ClaimedStandardEvidenceMustBelongToClaim();
            var valres = validator.Validate(soln);

            valres.Errors.Should().BeEmpty();
        }
Ejemplo n.º 11
0
        public void Update_CallsValidator_WithRuleset()
        {
            var logic = new StandardsApplicableLogic(_modifier.Object, _datastore.Object, _validator.Object, _filter.Object, _context.Object);
            var claim = Creator.GetStandardsApplicable();

            var valres = new ValidationResult();

            _validator.Setup(x => x.Validate(It.IsAny <ValidationContext>())).Returns(valres);

            logic.Update(claim);

            _validator.Verify(x => x.ValidateAndThrowEx(
                                  It.Is <StandardsApplicable>(c => c == claim),
                                  It.Is <string>(rs => rs == nameof(IClaimsLogic <StandardsApplicable> .Update))), Times.Once());
        }
Ejemplo n.º 12
0
        public void MustBeValidStatusTransition_Invalid_ReturnsError(StandardsApplicableStatus oldStatus, StandardsApplicableStatus newStatus, string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new StandardsApplicableValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetStandardsApplicable(status: oldStatus);
            var newClaim  = Creator.GetStandardsApplicable(status: newStatus);

            _claimDatastore.Setup(x => x.ById(newClaim.Id)).Returns(oldClaim);

            validator.MustBeValidStatusTransition();
            var valres = validator.Validate(newClaim);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid Status transition")
            .And
            .HaveCount(1);
        }
        public void ClaimedStandardEvidenceMustBelongToClaim_Invalid_ReturnsError()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var claim     = Creator.GetStandardsApplicable();
            var claimEv   = Creator.GetStandardsApplicableEvidence();

            soln.ClaimedStandard         = new List <StandardsApplicable>(new [] { claim });
            soln.ClaimedStandardEvidence = new List <StandardsApplicableEvidence>(new[] { claimEv });

            validator.ClaimedStandardEvidenceMustBelongToClaim();
            var valres = validator.Validate(soln);

            valres.Errors.Should()
            .Contain(x => x.ErrorMessage == "ClaimedStandardEvidence must belong to claim")
            .And
            .HaveCount(1);
        }
        public void SolutionMustBeInReview_NonReview_ReturnsError(SolutionStatus status)
        {
            var validator = new StandardsApplicableEvidenceValidator(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var soln      = Creator.GetSolution(status: status);
            var claim     = Creator.GetStandardsApplicable(solnId: soln.Id);
            var evidence  = Creator.GetStandardsApplicableEvidence(claimId: claim.Id);

            _claimDatastore.As <IClaimsDatastore <ClaimsBase> >().Setup(x => x.ById(evidence.ClaimId)).Returns(claim);
            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);

            validator.SolutionMustBeInReview();
            var valres = validator.Validate(evidence);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Can only add evidence if solution is in review")
            .And
            .HaveCount(1);
        }
        public void ClaimedStandardMustBelongToSolution_Valid_Succeeds()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();

            soln.ClaimedStandard = new List <StandardsApplicable>
                                   (
                new []
            {
                Creator.GetStandardsApplicable(solnId: soln.Solution.Id),
                Creator.GetStandardsApplicable(solnId: soln.Solution.Id),
                Creator.GetStandardsApplicable(solnId: soln.Solution.Id)
            }
                                   );

            validator.ClaimedStandardMustBelongToSolution();
            var valres = validator.Validate(soln);

            valres.Errors.Should().BeEmpty();
        }
Ejemplo n.º 16
0
        public void Validate_Update_FinalState_ReturnsError(
            [Values(
                 StandardsApplicableStatus.Approved,
                 StandardsApplicableStatus.ApprovedPartial,
                 StandardsApplicableStatus.ApprovedFirstOfType,
                 StandardsApplicableStatus.Rejected)]
            StandardsApplicableStatus oldStatus,
            [Values(
                 StandardsApplicableStatus.NotStarted,
                 StandardsApplicableStatus.Draft,
                 StandardsApplicableStatus.Submitted,
                 StandardsApplicableStatus.Remediation,
                 StandardsApplicableStatus.Approved,
                 StandardsApplicableStatus.ApprovedPartial,
                 StandardsApplicableStatus.ApprovedFirstOfType,
                 StandardsApplicableStatus.Rejected)]
            StandardsApplicableStatus newStatus,
            [Values(
                 Roles.Admin,
                 Roles.Buyer,
                 Roles.Supplier)]
            string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new StandardsApplicableValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetStandardsApplicable(status: oldStatus);
            var newClaim  = Creator.GetStandardsApplicable(status: newStatus);

            _claimDatastore.Setup(x => x.ById(newClaim.Id)).Returns(oldClaim);

            validator.MustBeValidStatusTransition();
            var valres = validator.Validate(newClaim);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid Status transition")
            .And
            .HaveCount(1);
        }
        public void ClaimedStandardMustBelongToSolution_Invalid_ReturnsError()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();

            soln.ClaimedStandard = new List <StandardsApplicable>
                                   (
                new []
            {
                Creator.GetStandardsApplicable(),
                Creator.GetStandardsApplicable(),
                Creator.GetStandardsApplicable()
            }
                                   );

            validator.ClaimedStandardMustBelongToSolution();
            var valres = validator.Validate(soln);

            valres.Errors.Should()
            .Contain(x => x.ErrorMessage == "ClaimedStandard must belong to solution")
            .And
            .HaveCount(1);
        }