Exemple #1
0
        public void GraphLookup_with_restrictSearchWithMatch_should_return_expected_result()
        {
            RequireServer.Check();
            EnsureTestData();
            var subject          = __employeesCollection.Aggregate();
            var connectFromField = (FieldDefinition <Employee, string>) "ReportsTo";
            var connectToField   = (FieldDefinition <Employee, string>) "Name";
            var startWith        = (AggregateExpressionDefinition <Employee, string>) "$reportsTo";
            var @as     = (FieldDefinition <EmployeeWithReportingHierarchy, Employee[]>) "ReportingHierarchy";
            var options = new AggregateGraphLookupOptions <Employee, Employee, EmployeeWithReportingHierarchy>
            {
                RestrictSearchWithMatch = Builders <Employee> .Filter.Ne("Id", 1)
            };

            var result = subject
                         .GraphLookup(__employeesCollection, connectFromField, connectToField, startWith, @as, options)
                         .ToList();

            var comparer = new EmployeeWithReportingHierarchyEqualityComparer();

            result.WithComparer(comparer).Should().Equal(
                new EmployeeWithReportingHierarchy(__dev, new Employee[0]),
                new EmployeeWithReportingHierarchy(__eliot, new Employee[0]),
                new EmployeeWithReportingHierarchy(__ron, new[] { __eliot }),
                new EmployeeWithReportingHierarchy(__andrew, new[] { __eliot }),
                new EmployeeWithReportingHierarchy(__asya, new[] { __eliot, __ron }),
                new EmployeeWithReportingHierarchy(__dan, new[] { __eliot, __andrew }));
        }
Exemple #2
0
        public void GraphLookup_with_expressions_should_return_expected_result()
        {
            RequireServer.Check();
            EnsureTestData();
            var subject = __employeesCollection.Aggregate();

            var result = subject
                         .GraphLookup(
                __employeesCollection,
                connectFromField: x => x.ReportsTo,
                connectToField: x => x.Name,
                startWith: x => x.ReportsTo,
                @as: (EmployeeWithReportingHierarchy x) => x.ReportingHierarchy)
                         .ToList();

            var comparer = new EmployeeWithReportingHierarchyEqualityComparer();

            result.WithComparer(comparer).Should().Equal(
                new EmployeeWithReportingHierarchy(__dev, new Employee[0]),
                new EmployeeWithReportingHierarchy(__eliot, new[] { __dev }),
                new EmployeeWithReportingHierarchy(__ron, new[] { __dev, __eliot }),
                new EmployeeWithReportingHierarchy(__andrew, new[] { __dev, __eliot }),
                new EmployeeWithReportingHierarchy(__asya, new[] { __dev, __eliot, __ron }),
                new EmployeeWithReportingHierarchy(__dan, new[] { __dev, __eliot, __andrew }));
        }
Exemple #3
0
        public void GraphLookup_should_return_expected_result()
        {
            RequireServer.Check();
            EnsureTestData();
            var subject          = __employeesCollection.Aggregate();
            var connectFromField = (FieldDefinition <Employee, string>) "ReportsTo";
            var connectToField   = (FieldDefinition <Employee, string>) "Name";
            var startWith        = (AggregateExpressionDefinition <Employee, string>) "$reportsTo";
            var @as = (FieldDefinition <EmployeeWithReportingHierarchy, IEnumerable <Employee> >) "ReportingHierarchy";

            var result = subject
                         .GraphLookup(__employeesCollection, connectFromField, connectToField, startWith, @as)
                         .ToList();

            var comparer = new EmployeeWithReportingHierarchyEqualityComparer();

            result.WithComparer(comparer).Should().Equal(
                new EmployeeWithReportingHierarchy(__dev, new Employee[0]),
                new EmployeeWithReportingHierarchy(__eliot, new[] { __dev }),
                new EmployeeWithReportingHierarchy(__ron, new[] { __dev, __eliot }),
                new EmployeeWithReportingHierarchy(__andrew, new[] { __dev, __eliot }),
                new EmployeeWithReportingHierarchy(__asya, new[] { __dev, __eliot, __ron }),
                new EmployeeWithReportingHierarchy(__dan, new[] { __dev, __eliot, __andrew }));
        }