public void Validate_Admin_Succeeds(
            [ValueSource(nameof(Operations))] string operation)
        {
            var ctx = Creator.GetContext(role: Roles.Admin);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var techCont  = Creator.GetTechnicalContact();
            var validator = new TechnicalContactValidator(_context.Object, _solutionDatastore.Object);

            var res = validator.Validate(techCont, ruleSet: operation);

            res.Errors.Should().BeEmpty();
        }
        public void TechnicalContactMustBelongToSolution_Valid_Succeeds()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var techCont  = Creator.GetTechnicalContact(solutionId: soln.Solution.Id);

            soln.TechnicalContact = new List <TechnicalContacts>(new[] { techCont });

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

            valres.Errors.Should().BeEmpty();
        }
Example #3
0
        public void Filter_NonSupplier_Returns_All(string role)
        {
            var ctx = Creator.GetContext(role: role);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var filter    = new TechnicalContactsFilter(_context.Object, _solutionDatastore.Object);
            var techConts = new[]
            {
                Creator.GetTechnicalContact(),
                Creator.GetTechnicalContact(),
                Creator.GetTechnicalContact()
            };
            var res = filter.Filter(techConts);

            res.Should().BeEquivalentTo(techConts);
        }
        public void TechnicalContactMustBelongToSolution_Invalid_ReturnsError()
        {
            var validator = new SolutionsExValidator(_context.Object, _logger.Object, _solutionsValidator.Object);
            var soln      = Creator.GetSolutionEx();
            var techCont  = Creator.GetTechnicalContact();

            soln.TechnicalContact = new List <TechnicalContacts>(new[] { techCont });

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

            valres.Errors.Should()
            .Contain(x => x.ErrorMessage == "TechnicalContact must belong to solution")
            .And
            .HaveCount(1);
        }
Example #5
0
        public void SupplierOwn_Other_ReturnsError()
        {
            var orgId = Guid.NewGuid().ToString();
            var ctx   = Creator.GetContext(orgId: orgId, role: Roles.Supplier);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var soln     = Creator.GetSolution();
            var techCont = Creator.GetTechnicalContact();

            _solutionDatastore.Setup(x => x.ById(techCont.SolutionId)).Returns(soln);
            var validator = new TechnicalContactsValidator(_context.Object, _logger.Object, _solutionDatastore.Object);

            validator.SupplierOwn();
            var res = validator.Validate(techCont);

            res.Errors.Count().Should().Be(1);
        }
        public void Validate_Supplier_Other_ReturnsError(
            [ValueSource(nameof(Operations))] string operation)
        {
            var orgId = Guid.NewGuid().ToString();
            var ctx   = Creator.GetContext(orgId: orgId, role: Roles.Supplier);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var soln     = Creator.GetSolution();
            var techCont = Creator.GetTechnicalContact();

            _solutionDatastore.Setup(x => x.ById(techCont.SolutionId)).Returns(soln);
            var validator = new TechnicalContactValidator(_context.Object, _solutionDatastore.Object);

            var res = validator.Validate(techCont, ruleSet: operation);

            res.Errors.Count().Should().Be(1);
        }
Example #7
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 techConts = new[]
            {
                Creator.GetTechnicalContact(solutionId: soln.Id),
                Creator.GetTechnicalContact(solutionId: soln.Id),
                Creator.GetTechnicalContact(solutionId: soln.Id)
            };

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

            _solutionsFilter.Verify(x => x.Filter(It.Is <IEnumerable <Solutions> >(solns => solns.Contains(soln))), Times.Exactly(techConts.Count()));
        }
Example #8
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 techConts = new[]
            {
                Creator.GetTechnicalContact(solutionId: soln.Id),
                Creator.GetTechnicalContact(solutionId: soln.Id),
                Creator.GetTechnicalContact(solutionId: soln.Id)
            };
            var expTechConts = techConts.Where(x => returnSoln);

            var res = filter.Filter(techConts);

            res.Should().BeEquivalentTo(expTechConts);
        }
Example #9
0
        public void Filter_Supplier_Returns_Own()
        {
            var orgId = Guid.NewGuid().ToString();
            var ctx   = Creator.GetContext(orgId: orgId, role: Roles.Supplier);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var filter = new TechnicalContactsFilter(_context.Object, _solutionDatastore.Object);
            var soln1  = Creator.GetSolution(orgId: orgId);
            var soln2  = Creator.GetSolution();
            var soln3  = Creator.GetSolution();

            _solutionDatastore.Setup(x => x.ById(soln1.Id)).Returns(soln1);
            _solutionDatastore.Setup(x => x.ById(soln2.Id)).Returns(soln2);
            _solutionDatastore.Setup(x => x.ById(soln3.Id)).Returns(soln3);
            var techContCtx1 = Creator.GetTechnicalContact(solutionId: soln1.Id);
            var techContCtx2 = Creator.GetTechnicalContact(solutionId: soln2.Id);
            var techContCtx3 = Creator.GetTechnicalContact(solutionId: soln3.Id);
            var techContCtxs = new[] { techContCtx1, techContCtx2, techContCtx3 };

            var res = filter.Filter(techContCtxs);

            res.Should().BeEquivalentTo(new[] { techContCtx1 });
        }