public void PreviousMustNotBeInUse_InUse_ReturnsError()
        {
            var claimId = Guid.NewGuid().ToString();

            // first chain: ev1 <-- ev2
            var ev1 = Creator.GetEvidenceBase(claimId: claimId);
            var ev2 = Creator.GetEvidenceBase(claimId: claimId, prevId: ev1.Id);

            // second chain: evA <-- evB
            var evA = Creator.GetEvidenceBase(claimId: claimId);
            var evB = Creator.GetEvidenceBase(claimId: claimId, prevId: evA.Id);

            // evidence datastore returns both chains
            _evidenceDatastore.Setup(x => x.ByClaim(claimId))
            .Returns(new[]
            {
                new[] { ev1, ev2 },
                new[] { evA, evB }
            });

            // create new evidence linked (previous) to ev1 ie 'fan out'
            var evidence  = Creator.GetEvidenceBase(claimId: claimId, prevId: ev1.Id);
            var validator = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);


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


            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Previous evidence already in use")
            .And
            .HaveCount(1);
        }
        public void Filter_Admin_ReturnsAll()
        {
            var filter   = new DummyEvidenceFilterBase(_claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var evidence = Creator.GetEvidenceBase();

            var res = filter.FilterForAdmin(new[] { evidence });

            res.Should().BeEquivalentTo(evidence);
        }
Example #3
0
        public void Create_Calls_Modifier()
        {
            var logic    = new DummyEvidenceLogicBase(_modifier.Object, _datastore.Object, _contacts.Object, _validator.Object, _filter.Object, _context.Object);
            var evidence = Creator.GetEvidenceBase(originalDate: DateTime.MinValue);

            logic.Create(evidence);

            _modifier.Verify(x => x.ForCreate(evidence), Times.Once);
        }
        public void Filter_Buyer_ReturnsNull()
        {
            var filter   = new DummyEvidenceFilterBase(_claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var evidence = Creator.GetEvidenceBase();

            var res = filter.FilterForBuyer(new[] { evidence });

            res.Should().BeNull();
        }
        public void MustBeValidClaimId_Valid_Succeeds()
        {
            var validator = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase();

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

            valres.Errors.Should().BeEmpty();
        }
Example #6
0
        public void ForCreate_SetsCreatedOn_ToUtcNow()
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            _contacts.Setup(x => x.ByEmail(It.IsAny <string>())).Returns(Creator.GetContact());
            var modifier = new DummyEvidenceBaseModifier(_context.Object, _contacts.Object);
            var evidence = Creator.GetEvidenceBase(createdOn: DateTime.MinValue);

            modifier.ForCreate(evidence);

            evidence.CreatedOn.Should().BeCloseTo(DateTime.UtcNow);
        }
Example #7
0
        public void MustBeSupplier_Supplier_Succeeds(string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new DummyValidatorBase(_context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase();

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

            valres.Errors.Should().BeEmpty();
        }
Example #8
0
        public void ForUpdate_DefaultOriginalDate_SetsOriginalDate_ToUtcNow()
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            _contacts.Setup(x => x.ByEmail(It.IsAny <string>())).Returns(Creator.GetContact());
            var modifier = new DummyEvidenceBaseModifier(_context.Object, _contacts.Object);
            var evidence = Creator.GetEvidenceBase(originalDate: default(DateTime));

            modifier.ForUpdate(evidence);

            evidence.OriginalDate.Should().BeCloseTo(DateTime.UtcNow);
        }
        public void PreviousMustNotBeInUse_NotInUse_Succeeds()
        {
            var validator = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase(prevId: Guid.NewGuid().ToString());

            _evidenceDatastore.Setup(x => x.ByClaim(evidence.ClaimId)).Returns(new[] { new[] { Creator.GetEvidenceBase() } });

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

            valres.Errors.Should().BeEmpty();
        }
Example #10
0
        public void ForUpdate_OriginalDate_DoesNotSet_OriginalDate()
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            _contacts.Setup(x => x.ByEmail(It.IsAny <string>())).Returns(Creator.GetContact());
            var modifier     = new DummyEvidenceBaseModifier(_context.Object, _contacts.Object);
            var originalDate = new DateTime(2006, 2, 20, 6, 3, 0);
            var evidence     = Creator.GetEvidenceBase(originalDate: originalDate);

            modifier.ForUpdate(evidence);

            evidence.OriginalDate.Should().BeCloseTo(originalDate);
        }
        public void MustBeValidClaimId_NotGuid_ReturnsError()
        {
            var validator = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase(claimId: "some other Id");

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid ClaimId")
            .And
            .HaveCount(1);
        }
Example #12
0
        public void MustBeSupplier_NonSupplier_ReturnsError(string role)
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(role: role));
            var validator = new DummyValidatorBase(_context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase();

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Must be supplier")
            .And
            .HaveCount(1);
        }
Example #13
0
        public void ForCreate_SetsCreatedById()
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            var contactId = Guid.NewGuid().ToString();
            var contact   = Creator.GetContact(id: contactId);

            _contacts.Setup(x => x.ByEmail(It.IsAny <string>())).Returns(contact);
            var modifier = new DummyEvidenceBaseModifier(_context.Object, _contacts.Object);
            var evidence = Creator.GetEvidenceBase(originalDate: DateTime.MinValue);

            modifier.ForCreate(evidence);

            evidence.CreatedById.Should().Be(contactId);
        }
        public void PreviousMustBeForSameClaim_Same_Succeeds()
        {
            var prevId       = Guid.NewGuid().ToString();
            var validator    = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence     = Creator.GetEvidenceBase(prevId: prevId);
            var prevEvidence = Creator.GetEvidenceBase(claimId: evidence.ClaimId);

            _evidenceDatastore.Setup(x => x.ById(prevId)).Returns(prevEvidence);

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

            valres.Errors.Should().BeEmpty();
        }
Example #15
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();
        }
        public void Filter_SupplierOther_ReturnsNull()
        {
            var filter   = new DummyEvidenceFilterBase(_claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var orgId    = Guid.NewGuid().ToString();
            var soln     = Creator.GetSolution(orgId: orgId);
            var claim    = Creator.GetClaimsBase(solnId: soln.Id);
            var evidence = Creator.GetEvidenceBase(claimId: claim.Id);
            var ctx      = Creator.GetContext();

            _context.Setup(c => c.HttpContext).Returns(ctx);
            _claimDatastore.Setup(x => x.ById(evidence.ClaimId)).Returns(claim);
            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);

            var res = filter.FilterForSupplier(new[] { evidence });

            res.Should().BeNull();
        }
        public void PreviousMustBeForSameClaim_Other_ReturnsError()
        {
            var prevId       = Guid.NewGuid().ToString();
            var validator    = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence     = Creator.GetEvidenceBase(prevId: prevId);
            var prevEvidence = Creator.GetEvidenceBase();

            _evidenceDatastore.Setup(x => x.ById(prevId)).Returns(prevEvidence);

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Previous evidence must be for same claim")
            .And
            .HaveCount(1);
        }
Example #18
0
        public void Create_CallsValidator_WithRuleset()
        {
            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext());
            _contacts.Setup(x => x.ByEmail(It.IsAny <string>())).Returns(Creator.GetContact());
            var logic    = new DummyEvidenceLogicBase(_modifier.Object, _datastore.Object, _contacts.Object, _validator.Object, _filter.Object, _context.Object);
            var evidence = Creator.GetEvidenceBase();

            var valres = new ValidationResult();

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

            logic.Create(evidence);

            _validator.Verify(x => x.ValidateAndThrowEx(
                                  It.Is <DummyEvidenceBase>(ev => ev == evidence),
                                  It.Is <string>(rs => rs == nameof(IEvidenceLogic <EvidenceLogicBase <EvidenceBase> > .Create))), Times.Once());
        }
        public void MustBeValidClaimId_Null_ReturnsError()
        {
            var validator = new DummyEvidenceValidatorBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object, _logger.Object);
            var evidence  = Creator.GetEvidenceBase();

            evidence.ClaimId = null;

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid ClaimId")
            .And
            .ContainSingle(x => x.ErrorMessage == "'Claim Id' must not be empty.")
            .And
            .HaveCount(2);
        }
        public void MustBeFromSameOrganisation_Same_Succeeds()
        {
            var orgId = Guid.NewGuid().ToString();

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

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

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

            valres.Errors.Should().BeEmpty();
        }
Example #21
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);
        }
Example #22
0
        public void Filter_SupplierOwn_ReturnsOwn()
        {
            var filter   = new DummyReviewsFilterBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var orgId    = Guid.NewGuid().ToString();
            var soln     = Creator.GetSolution(orgId: orgId);
            var claim    = Creator.GetClaimsBase(solnId: soln.Id);
            var evidence = Creator.GetEvidenceBase(claimId: claim.Id);
            var review   = Creator.GetReviewsBase(evidenceId: evidence.Id);
            var ctx      = Creator.GetContext(orgId: orgId);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            _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);

            var res = filter.FilterForSupplier(new[] { review });

            res.Should().BeEquivalentTo(review);
        }
        public void MustBeFromSameOrganisation_Other_ReturnsError()
        {
            var orgId = Guid.NewGuid().ToString();

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

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

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

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