Example #1
0
        public void MustBePending_NonDraft_ReturnsError(
            [Values(
                 Roles.Buyer,
                 Roles.Supplier,
                 Roles.Admin
                 )]
            string role,
            [Values(
                 CapabilitiesImplementedStatus.Submitted,
                 CapabilitiesImplementedStatus.Remediation,
                 CapabilitiesImplementedStatus.Approved,
                 CapabilitiesImplementedStatus.Rejected
                 )]
            CapabilitiesImplementedStatus status)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetCapabilitiesImplemented(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);
        }
Example #2
0
        public void Validate_Update_FinalState_ReturnsError(
            [Values(
                 CapabilitiesImplementedStatus.Approved,
                 CapabilitiesImplementedStatus.Rejected)]
            CapabilitiesImplementedStatus oldStatus,
            [Values(
                 CapabilitiesImplementedStatus.Draft,
                 CapabilitiesImplementedStatus.Submitted,
                 CapabilitiesImplementedStatus.Remediation,
                 CapabilitiesImplementedStatus.Approved,
                 CapabilitiesImplementedStatus.Rejected)]
            CapabilitiesImplementedStatus newStatus,
            [Values(
                 Roles.Admin,
                 Roles.Buyer,
                 Roles.Supplier)]
            string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetCapabilitiesImplemented(status: oldStatus);
            var newClaim  = Creator.GetCapabilitiesImplemented(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);
        }
Example #3
0
        public void MustBePending_Draft_Succeeds(string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetCapabilitiesImplemented(status: CapabilitiesImplementedStatus.Draft);

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

            valres.Errors.Should().BeEmpty();
        }
Example #4
0
        public void MustBePending_Draft_ReturnsError(string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetCapabilitiesImplemented(status: CapabilitiesImplementedStatus.Draft);

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Only supplier can delete a draft claim")
            .And
            .HaveCount(1);
        }
Example #5
0
        public void MustBeValidStatusTransition_Valid_Succeeds(CapabilitiesImplementedStatus oldStatus, CapabilitiesImplementedStatus newStatus, string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetCapabilitiesImplemented(status: oldStatus);
            var newClaim  = Creator.GetCapabilitiesImplemented(status: newStatus);

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

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

            valres.Errors.Should().BeEmpty();
        }
Example #6
0
        public void SolutionMustBeInReview_Review_Succeeds(SolutionStatus status)
        {
            var validator = new CapabilitiesImplementedEvidenceValidator(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var soln      = Creator.GetSolution(status: status);
            var claim     = Creator.GetCapabilitiesImplemented(solnId: soln.Id);
            var evidence  = Creator.GetCapabilitiesImplementedEvidence(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 ClaimedCapabilityEvidenceMustBelongToClaim_Valid_Succeeds()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var claim     = Creator.GetCapabilitiesImplemented();
            var claimEv   = Creator.GetCapabilitiesImplementedEvidence(claimId: claim.Id);

            soln.ClaimedCapability         = new List <CapabilitiesImplemented>(new [] { claim });
            soln.ClaimedCapabilityEvidence = new List <CapabilitiesImplementedEvidence>(new[] { claimEv });

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

            valres.Errors.Should().BeEmpty();
        }
Example #8
0
        public void MustBeValidStatusTransition_Invalid_ReturnsError(CapabilitiesImplementedStatus oldStatus, CapabilitiesImplementedStatus newStatus, string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new CapabilitiesImplementedValidator(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var oldClaim  = Creator.GetCapabilitiesImplemented(status: oldStatus);
            var newClaim  = Creator.GetCapabilitiesImplemented(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);
        }
Example #9
0
        public void SolutionMustBeInReview_NonReview_ReturnsError(SolutionStatus status)
        {
            var validator = new CapabilitiesImplementedEvidenceValidator(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var soln      = Creator.GetSolution(status: status);
            var claim     = Creator.GetCapabilitiesImplemented(solnId: soln.Id);
            var evidence  = Creator.GetCapabilitiesImplementedEvidence(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 ClaimedCapabilityEvidenceMustBelongToClaim_Invalid_ReturnsError()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var claim     = Creator.GetCapabilitiesImplemented();
            var claimEv   = Creator.GetCapabilitiesImplementedEvidence();

            soln.ClaimedCapability         = new List <CapabilitiesImplemented>(new [] { claim });
            soln.ClaimedCapabilityEvidence = new List <CapabilitiesImplementedEvidence>(new[] { claimEv });

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

            valres.Errors.Should()
            .Contain(x => x.ErrorMessage == "ClaimedCapabilityEvidence must belong to claim")
            .And
            .HaveCount(1);
        }
        public void ClaimedCapabilityMustBelongToSolution_Valid_Succeeds()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();

            soln.ClaimedCapability = new List <CapabilitiesImplemented>
                                     (
                new []
            {
                Creator.GetCapabilitiesImplemented(solnId: soln.Solution.Id),
                Creator.GetCapabilitiesImplemented(solnId: soln.Solution.Id),
                Creator.GetCapabilitiesImplemented(solnId: soln.Solution.Id)
            }
                                     );

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

            valres.Errors.Should().BeEmpty();
        }
        public void ClaimedCapabilityMustBelongToSolution_Invalid_ReturnsError()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();

            soln.ClaimedCapability = new List <CapabilitiesImplemented>
                                     (
                new []
            {
                Creator.GetCapabilitiesImplemented(),
                Creator.GetCapabilitiesImplemented(),
                Creator.GetCapabilitiesImplemented()
            }
                                     );

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

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