Пример #1
0
        public void MustBeValidOwnerId_NotGuid_ReturnsError()
        {
            var validator = new DummyClaimsValidatorBase(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetClaimsBase(ownerId: "some other Id");

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid OwnerId")
            .And
            .HaveCount(1);
        }
Пример #2
0
        public void Filter_SupplierOther_ReturnsNull()
        {
            var filter = new DummyClaimsFilterBase(_context.Object, _solutionDatastore.Object);
            var orgId  = Guid.NewGuid().ToString();
            var soln   = Creator.GetSolution(orgId: orgId);
            var claim  = Creator.GetClaimsBase(solnId: soln.Id);
            var ctx    = Creator.GetContext();

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

            var res = filter.FilterForSupplier(claim);

            res.Should().BeNull();
        }
        public void Delete_CallsValidator_WithRuleset()
        {
            var logic = new DummyClaimsLogicBase(_modifier.Object, _datastore.Object, _validator.Object, _filter.Object, _context.Object);
            var claim = Creator.GetClaimsBase();

            var valres = new ValidationResult();

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

            logic.Delete(claim);

            _validator.Verify(x => x.ValidateAndThrowEx(
                                  It.Is <ClaimsBase>(c => c == claim),
                                  It.Is <string>(rs => rs == nameof(IClaimsLogic <ClaimsBase> .Delete))), Times.Once());
        }
Пример #4
0
        public void MustBeSameOrganisation_Same_NewClaim_Succeeds()
        {
            var orgId = Guid.NewGuid().ToString();

            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(orgId: orgId));
            var validator = new DummyClaimsValidatorBase(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetClaimsBase();

            _solutionsDatastore.Setup(x => x.ById(claim.SolutionId)).Returns(Creator.GetSolution(orgId: orgId));

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

            valres.Errors.Should().BeEmpty();
        }
Пример #5
0
        public void MustBeSameSolution_Different_ReturnsError()
        {
            var validator = new DummyClaimsValidatorBase(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetClaimsBase();

            _claimDatastore.Setup(x => x.ById(claim.Id)).Returns(Creator.GetClaimsBase());

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Cannot transfer claim between solutions")
            .And
            .HaveCount(1);
        }
Пример #6
0
        public void MustBeValidSolutionId_Null_ReturnsError()
        {
            var validator = new DummyClaimsValidatorBase(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var claim     = Creator.GetClaimsBase();

            claim.SolutionId = null;

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Invalid SolutionId")
            .And
            .ContainSingle(x => x.ErrorMessage == "'Solution Id' must not be empty.")
            .And
            .HaveCount(2);
        }
        public void Filter_SupplierOwn_ReturnsOwn()
        {
            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(orgId: orgId);

            _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().BeEquivalentTo(evidence);
        }
        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();
        }
Пример #9
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();
        }
Пример #10
0
        public void ContactMustBeSameOrganisation_Different_ReturnsError()
        {
            var orgId = Guid.NewGuid().ToString();

            _context.Setup(x => x.HttpContext).Returns(Creator.GetContext(orgId: orgId));
            var validator = new DummyClaimsValidatorBase(_context.Object, _logger.Object, _claimDatastore.Object, _contactsDatastore.Object, _solutionsDatastore.Object);
            var contact   = Creator.GetContact(orgId: orgId);
            var claim     = Creator.GetClaimsBase();

            _contactsDatastore.Setup(x => x.ById(contact.Id)).Returns(contact);

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

            valres.Errors.Should()
            .ContainSingle(x => x.ErrorMessage == "Contact must be from organisation")
            .And
            .HaveCount(1);
        }
        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);
        }
Пример #12
0
        public void Filter_None_Calls_SolutionFilter(
            [Values(true, false)] bool returnSoln)
        {
            var filter = Create();
            var soln   = Creator.GetSolution();

            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);
            _solutionsFilter
            .Setup(x => x.Filter(It.Is <IEnumerable <Solutions> >(solns => solns.Contains(soln))))
            .Returns(returnSoln ? new[] { soln } : Enumerable.Empty <Solutions>());
            var claims = new[]
            {
                Creator.GetClaimsBase(solnId: soln.Id),
                Creator.GetClaimsBase(solnId: soln.Id),
                Creator.GetClaimsBase(solnId: soln.Id)
            };

            // use ToList() to force LINQ to run
            filter.Filter(claims).ToList();

            _solutionsFilter.Verify(x => x.Filter(It.Is <IEnumerable <Solutions> >(solns => solns.Contains(soln))), Times.Exactly(claims.Count()));
        }
Пример #13
0
        public void Filter_None_Returns_Filtered_By_SolutionFilter(
            [Values(true, false)] bool returnSoln)
        {
            var filter = Create();
            var soln   = Creator.GetSolution();

            _solutionDatastore.Setup(x => x.ById(soln.Id)).Returns(soln);
            _solutionsFilter
            .Setup(x => x.Filter(It.Is <IEnumerable <Solutions> >(solns => solns.Contains(soln))))
            .Returns(returnSoln ? new[] { soln } : Enumerable.Empty <Solutions>());
            var claims = new[]
            {
                Creator.GetClaimsBase(solnId: soln.Id),
                Creator.GetClaimsBase(solnId: soln.Id),
                Creator.GetClaimsBase(solnId: soln.Id)
            };
            var expClaims = claims.Where(x => returnSoln);

            var res = filter.Filter(claims);

            res.Should().BeEquivalentTo(returnSoln ? claims : expClaims);
        }