示例#1
0
        public void PreviousMustNotBeInUse_InUse_ReturnsError()
        {
            var evidenceId = Guid.NewGuid().ToString();

            // first chain: rev1 <-- rev2
            var rev1 = Creator.GetReviewsBase(evidenceId: evidenceId);
            var rev2 = Creator.GetReviewsBase(evidenceId: evidenceId, prevId: rev1.Id);

            // second chain: revA <-- revB
            var revA = Creator.GetReviewsBase(evidenceId: evidenceId);
            var revB = Creator.GetReviewsBase(evidenceId: evidenceId, prevId: revA.Id);

            // review datastore returns both chains
            _reviewsDatastore.Setup(x => x.ByEvidence(evidenceId))
            .Returns(new[]
            {
                new[] { rev1, rev2 },
                new[] { revA, revB }
            });

            // create new review linked (previous) to rev1 ie 'fan out'
            var review    = Creator.GetReviewsBase(evidenceId: evidenceId, prevId: rev1.Id);
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);


            validator.PreviousMustNotBeInUse();
            var valres = validator.Validate(review);


            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Previous review already in use")
            .And
            .HaveCount(1);
        }
示例#2
0
        public void MustBeValidPreviousId_Null_Succeeds()
        {
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase(prevId: null);

            validator.MustBeValidPreviousId();
            var valres = validator.Validate(review);

            valres.Errors.Should().BeEmpty();
        }
示例#3
0
        public void PreviousMustNotBeInUse_NotInUse_Succeeds()
        {
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase(prevId: Guid.NewGuid().ToString());

            _reviewsDatastore.Setup(x => x.ByEvidence(review.EvidenceId)).Returns(new[] { new[] { Creator.GetReviewsBase() } });

            validator.PreviousMustNotBeInUse();
            var valres = validator.Validate(review);

            valres.Errors.Should().BeEmpty();
        }
示例#4
0
        public void MustBeValidEvidenceId_NotGuid_ReturnsError()
        {
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase(evidenceId: "some other Id");

            validator.MustBeValidEvidenceId();
            var valres = validator.Validate(review);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid EvidenceId")
            .And
            .HaveCount(1);
        }
示例#5
0
        public void PreviousMustBeForSameEvidence_Same_Succeeds()
        {
            var validator    = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var prevReview   = Creator.GetReviewsBase();
            var review       = Creator.GetReviewsBase(prevId: prevReview.Id, evidenceId: prevReview.EvidenceId);
            var prevEvidence = Creator.GetEvidenceBase();

            _reviewsDatastore.Setup(x => x.ById(prevReview.Id)).Returns(prevReview);
            _evidenceDatastore.Setup(x => x.ById(prevReview.EvidenceId)).Returns(prevEvidence);

            validator.PreviousMustBeForSameEvidence();
            var valres = validator.Validate(review);

            valres.Errors.Should().BeEmpty();
        }
示例#6
0
        public void MustBeValidEvidenceId_Null_ReturnsError()
        {
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase();

            review.EvidenceId = null;

            validator.MustBeValidEvidenceId();
            var valres = validator.Validate(review);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid EvidenceId")
            .And
            .ContainSingle(x => x.ErrorMessage == "'Evidence Id' must not be empty.")
            .And
            .HaveCount(2);
        }
示例#7
0
        public void PreviousMustBeForSameEvidence_Other_ReturnsError()
        {
            var validator    = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var prevReview   = Creator.GetReviewsBase();
            var review       = Creator.GetReviewsBase(prevId: prevReview.Id);
            var prevEvidence = Creator.GetEvidenceBase();

            _reviewsDatastore.Setup(x => x.ById(prevReview.Id)).Returns(prevReview);
            _evidenceDatastore.Setup(x => x.ById(prevReview.EvidenceId)).Returns(prevEvidence);

            validator.PreviousMustBeForSameEvidence();
            var valres = validator.Validate(review);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Previous review must be for same evidence")
            .And
            .HaveCount(1);
        }
示例#8
0
        public void MustBeFromSameOrganisation_Same_Succeeds()
        {
            var orgId     = Guid.NewGuid().ToString();
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase();

            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(orgId: orgId));
            var soln     = Creator.GetSolution(orgId: orgId);
            var claim    = Creator.GetClaimsBase(solnId: soln.Id);
            var evidence = Creator.GetEvidenceBase(claimId: claim.Id);

            _evidenceDatastore.Setup(x => x.ById(review.EvidenceId)).Returns(evidence);
            _claimDatastore.Setup(x => x.ById(evidence.ClaimId)).Returns(claim);
            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);

            validator.MustBeFromSameOrganisation();
            var valres = validator.Validate(review);

            valres.Errors.Should().BeEmpty();
        }
示例#9
0
        public void MustBeFromSameOrganisation_Other_ReturnsError()
        {
            var orgId = Guid.NewGuid().ToString();

            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            var validator = new DummyReviewsValidatorBase(_reviewsDatastore.Object, _evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var review    = Creator.GetReviewsBase();
            var soln      = Creator.GetSolution(orgId: orgId);
            var claim     = Creator.GetClaimsBase(solnId: soln.Id);
            var evidence  = Creator.GetEvidenceBase();

            _evidenceDatastore.Setup(x => x.ById(review.EvidenceId)).Returns(evidence);
            _claimDatastore.Setup(x => x.ById(evidence.ClaimId)).Returns(claim);
            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);

            validator.MustBeFromSameOrganisation();
            var valres = validator.Validate(review);

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Must be from same organisation")
            .And
            .HaveCount(1);
        }