Example #1
0
        public void Filter_None_Returns_Approved(
            [ValueSource(typeof(Creator), nameof(Creator.SolutionStatuses))] SolutionStatus status)
        {
            var filter = new SolutionsFilter();
            var solns  = new[]
            {
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status)
            };
            var expSolns = solns.Where(x => x.Status == SolutionStatus.Approved);

            var res = filter.Filter(solns);

            res.Should().BeEquivalentTo(expSolns);
        }
        public void Filter_Supplier_Returns_Own([ValueSource(nameof(Statuses))] SolutionStatus status)
        {
            var orgId = Guid.NewGuid().ToString();
            var ctx   = Creator.GetContext(orgId: orgId, role: Roles.Supplier);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var filter = new SolutionsFilter(_context.Object);
            var soln1  = Creator.GetSolution(status: status, orgId: orgId);
            var soln2  = Creator.GetSolution(status: status);
            var soln3  = Creator.GetSolution(status: status);
            var solns  = new[] { soln1, soln2, soln3 };

            var res = filter.Filter(solns);

            res.Should().BeEquivalentTo(soln1);
        }
        public void Filter_Admin_Returns_All([ValueSource(nameof(Statuses))] SolutionStatus status)
        {
            var ctx = Creator.GetContext(role: Roles.Admin);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var filter = new SolutionsFilter(_context.Object);
            var solns  = new[]
            {
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status)
            };

            var res = filter.Filter(solns);

            res.Should().BeEquivalentTo(solns);
        }
        public void Filter_None_Returns_NonFailedDraft([ValueSource(nameof(Statuses))] SolutionStatus status)
        {
            var ctx = Creator.GetContext(role: "None");

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var filter = new SolutionsFilter(_context.Object);
            var solns  = new[]
            {
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status),
                Creator.GetSolution(status: status)
            };
            var expSolns = solns.Where(x =>
                                       x.Status != SolutionStatus.Draft &&
                                       x.Status != SolutionStatus.Failed);

            var res = filter.Filter(solns);

            res.Should().BeEquivalentTo(expSolns);
        }