Exemplo n.º 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);
        }
        public void Create_Calls_Modifier()
        {
            var logic  = new DummyReviewsLogicBase(_modifier.Object, _datastore.Object, _contacts.Object, _validator.Object, _filter.Object, _context.Object);
            var review = Creator.GetReviewsBase(originalDate: DateTime.MinValue);

            logic.Create(review);

            _modifier.Verify(x => x.ForCreate(review), Times.Once);
        }
Exemplo n.º 3
0
        public void Filter_Buyer_ReturnsNull()
        {
            var filter = new DummyReviewsFilterBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var review = Creator.GetReviewsBase();

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

            res.Should().BeNull();
        }
Exemplo n.º 4
0
        public void Filter_Admin_ReturnsAll()
        {
            var filter = new DummyReviewsFilterBase(_evidenceDatastore.Object, _claimDatastore.Object, _solutionDatastore.Object, _context.Object);
            var review = Creator.GetReviewsBase();

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

            res.Should().BeEquivalentTo(review);
        }
Exemplo n.º 5
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();
        }
        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 DummyReviewsBaseModifier(_context.Object, _contacts.Object);
            var review   = Creator.GetReviewsBase(originalDate: default(DateTime));

            modifier.ForUpdate(review);

            review.OriginalDate.Should().BeCloseTo(DateTime.UtcNow);
        }
        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 DummyReviewsBaseModifier(_context.Object, _contacts.Object);
            var review   = Creator.GetReviewsBase(createdOn: DateTime.MinValue);

            modifier.ForCreate(review);

            review.CreatedOn.Should().BeCloseTo(DateTime.UtcNow);
        }
        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 DummyReviewsBaseModifier(_context.Object, _contacts.Object);
            var originalDate = new DateTime(2006, 2, 20, 6, 3, 0);
            var review       = Creator.GetReviewsBase(originalDate: originalDate);

            modifier.ForUpdate(review);

            review.OriginalDate.Should().BeCloseTo(originalDate);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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);
        }
        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 DummyReviewsBaseModifier(_context.Object, _contacts.Object);
            var review   = Creator.GetReviewsBase(originalDate: DateTime.MinValue);

            modifier.ForCreate(review);

            review.CreatedById.Should().Be(contactId);
        }
Exemplo n.º 12
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 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 DummyReviewsLogicBase(_modifier.Object, _datastore.Object, _contacts.Object, _validator.Object, _filter.Object, _context.Object);
            var review = Creator.GetReviewsBase();

            var valres = new ValidationResult();

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

            logic.Create(review);

            _validator.Verify(x => x.ValidateAndThrowEx(
                                  It.Is <DummyReviewsBase>(ev => ev == review),
                                  It.Is <string>(rs => rs == nameof(IEvidenceLogic <ReviewsLogicBase <ReviewsBase> > .Create))), Times.Once());
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public void Filter_SupplierOther_ReturnsNull()
        {
            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();

            _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().BeNull();
        }
Exemplo n.º 17
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();
        }
Exemplo n.º 18
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);
        }