public void Then_Arguments_Are_Included_In_Field_Selections()
        {
            var phoneNumberSelection = SelectionSetBuilder.For <PhoneNumber>()
                                       .AddScalarField(phone => phone.Number)
                                       .Build();
            var phoneArgs = new ArgumentCollection
            {
                ArgumentBuilder.Build("areaCode", "231")
            };
            var expectedPhoneArgs = new IArgument[phoneArgs.Count];

            // copy arguments so we don't contaminate expectations
            phoneArgs.CopyTo(expectedPhoneArgs, 0);

            var contactSelection = SelectionSetBuilder.For <Contact>()
                                   .AddObjectCollectionField(contact => contact.PhoneNumbers, phoneArgs, phoneNumberSelection)
                                   .AddObjectCollectionField("foobar", contact => contact.PhoneNumbers, phoneArgs, phoneNumberSelection)
                                   .Build();

            var numbersArgs = new ArgumentCollection
            {
                ArgumentBuilder.Build("greaterThan", 10),
                ArgumentBuilder.Build("isEven", true)
            };
            var expectedNumbersArgs = new IArgument[numbersArgs.Count];

            // copy arguments so we don't contaminate expectations
            numbersArgs.CopyTo(expectedNumbersArgs, 0);

            var customerSelection = SelectionSetBuilder.For <Customer>()
                                    .AddScalarCollectionField(customer => customer.FavoriteNumbers, numbersArgs)
                                    .AddScalarCollectionField("myNumbers", customer => customer.FavoriteNumbers, numbersArgs)
                                    .AddObjectField(customer => customer.CustomerContact, contactSelection)
                                    .Build();

            var expectedPhoneSelection = new SelectionSet <PhoneNumber>(new List <ISelectionSetItem>
            {
                new ScalarFieldSelectionItem(null, nameof(PhoneNumber.Number))
            });
            var expectedContactSelection = new SelectionSet <Contact>(new List <ISelectionSetItem>
            {
                new ObjectFieldSelectionItem(null, nameof(Contact.PhoneNumbers), expectedPhoneArgs, expectedPhoneSelection),
                new ObjectFieldSelectionItem("foobar", nameof(Contact.PhoneNumbers), expectedPhoneArgs, expectedPhoneSelection),
            });
            var expectedCustomerSelections = new List <ISelectionSetItem>
            {
                new ScalarFieldSelectionItem(null, nameof(Customer.FavoriteNumbers), expectedNumbersArgs),
                new ScalarFieldSelectionItem("myNumbers", nameof(Customer.FavoriteNumbers), expectedNumbersArgs),
                new ObjectFieldSelectionItem(null, nameof(Customer.CustomerContact), expectedContactSelection)
            };

            customerSelection.Should().NotBeNull();
            customerSelection.Selections.Should()
            .BeEquivalentTo(expectedCustomerSelections, options => options.RespectingRuntimeTypes());
        }
        public void Then_Arguments_Are_Included_In_Field_Selections()
        {
            var customerSelectionSet = SelectionSetBuilder.For <Customer>()
                                       .AddScalarField(customer => customer.Id)
                                       .Build();

            var versionArgs = new ArgumentCollection
            {
                ArgumentBuilder.Build("foo", "hello world"),
                ArgumentBuilder.Build("bar", 10),
                ArgumentBuilder.Build("baz")
            };
            var expectedVersionArgs = new IArgument[versionArgs.Count];

            // copy the original arguments so our expectations aren't contaminated by the method under test
            versionArgs.CopyTo(expectedVersionArgs, 0);

            var customersArgs = new ArgumentCollection
            {
                ArgumentBuilder.Build("isActive", true),
                ArgumentBuilder.Build("age", 50.2)
            };
            var expectedCustomersArgs = new IArgument[customersArgs.Count];

            // copy the original arguments so our expectations aren't contaminated by the method under test
            customersArgs.CopyTo(expectedCustomersArgs, 0);

            var queryOperation = QueryOperationBuilder.ForSchema <SimpleSchema>(OperationTypeForFixture)
                                 .AddScalarCollectionField(schema => schema.PastVersions, versionArgs)
                                 .AddScalarCollectionField("versions", schema => schema.PastVersions, versionArgs)
                                 .AddObjectCollectionField(schema => schema.Customers, customersArgs, customerSelectionSet)
                                 .AddObjectCollectionField("foobar", schema => schema.Customers, customersArgs, customerSelectionSet)
                                 .Build();

            var expectedCustomerSelectionSet = new SelectionSet <Customer>(new List <ISelectionSetItem>
            {
                new ScalarFieldSelectionItem(null, nameof(Customer.Id))
            });

            var expectedSchemaSelections = new List <ISelectionSetItem>
            {
                new ScalarFieldSelectionItem(null, nameof(SimpleSchema.PastVersions), expectedVersionArgs),
                new ScalarFieldSelectionItem("versions", nameof(SimpleSchema.PastVersions), expectedVersionArgs),
                new ObjectFieldSelectionItem(null, nameof(SimpleSchema.Customers), expectedCustomersArgs,
                                             expectedCustomerSelectionSet),
                new ObjectFieldSelectionItem("foobar", nameof(SimpleSchema.Customers), expectedCustomersArgs,
                                             expectedCustomerSelectionSet),
            };

            queryOperation.Should().NotBeNull();
            queryOperation.SelectionSet.Selections.Should().BeEquivalentTo(expectedSchemaSelections,
                                                                           options => options.RespectingRuntimeTypes());
        }